Skip to content

Commit 1948c3e

Browse files
authored
Merge pull request #4921 from camilamacedo86/add-make-tests-faster
🌱 (chore): optimize CI time and usage of resources
2 parents 9623a8b + 4aa8c2e commit 1948c3e

File tree

5 files changed

+69
-31
lines changed

5 files changed

+69
-31
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ test-coverage: ## Run unit tests creating the output to report coverage
156156
.PHONY: test-integration
157157
test-integration: ## Run the integration tests
158158
./test/integration.sh
159+
./test/features.sh
159160

160161
.PHONY: check-testdata
161162
check-testdata: ## Run the script to ensure that the testdata is updated

test/e2e/alphagenerate/generate_test.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,24 @@ var _ = Describe("kubebuilder", func() {
7474
validateProjectFile(kbc, filepath.Join(kbc.Dir, "PROJECT"))
7575
})
7676

77-
It("should regenerate project with grafana plugin with success", func() {
78-
generateProjectWithGrafanaPlugin(kbc)
79-
regenerateProjectWith(kbc, projectOutputDir)
80-
validateGrafanaPlugin(projectFilePath)
81-
})
77+
It("should regenerate project with plugins with success", func() {
78+
By("Enabling the Grafana plugin")
79+
err := kbc.Edit("--plugins", "grafana.kubebuilder.io/v1-alpha")
80+
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Grafana Plugin")
8281

83-
It("should regenerate project with DeployImage plugin with success", func() {
84-
generateProjectWithDeployImagePlugin(kbc)
85-
regenerateProjectWith(kbc, projectOutputDir)
86-
validateDeployImagePlugin(projectFilePath)
87-
})
82+
By("Generate API with Deploy Image plugin")
83+
generateAPIWithDeployImage(kbc)
84+
85+
By("Enabling Helm plugin")
86+
err = kbc.Edit("--plugins", "helm.kubebuilder.io/v1-alpha")
87+
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Helm Plugin")
8888

89-
It("should regenerate project with helm plugin with success", func() {
90-
generateProjectWithHelmPlugin(kbc)
89+
By("Re-generating the project with plugins")
9190
regenerateProjectWith(kbc, projectOutputDir)
91+
92+
By("By validating the expected scaffolded files")
93+
validateGrafanaPlugin(projectFilePath)
94+
validateDeployImagePlugin(projectFilePath)
9295
validateHelmPlugin(projectFilePath)
9396
})
9497
})
@@ -200,19 +203,7 @@ func regenerateProjectWith(kbc *utils.TestContext, projectOutputDir string) {
200203
Expect(err).NotTo(HaveOccurred(), "Failed to regenerate project")
201204
}
202205

203-
func generateProjectWithGrafanaPlugin(kbc *utils.TestContext) {
204-
By("editing project to enable Grafana plugin")
205-
err := kbc.Edit("--plugins", "grafana.kubebuilder.io/v1-alpha")
206-
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Grafana Plugin")
207-
}
208-
209-
func generateProjectWithHelmPlugin(kbc *utils.TestContext) {
210-
By("editing project to enable Helm plugin")
211-
err := kbc.Edit("--plugins", "helm.kubebuilder.io/v1-alpha")
212-
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Helm Plugin")
213-
}
214-
215-
func generateProjectWithDeployImagePlugin(kbc *utils.TestContext) {
206+
func generateAPIWithDeployImage(kbc *utils.TestContext) {
216207
By("creating an API with DeployImage plugin")
217208
err := kbc.CreateAPI(
218209
"--group", "crew",

test/e2e/setup.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ function test_cluster {
6464
docker pull busybox:1.36.1
6565
kind load docker-image --name $KIND_CLUSTER busybox:1.36.1
6666

67-
go test $(dirname "$0")/grafana $flags -timeout 30m
6867
go test $(dirname "$0")/deployimage $flags -timeout 30m
6968
go test $(dirname "$0")/v4 $flags -timeout 30m
70-
go test $(dirname "$0")/alphagenerate $flags -timeout 30m
7169
}

test/e2e/utils/test_context.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,25 @@ func NewTestContext(binaryName string, env ...string) (*TestContext, error) {
7373
ServiceAccount: fmt.Sprintf("e2e-%s-controller-manager", testSuffix),
7474
CmdContext: cc,
7575
}
76-
k8sVersion, err := kubectl.Version()
76+
var k8sVersion *KubernetesVersion
77+
v, err := kubectl.Version()
7778
if err != nil {
78-
return nil, fmt.Errorf("failed to get kubernetes version: %w", err)
79+
_, _ = fmt.Fprintf(GinkgoWriter, "warning: failed to get kubernetes version: %v\n", err)
80+
k8sVersion = &KubernetesVersion{
81+
ClientVersion: VersionInfo{
82+
Major: "1",
83+
Minor: "0",
84+
GitVersion: "v1.0.0-fake",
85+
},
86+
ServerVersion: VersionInfo{
87+
Major: "1",
88+
Minor: "0",
89+
GitVersion: "v1.0.0-fake",
90+
},
91+
}
92+
} else {
93+
k8sVersion = &v
7994
}
80-
8195
// Set CmdContext.Dir after running Kubectl.Version() because dir does not exist yet.
8296
if cc.Dir, err = filepath.Abs("e2e-" + testSuffix); err != nil {
8397
return nil, fmt.Errorf("failed to determine absolute path to %q: %w", "e2e-"+testSuffix, err)
@@ -93,7 +107,7 @@ func NewTestContext(binaryName string, env ...string) (*TestContext, error) {
93107
ImageName: "e2e-test/controller-manager:" + testSuffix,
94108
CmdContext: cc,
95109
Kubectl: kubectl,
96-
K8sVersion: &k8sVersion,
110+
K8sVersion: k8sVersion,
97111
BinaryName: binaryName,
98112
}, nil
99113
}

test/features.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
source "$(dirname "$0")/common.sh"
20+
21+
header_text "Running e2e tests that do not require a cluster"
22+
23+
build_kb
24+
fetch_tools
25+
26+
pushd . >/dev/null
27+
28+
header_text "Running Grafana Plugin E2E tests"
29+
go test "$(dirname "$0")/e2e/grafana" ${flags:-} -timeout 30m
30+
31+
header_text "Running Alpha Generate Command E2E tests"
32+
go test "$(dirname "$0")/e2e/alphagenerate" ${flags:-} -timeout 30m
33+
34+
popd >/dev/null

0 commit comments

Comments
 (0)