Skip to content

Commit

Permalink
fix ci by spliting the tests for version
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Oct 11, 2019
1 parent 3103ad7 commit f3f297c
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 33 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ install:

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

# TBD. Suppressing for now.
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ test-project-generation:

.PHONY: test-e2e
test-e2e:
./test_e2e.sh
./test_e2e_v1.sh
./test_e2e_v2.sh
4 changes: 2 additions & 2 deletions test/e2e/kubectl.go → test/e2e/utils/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package utils

import (
"errors"
Expand All @@ -24,7 +24,7 @@ import (

// Kubectl contains context to run kubectl commands
type Kubectl struct {
*cmdContext
*CmdContext
Namespace string
}

Expand Down
14 changes: 7 additions & 7 deletions test/e2e/test_context.go → test/e2e/utils/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package utils

import (
"fmt"
Expand All @@ -30,7 +30,7 @@ const certmanagerVersion = "v0.10.1"

// KBTestContext specified to run e2e tests
type KBTestContext struct {
*cmdContext
*CmdContext
TestSuffix string
Domain string
Group string
Expand All @@ -55,7 +55,7 @@ func TestContext(env ...string) (*KBTestContext, error) {
return nil, err
}

cc := &cmdContext{
cc := &CmdContext{
Env: env,
Dir: path,
}
Expand All @@ -68,10 +68,10 @@ func TestContext(env ...string) (*KBTestContext, error) {
Kind: "Foo" + testSuffix,
Resources: "foo" + testSuffix + "s",
ImageName: "e2e-test/controller-manager:" + testSuffix,
cmdContext: cc,
CmdContext: cc,
Kubectl: &Kubectl{
Namespace: fmt.Sprintf("e2e-%s-system", testSuffix),
cmdContext: cc,
CmdContext: cc,
},
}, nil
}
Expand Down Expand Up @@ -166,13 +166,13 @@ func (kc *KBTestContext) LoadImageToKindCluster() error {
return err
}

type cmdContext struct {
type CmdContext struct {
// environment variables in k=v format.
Env []string
Dir string
}

func (cc *cmdContext) Run(cmd *exec.Cmd) ([]byte, error) {
func (cc *CmdContext) Run(cmd *exec.Cmd) ([]byte, error) {
cmd.Dir = cc.Dir
cmd.Env = append(os.Environ(), cc.Env...)
command := strings.Join(cmd.Args, " ")
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/util.go → test/e2e/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package utils

import (
"bytes"
Expand All @@ -39,9 +39,9 @@ func randomSuffix() (string, error) {
return string(res), nil
}

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

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

// uncommentCode searches for target in the file and remove the comment prefix
// UncommentCode searches for target in the file and remove the comment prefix
// of the target content. The target content may span multiple lines.
func uncommentCode(filename, target, prefix string) error {
func UncommentCode(filename, target, prefix string) error {
content, err := ioutil.ReadFile(filename)
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/e2e_v1.go → test/e2e/v1/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package v1

import (
"fmt"
"os/exec"
"path/filepath"
"sigs.k8s.io/kubebuilder/test/e2e/utils"
"strings"
"time"

Expand All @@ -29,10 +30,10 @@ import (

var _ = Describe("kubebuilder", func() {
Context("with v1 scaffolding", func() {
var kbc *KBTestContext
var kbc *utils.KBTestContext
BeforeEach(func() {
var err error
kbc, err = TestContext("GO111MODULE=off")
kbc, err = utils.TestContext("GO111MODULE=off")
Expect(err).NotTo(HaveOccurred())
Expect(kbc.Prepare()).To(Succeed())
})
Expand Down Expand Up @@ -121,7 +122,7 @@ var _ = Describe("kubebuilder", func() {
"-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}",
)
Expect(err).NotTo(HaveOccurred())
podNames := getNonEmptyLines(podOutput)
podNames := utils.GetNonEmptyLines(podOutput)
if len(podNames) != 1 {
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames))
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_test.go → test/e2e/v1/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package v1

import (
"fmt"
Expand Down
21 changes: 11 additions & 10 deletions test/e2e/e2e_v2.go → test/e2e/v2/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package v2

import (
"fmt"
"io/ioutil"
"path/filepath"
"sigs.k8s.io/kubebuilder/test/e2e/utils"
"strconv"
"strings"
"time"
Expand All @@ -30,10 +31,10 @@ import (

var _ = Describe("kubebuilder", func() {
Context("with v2 scaffolding", func() {
var kbc *KBTestContext
var kbc *utils.KBTestContext
BeforeEach(func() {
var err error
kbc, err = TestContext("GO111MODULE=on")
kbc, err = utils.TestContext("GO111MODULE=on")
Expect(err).NotTo(HaveOccurred())
Expect(kbc.Prepare()).To(Succeed())

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

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

By("uncomment kustomization.yaml to enable webhook and ca injection")
Expect(uncommentCode(
Expect(utils.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../webhook", "#")).To(Succeed())
Expect(uncommentCode(
Expect(utils.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../certmanager", "#")).To(Succeed())
Expect(uncommentCode(
Expect(utils.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- manager_webhook_patch.yaml", "#")).To(Succeed())
Expect(uncommentCode(
Expect(utils.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- webhookcainjection_patch.yaml", "#")).To(Succeed())
Expect(uncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
Expect(utils.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
`#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
# objref:
# kind: Certificate
Expand Down Expand Up @@ -161,7 +162,7 @@ var _ = Describe("kubebuilder", func() {
"pods", "-l", "control-plane=controller-manager",
"-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")
Expect(err).NotTo(HaveOccurred())
podNames := getNonEmptyLines(podOutput)
podNames := utils.GetNonEmptyLines(podOutput)
if len(podNames) != 1 {
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames))
}
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/v2/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v2

import (
"fmt"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

// Run e2e tests using the Ginkgo runner.
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n")
RunSpecs(t, "Kubebuilder e2e suite")
}
2 changes: 1 addition & 1 deletion test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ setup_envs
docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1

go test ./test/e2e
go test ./test/e2e/v1
30 changes: 30 additions & 0 deletions test_e2e_v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

source common.sh

fetch_tools
build_kb

setup_envs

docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1
kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1

go test ./test/e2e/v2

0 comments on commit f3f297c

Please sign in to comment.