Skip to content

Commit f3f297c

Browse files
fix ci by spliting the tests for version
1 parent 3103ad7 commit f3f297c

File tree

11 files changed

+99
-33
lines changed

11 files changed

+99
-33
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ install:
3939

4040
script:
4141
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e.sh ; fi
42+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then GO111MODULE=on TRACE=1 PATH=$PATH:$(pwd) ./test_e2e_v2.sh ; fi
4243
- GO111MODULE=on TRACE=1 ./test.sh
4344

4445
# TBD. Suppressing for now.

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ test-project-generation:
4141

4242
.PHONY: test-e2e
4343
test-e2e:
44-
./test_e2e.sh
44+
./test_e2e_v1.sh
45+
./test_e2e_v2.sh

test/e2e/kubectl.go renamed to test/e2e/utils/kubectl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package utils
1818

1919
import (
2020
"errors"
@@ -24,7 +24,7 @@ import (
2424

2525
// Kubectl contains context to run kubectl commands
2626
type Kubectl struct {
27-
*cmdContext
27+
*CmdContext
2828
Namespace string
2929
}
3030

test/e2e/test_context.go renamed to test/e2e/utils/test_context.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package utils
1818

1919
import (
2020
"fmt"
@@ -30,7 +30,7 @@ const certmanagerVersion = "v0.10.1"
3030

3131
// KBTestContext specified to run e2e tests
3232
type KBTestContext struct {
33-
*cmdContext
33+
*CmdContext
3434
TestSuffix string
3535
Domain string
3636
Group string
@@ -55,7 +55,7 @@ func TestContext(env ...string) (*KBTestContext, error) {
5555
return nil, err
5656
}
5757

58-
cc := &cmdContext{
58+
cc := &CmdContext{
5959
Env: env,
6060
Dir: path,
6161
}
@@ -68,10 +68,10 @@ func TestContext(env ...string) (*KBTestContext, error) {
6868
Kind: "Foo" + testSuffix,
6969
Resources: "foo" + testSuffix + "s",
7070
ImageName: "e2e-test/controller-manager:" + testSuffix,
71-
cmdContext: cc,
71+
CmdContext: cc,
7272
Kubectl: &Kubectl{
7373
Namespace: fmt.Sprintf("e2e-%s-system", testSuffix),
74-
cmdContext: cc,
74+
CmdContext: cc,
7575
},
7676
}, nil
7777
}
@@ -166,13 +166,13 @@ func (kc *KBTestContext) LoadImageToKindCluster() error {
166166
return err
167167
}
168168

169-
type cmdContext struct {
169+
type CmdContext struct {
170170
// environment variables in k=v format.
171171
Env []string
172172
Dir string
173173
}
174174

175-
func (cc *cmdContext) Run(cmd *exec.Cmd) ([]byte, error) {
175+
func (cc *CmdContext) Run(cmd *exec.Cmd) ([]byte, error) {
176176
cmd.Dir = cc.Dir
177177
cmd.Env = append(os.Environ(), cc.Env...)
178178
command := strings.Join(cmd.Args, " ")

test/e2e/util.go renamed to test/e2e/utils/util.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package utils
1818

1919
import (
2020
"bytes"
@@ -39,9 +39,9 @@ func randomSuffix() (string, error) {
3939
return string(res), nil
4040
}
4141

42-
// getNonEmptyLines converts given command output string into individual objects
42+
// GetNonEmptyLines converts given command output string into individual objects
4343
// according to line breakers, and ignores the empty elements in it.
44-
func getNonEmptyLines(output string) []string {
44+
func GetNonEmptyLines(output string) []string {
4545
var res []string
4646
elements := strings.Split(output, "\n")
4747
for _, element := range elements {
@@ -53,8 +53,8 @@ func getNonEmptyLines(output string) []string {
5353
return res
5454
}
5555

56-
// insertCode searches target content in the file and insert `toInsert` after the target.
57-
func insertCode(filename, target, code string) error {
56+
// InsertCode searches target content in the file and insert `toInsert` after the target.
57+
func InsertCode(filename, target, code string) error {
5858
contents, err := ioutil.ReadFile(filename)
5959
if err != nil {
6060
return err
@@ -64,9 +64,9 @@ func insertCode(filename, target, code string) error {
6464
return ioutil.WriteFile(filename, []byte(out), 0644)
6565
}
6666

67-
// uncommentCode searches for target in the file and remove the comment prefix
67+
// UncommentCode searches for target in the file and remove the comment prefix
6868
// of the target content. The target content may span multiple lines.
69-
func uncommentCode(filename, target, prefix string) error {
69+
func UncommentCode(filename, target, prefix string) error {
7070
content, err := ioutil.ReadFile(filename)
7171
if err != nil {
7272
return err

test/e2e/e2e_v1.go renamed to test/e2e/v1/e2e_suite.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package v1
1818

1919
import (
2020
"fmt"
2121
"os/exec"
2222
"path/filepath"
23+
"sigs.k8s.io/kubebuilder/test/e2e/utils"
2324
"strings"
2425
"time"
2526

@@ -29,10 +30,10 @@ import (
2930

3031
var _ = Describe("kubebuilder", func() {
3132
Context("with v1 scaffolding", func() {
32-
var kbc *KBTestContext
33+
var kbc *utils.KBTestContext
3334
BeforeEach(func() {
3435
var err error
35-
kbc, err = TestContext("GO111MODULE=off")
36+
kbc, err = utils.TestContext("GO111MODULE=off")
3637
Expect(err).NotTo(HaveOccurred())
3738
Expect(kbc.Prepare()).To(Succeed())
3839
})
@@ -121,7 +122,7 @@ var _ = Describe("kubebuilder", func() {
121122
"-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}",
122123
)
123124
Expect(err).NotTo(HaveOccurred())
124-
podNames := getNonEmptyLines(podOutput)
125+
podNames := utils.GetNonEmptyLines(podOutput)
125126
if len(podNames) != 1 {
126127
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames))
127128
}

test/e2e/e2e_test.go renamed to test/e2e/v1/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package v1
1818

1919
import (
2020
"fmt"

test/e2e/e2e_v2.go renamed to test/e2e/v2/e2e_suite.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package e2e
17+
package v2
1818

1919
import (
2020
"fmt"
2121
"io/ioutil"
2222
"path/filepath"
23+
"sigs.k8s.io/kubebuilder/test/e2e/utils"
2324
"strconv"
2425
"strings"
2526
"time"
@@ -30,10 +31,10 @@ import (
3031

3132
var _ = Describe("kubebuilder", func() {
3233
Context("with v2 scaffolding", func() {
33-
var kbc *KBTestContext
34+
var kbc *utils.KBTestContext
3435
BeforeEach(func() {
3536
var err error
36-
kbc, err = TestContext("GO111MODULE=on")
37+
kbc, err = utils.TestContext("GO111MODULE=on")
3738
Expect(err).NotTo(HaveOccurred())
3839
Expect(kbc.Prepare()).To(Succeed())
3940

@@ -73,7 +74,7 @@ var _ = Describe("kubebuilder", func() {
7374
Expect(err).Should(Succeed())
7475

7576
By("implementing the API")
76-
Expect(insertCode(
77+
Expect(utils.InsertCode(
7778
filepath.Join(kbc.Dir, "api", kbc.Version, fmt.Sprintf("%s_types.go", strings.ToLower(kbc.Kind))),
7879
fmt.Sprintf(`type %sSpec struct {
7980
`, kbc.Kind),
@@ -97,19 +98,19 @@ var _ = Describe("kubebuilder", func() {
9798
Expect(err).Should(Succeed())
9899

99100
By("uncomment kustomization.yaml to enable webhook and ca injection")
100-
Expect(uncommentCode(
101+
Expect(utils.UncommentCode(
101102
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
102103
"#- ../webhook", "#")).To(Succeed())
103-
Expect(uncommentCode(
104+
Expect(utils.UncommentCode(
104105
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
105106
"#- ../certmanager", "#")).To(Succeed())
106-
Expect(uncommentCode(
107+
Expect(utils.UncommentCode(
107108
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
108109
"#- manager_webhook_patch.yaml", "#")).To(Succeed())
109-
Expect(uncommentCode(
110+
Expect(utils.UncommentCode(
110111
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
111112
"#- webhookcainjection_patch.yaml", "#")).To(Succeed())
112-
Expect(uncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
113+
Expect(utils.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
113114
`#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
114115
# objref:
115116
# kind: Certificate
@@ -161,7 +162,7 @@ var _ = Describe("kubebuilder", func() {
161162
"pods", "-l", "control-plane=controller-manager",
162163
"-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")
163164
Expect(err).NotTo(HaveOccurred())
164-
podNames := getNonEmptyLines(podOutput)
165+
podNames := utils.GetNonEmptyLines(podOutput)
165166
if len(podNames) != 1 {
166167
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames))
167168
}

test/e2e/v2/e2e_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2018 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+
17+
package v2
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
23+
. "github.com/onsi/ginkgo"
24+
. "github.com/onsi/gomega"
25+
)
26+
27+
// Run e2e tests using the Ginkgo runner.
28+
func TestE2E(t *testing.T) {
29+
RegisterFailHandler(Fail)
30+
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n")
31+
RunSpecs(t, "Kubebuilder e2e suite")
32+
}

test_e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ setup_envs
2727
docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
2828
kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
2929

30-
go test ./test/e2e
30+
go test ./test/e2e/v1

test_e2e_v2.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2018 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+
docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
28+
kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
29+
30+
go test ./test/e2e/v2

0 commit comments

Comments
 (0)