Skip to content

Commit 122a922

Browse files
author
Mengqi Yu
committed
🏃 more robust golden test
1 parent b4ac7b8 commit 122a922

10 files changed

+64
-130
lines changed

.travis.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ before_install:
2727
# NOTE: The latest version of dep requires go 1.13
2828
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir -p /Users/travis/gopath/bin; fi
2929
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then GO111MODULE=on scripts/install_and_setup.sh; fi
30+
- GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.2
31+
- GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@v3.2.1
3032

3133
before_script:
3234

@@ -37,9 +39,10 @@ install:
3739
-
3840

3941
script:
40-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e.sh ; fi
41-
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e_v2.sh ; fi
42+
- GO111MODULE=on TRACE=1 ./golden_test.sh
4243
- GO111MODULE=on TRACE=1 ./test.sh
44+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e_v1.sh ; fi
45+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e_v2.sh ; fi
4346

4447
# TBD. Suppressing for now.
4548
notifications:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ generate: ## Update/generate all mock data. You should run this commands to upda
5151

5252
.PHONY: generate-testdata
5353
generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder
54-
GO111MODULE=on ./generated_golden.sh
54+
GO111MODULE=on ./generate_golden.sh
5555

5656
.PHONY: generate-vendor
5757
generate-vendor: ## Update/generate the vendor by using the path $GOPATH/src/sigs.k8s.io/kubebuilder-test

generated_golden.sh generate_golden.sh

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ scaffold_test_project() {
7676
fi
7777
make all test # v2 doesn't test by default
7878
rm -f Gopkg.lock
79+
rm -f go.sum
7980
rm -rf ./vendor
8081
rm -rf ./bin
8182
export GOPATH=$oldgopath
@@ -84,6 +85,8 @@ scaffold_test_project() {
8485

8586
set -e
8687

88+
GOPROXY=https://proxy.golang.org/
89+
8790
build_kb
8891
scaffold_test_project gopath/src/project 1
8992
scaffold_test_project project-v2 2

golden_test.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
source common.sh
21+
22+
fetch_tools
23+
build_kb
24+
25+
setup_envs
26+
27+
check_directory=testdata
28+
29+
# Check testdata directory first. If there are any uncommitted change, fail the test.
30+
if [[ `git status ${check_directory} --porcelain` ]]; then
31+
header_text "Golden test precondition failed!"
32+
header_text "Please commit the change under testdata directory before running the golden test"
33+
exit 1
34+
fi
35+
36+
./generate_golden.sh
37+
38+
# Check if there are any changes to files under testdata directory.
39+
if [[ `git status ${check_directory} --porcelain` ]]; then
40+
header_text "git status ${check_directory} --porcelain"
41+
git status ${check_directory} --porcelain
42+
header_text "git diff ${check_directory}"
43+
git diff ${check_directory}
44+
header_text "Golden test failed!"
45+
header_text "Please make sure you have run ./generate_golden.sh if you have changed the scaffolding"
46+
exit 1
47+
else
48+
header_text "Golden test passed!"
49+
fi

scripts/install_and_setup.sh

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
export GO111MODULE=on
1818

1919
go get sigs.k8s.io/kind@v0.5.1
20-
go get sigs.k8s.io/kustomize/v3/cmd/kustomize@v3.1.0
2120

2221
# You can use --image flag to specify the cluster version you want, e.g --image=kindest/node:v1.13.6, the supported version are listed at https://hub.docker.com/r/kindest/node/tags
2322
kind create cluster --config test/kind-config.yaml --image=kindest/node:v1.14.1

test_e2e.sh test_e2e_v1.sh

File renamed without changes.

testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.2
68
creationTimestamp: null
79
name: admirals.crew.testproject.org
810
spec:

testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.2
68
creationTimestamp: null
79
name: captains.crew.testproject.org
810
spec:

testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
apiVersion: apiextensions.k8s.io/v1beta1
44
kind: CustomResourceDefinition
55
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.2
68
creationTimestamp: null
79
name: firstmates.crew.testproject.org
810
spec:

testdata/project-v2/go.sum

-126
This file was deleted.

0 commit comments

Comments
 (0)