Skip to content

Commit

Permalink
Merge pull request #148 from sapcc/fix-ginkgo-k8s
Browse files Browse the repository at this point in the history
Fix ginkgo for kubernetes controller development
  • Loading branch information
SuperSandro2000 authored Feb 29, 2024
2 parents 6bbaca0 + 8927faf commit b9ac6c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/core/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func Scan() ScanResult {
}
if v.Mod.Path == "k8s.io/api" {
kubernetesVersion = strings.ReplaceAll(v.Mod.Version, "v0", "1")
splitted := strings.Split(kubernetesVersion, ".")
kubernetesVersion = strings.Join(splitted[:len(splitted)-1], ".")
}
if v.Mod.Path == "sigs.k8s.io/controller-runtime" {
kubernetesController = true
Expand Down
9 changes: 6 additions & 3 deletions internal/makefile/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,22 @@ endif
},
}

testRunner := "go test -shuffle=on"
testRunner := "go test -shuffle=on -p 1 -coverprofile=$@"
if sr.UseGinkgo {
testRunner = "ginkgo run --randomize-all"
testRunner = "ginkgo run --randomize-all -output-dir=build"
testRule.prerequisites = append(testRule.prerequisites, "install-ginkgo")
}
goTest := fmt.Sprintf(`%s $(GO_BUILDFLAGS) -ldflags '%s $(GO_LDFLAGS)' -p 1 -coverprofile=$@ -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS)`,
goTest := fmt.Sprintf(`%s $(GO_BUILDFLAGS) -ldflags '%s $(GO_LDFLAGS)' -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(GO_TESTPKGS)`,
testRunner, makeDefaultLinkerFlags(path.Base(sr.MustModulePath()), sr))
if sr.KubernetesController {
testRule.prerequisites = append(testRule.prerequisites, "generate", "install-setup-envtest")
testRule.recipe = append(testRule.recipe, fmt.Sprintf(`KUBEBUILDER_ASSETS="$(shell setup-envtest use %s --bin-dir $(TESTBIN) -p path)" %s`, sr.KubernetesVersion, goTest))
} else {
testRule.recipe = append(testRule.recipe, `@env $(GO_TESTENV) `+goTest)
}
if sr.UseGinkgo {
testRule.recipe = append(testRule.recipe, `@mv build/coverprofile.out build/cover.out`)
}

test.addRule(testRule)

Expand Down

0 comments on commit b9ac6c3

Please sign in to comment.