Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ test-coverage: ## Run unit tests creating the output to report coverage
.PHONY: test-integration
test-integration: ## Run the integration tests
./test/integration.sh
./test/features.sh

.PHONY: check-testdata
check-testdata: ## Run the script to ensure that the testdata is updated
Expand Down
41 changes: 16 additions & 25 deletions test/e2e/alphagenerate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,24 @@ var _ = Describe("kubebuilder", func() {
validateProjectFile(kbc, filepath.Join(kbc.Dir, "PROJECT"))
})

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

It("should regenerate project with DeployImage plugin with success", func() {
generateProjectWithDeployImagePlugin(kbc)
regenerateProjectWith(kbc, projectOutputDir)
validateDeployImagePlugin(projectFilePath)
})
By("Generate API with Deploy Image plugin")
generateAPIWithDeployImage(kbc)

By("Enabling Helm plugin")
err = kbc.Edit("--plugins", "helm.kubebuilder.io/v1-alpha")
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Helm Plugin")

It("should regenerate project with helm plugin with success", func() {
generateProjectWithHelmPlugin(kbc)
By("Re-generating the project with plugins")
regenerateProjectWith(kbc, projectOutputDir)

By("By validating the expected scaffolded files")
validateGrafanaPlugin(projectFilePath)
validateDeployImagePlugin(projectFilePath)
validateHelmPlugin(projectFilePath)
})
})
Expand Down Expand Up @@ -200,19 +203,7 @@ func regenerateProjectWith(kbc *utils.TestContext, projectOutputDir string) {
Expect(err).NotTo(HaveOccurred(), "Failed to regenerate project")
}

func generateProjectWithGrafanaPlugin(kbc *utils.TestContext) {
By("editing project to enable Grafana plugin")
err := kbc.Edit("--plugins", "grafana.kubebuilder.io/v1-alpha")
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Grafana Plugin")
}

func generateProjectWithHelmPlugin(kbc *utils.TestContext) {
By("editing project to enable Helm plugin")
err := kbc.Edit("--plugins", "helm.kubebuilder.io/v1-alpha")
Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Helm Plugin")
}

func generateProjectWithDeployImagePlugin(kbc *utils.TestContext) {
func generateAPIWithDeployImage(kbc *utils.TestContext) {
By("creating an API with DeployImage plugin")
err := kbc.CreateAPI(
"--group", "crew",
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ function test_cluster {
docker pull busybox:1.36.1
kind load docker-image --name $KIND_CLUSTER busybox:1.36.1

go test $(dirname "$0")/grafana $flags -timeout 30m
go test $(dirname "$0")/deployimage $flags -timeout 30m
go test $(dirname "$0")/v4 $flags -timeout 30m
go test $(dirname "$0")/alphagenerate $flags -timeout 30m
}
22 changes: 18 additions & 4 deletions test/e2e/utils/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,25 @@ func NewTestContext(binaryName string, env ...string) (*TestContext, error) {
ServiceAccount: fmt.Sprintf("e2e-%s-controller-manager", testSuffix),
CmdContext: cc,
}
k8sVersion, err := kubectl.Version()
var k8sVersion *KubernetesVersion
v, err := kubectl.Version()
if err != nil {
return nil, fmt.Errorf("failed to get kubernetes version: %w", err)
_, _ = fmt.Fprintf(GinkgoWriter, "warning: failed to get kubernetes version: %v\n", err)
k8sVersion = &KubernetesVersion{
ClientVersion: VersionInfo{
Major: "1",
Minor: "0",
GitVersion: "v1.0.0-fake",
},
ServerVersion: VersionInfo{
Major: "1",
Minor: "0",
GitVersion: "v1.0.0-fake",
},
}
} else {
k8sVersion = &v
}

// Set CmdContext.Dir after running Kubectl.Version() because dir does not exist yet.
if cc.Dir, err = filepath.Abs("e2e-" + testSuffix); err != nil {
return nil, fmt.Errorf("failed to determine absolute path to %q: %w", "e2e-"+testSuffix, err)
Expand All @@ -93,7 +107,7 @@ func NewTestContext(binaryName string, env ...string) (*TestContext, error) {
ImageName: "e2e-test/controller-manager:" + testSuffix,
CmdContext: cc,
Kubectl: kubectl,
K8sVersion: &k8sVersion,
K8sVersion: k8sVersion,
BinaryName: binaryName,
}, nil
}
Expand Down
34 changes: 34 additions & 0 deletions test/features.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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 -euo pipefail

source "$(dirname "$0")/common.sh"

header_text "Running e2e tests that do not require a cluster"

build_kb
fetch_tools

pushd . >/dev/null

header_text "Running Grafana Plugin E2E tests"
go test "$(dirname "$0")/e2e/grafana" ${flags:-} -timeout 30m

header_text "Running Alpha Generate Command E2E tests"
go test "$(dirname "$0")/e2e/alphagenerate" ${flags:-} -timeout 30m

popd >/dev/null