Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 e2e tests improve assertions by simplify style of checks #4456

Merged
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
6 changes: 3 additions & 3 deletions docs/book/src/plugins/extending/testing-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Here’s a general workflow to create a sample project using the `go/v4` plugin
"--domain", kbc.Domain,
"--fetch-deps=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to initialize a project")
```

- **To define API:**
Expand All @@ -70,7 +70,7 @@ Here’s a general workflow to create a sample project using the `go/v4` plugin
"--controller",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to create an API")
```

- **To scaffold webhook configurations:**
Expand All @@ -83,7 +83,7 @@ Here’s a general workflow to create a sample project using the `go/v4` plugin
"--defaulting",
"--programmatic-validation",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to create an webhook")
```

[cert-manager-install]: https://pkg.go.dev/sigs.k8s.io/kubebuilder/v4/test/e2e/utils#TestContext.InstallCertManager
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alphagenerate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func generateProject(kbc *utils.TestContext) {
"--external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1",
"--external-api-domain=cert-manager.io",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to scaffold API with external API")
}

func regenerateProject(kbc *utils.TestContext, projectOutputDir string) {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/deployimage/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func creatingAPI(kbc *utils.TestContext) {
"--make=false",
"--manifests=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to create API definition")
}

func creatingAPIWithOptions(kbc *utils.TestContext) {
Expand All @@ -69,7 +69,7 @@ func creatingAPIWithOptions(kbc *utils.TestContext) {
"--make=false",
"--manifests=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to create API definition with deploy-image/v1-alpha")
}

func initTheProject(kbc *utils.TestContext) {
Expand All @@ -79,5 +79,5 @@ func initTheProject(kbc *utils.TestContext) {
"--project-version", "3",
"--domain", kbc.Domain,
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to initialize project")
}
12 changes: 6 additions & 6 deletions test/e2e/grafana/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func GenerateProject(kbc *utils.TestContext) {
err = kbc.Init(
"--plugins", "grafana.kubebuilder.io/v1-alpha",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to initialize project")

By("verifying the initial template content and updating for real custom metrics")
ExpectWithOffset(1, pluginutil.ReplaceInFile(
Expand All @@ -83,17 +83,17 @@ customMetrics:
err = kbc.Edit(
"--plugins", "grafana.kubebuilder.io/v1-alpha",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to edit base of the project")

fileContainsExpr, err := pluginutil.HasFileContentWith(
filepath.Join(kbc.Dir, "grafana", "custom-metrics", "custom-metrics-dashboard.json"),
`sum(rate(foo_bar{job=\"$job\", namespace=\"$namespace\"}[5m])) by (instance, pod)`)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, fileContainsExpr).To(BeTrue())
Expect(err).NotTo(HaveOccurred(), "Failed to edit sum rate for custom metrics")
Expect(fileContainsExpr).To(BeTrue())

fileContainsExpr, err = pluginutil.HasFileContentWith(
filepath.Join(kbc.Dir, "grafana", "custom-metrics", "custom-metrics-dashboard.json"),
`histogram_quantile(0.90, sum by(instance, le) (rate(foo_bar{job=\"$job\", namespace=\"$namespace\"}[5m])))`)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, fileContainsExpr).To(BeTrue())
Expect(err).NotTo(HaveOccurred(), "Failed to edit histogram_quantile for custom metrics")
Expect(fileContainsExpr).To(BeTrue())
}
16 changes: 8 additions & 8 deletions test/e2e/v4/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func GenerateV4(kbc *utils.TestContext) {
"--programmatic-validation",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to scaffolding mutating webhook")

By("implementing the mutating and validating webhooks")
webhookFilePath := filepath.Join(
kbc.Dir, "internal/webhook", kbc.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind)))
err = utils.ImplementWebhooks(webhookFilePath, strings.ToLower(kbc.Kind))
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to implement webhooks")

scaffoldConversionWebhook(kbc)

Expand Down Expand Up @@ -95,14 +95,14 @@ func GenerateV4WithoutMetrics(kbc *utils.TestContext) {
"--programmatic-validation",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to scaffolding mutating webhook")

By("implementing the mutating and validating webhooks")
webhookFilePath := filepath.Join(
kbc.Dir, "internal/webhook", kbc.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind)))
err = utils.ImplementWebhooks(webhookFilePath, strings.ToLower(kbc.Kind))
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to implement webhooks")

scaffoldConversionWebhook(kbc)

Expand Down Expand Up @@ -158,14 +158,14 @@ func GenerateV4WithNetworkPolicies(kbc *utils.TestContext) {
"--programmatic-validation",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to scaffolding mutating webhook")

By("implementing the mutating and validating webhooks")
webhookFilePath := filepath.Join(
kbc.Dir, "internal/webhook", kbc.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind)))
err = utils.ImplementWebhooks(webhookFilePath, strings.ToLower(kbc.Kind))
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to implement webhooks")

scaffoldConversionWebhook(kbc)

Expand Down Expand Up @@ -222,7 +222,7 @@ func creatingAPI(kbc *utils.TestContext) {
"--controller",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to create API")

By("implementing the API")
ExpectWithOffset(1, pluginutil.InsertCode(
Expand All @@ -241,7 +241,7 @@ func initingTheProject(kbc *utils.TestContext) {
"--project-version", "3",
"--domain", kbc.Domain,
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "Failed to initialize project")
}

const metricsTarget = `- path: manager_metrics_patch.yaml
Expand Down
Loading