...
1
16
17 package process
18
19 import (
20 "os"
21
22 . "github.com/onsi/ginkgo/v2"
23 . "github.com/onsi/gomega"
24 )
25
26 var _ = Describe("BinPathFinder", func() {
27 var prevAssetPath string
28 BeforeEach(func() {
29 prevAssetPath = os.Getenv(EnvAssetsPath)
30 Expect(os.Unsetenv(EnvAssetsPath)).To(Succeed())
31 Expect(os.Unsetenv(EnvAssetOverridePrefix + "_SOME_FAKE")).To(Succeed())
32 Expect(os.Unsetenv(EnvAssetOverridePrefix + "OTHERFAKE")).To(Succeed())
33 })
34 AfterEach(func() {
35 if prevAssetPath != "" {
36 Expect(os.Setenv(EnvAssetsPath, prevAssetPath)).To(Succeed())
37 }
38 })
39 Context("when individual overrides are present", func() {
40 BeforeEach(func() {
41 Expect(os.Setenv(EnvAssetOverridePrefix+"OTHERFAKE", "/other/path")).To(Succeed())
42 Expect(os.Setenv(EnvAssetOverridePrefix+"_SOME_FAKE", "/some/path")).To(Succeed())
43
44 Expect(os.Setenv(EnvAssetsPath, "/global/path")).To(Succeed())
45 })
46
47 It("should prefer individual overrides, using them unmodified", func() {
48 Expect(BinPathFinder("otherfake", "/hardcoded/path")).To(Equal("/other/path"))
49 })
50
51 It("should convert lowercase to uppercase, remove leading numbers, and replace punctuation with underscores when resolving the env var name", func() {
52 Expect(BinPathFinder("123.some-fake", "/hardcoded/path")).To(Equal("/some/path"))
53 })
54 })
55
56 Context("when individual overrides are missing but the global override is present", func() {
57 BeforeEach(func() {
58 Expect(os.Setenv(EnvAssetsPath, "/global/path")).To(Succeed())
59 })
60 It("should prefer the global override, appending the name to that path", func() {
61 Expect(BinPathFinder("some-fake", "/hardcoded/path")).To(Equal("/global/path/some-fake"))
62 })
63 })
64
65 Context("when an asset directory is given and no overrides are present", func() {
66 It("should use the asset directory, appending the name to that path", func() {
67 Expect(BinPathFinder("some-fake", "/hardcoded/path")).To(Equal("/hardcoded/path/some-fake"))
68 })
69 })
70
71 Context("when no path configuration is given", func() {
72 It("should just use the default path", func() {
73 Expect(BinPathFinder("some-fake", "")).To(Equal("/usr/local/kubebuilder/bin/some-fake"))
74 })
75 })
76 })
77
View as plain text