@@ -8,59 +8,53 @@ import (
8
8
)
9
9
10
10
var _ = Describe ("BinPathFinder" , func () {
11
- Context ("when relying on the default assets path" , func () {
12
- var (
13
- previousAssetsPath string
14
- )
11
+ var prevAssetPath string
12
+ BeforeEach (func () {
13
+ prevAssetPath = os .Getenv (EnvAssetsPath )
14
+ Expect (os .Unsetenv (EnvAssetsPath )).To (Succeed ())
15
+ Expect (os .Unsetenv (EnvAssetOverridePrefix + "_SOME_FAKE" ))
16
+ Expect (os .Unsetenv (EnvAssetOverridePrefix + "OTHERFAKE" ))
17
+ })
18
+ AfterEach (func () {
19
+ if prevAssetPath != "" {
20
+ Expect (os .Setenv (EnvAssetsPath , prevAssetPath ))
21
+ }
22
+ })
23
+ Context ("when individual overrides are present" , func () {
15
24
BeforeEach (func () {
16
- previousAssetsPath = assetsPath
17
- assetsPath = "/some/path/assets/bin"
25
+ Expect (os .Setenv (EnvAssetOverridePrefix + "OTHERFAKE" , "/other/path" )).To (Succeed ())
26
+ Expect (os .Setenv (EnvAssetOverridePrefix + "_SOME_FAKE" , "/some/path" )).To (Succeed ())
27
+ // set the global path to make sure we don't prefer it
28
+ Expect (os .Setenv (EnvAssetsPath , "/global/path" )).To (Succeed ())
18
29
})
19
- AfterEach (func () {
20
- assetsPath = previousAssetsPath
30
+
31
+ It ("should prefer individual overrides, using them unmodified" , func () {
32
+ Expect (BinPathFinder ("otherfake" , "/hardcoded/path" )).To (Equal ("/other/path" ))
21
33
})
22
- It ( "returns the default path when no env var is configured" , func () {
23
- binPath := BinPathFinder ( "some_bin" )
24
- Expect (binPath ) .To (Equal ("/some/path/assets/bin/some_bin " ))
34
+
35
+ It ( "should convert lowercase to uppercase, remove leading numbers, and replace punctuation with underscores when resolving the env var name" , func () {
36
+ Expect (BinPathFinder ( "123.some-fake" , "/hardcoded/path" )) .To (Equal ("/some/path" ))
25
37
})
26
38
})
27
39
28
- Context ("when environment is configured" , func () {
29
- var (
30
- previousValue string
31
- wasSet bool
32
- )
40
+ Context ("when individual overrides are missing but the global override is present" , func () {
33
41
BeforeEach (func () {
34
- envVarName := "TEST_ASSET_ANOTHER_SYMBOLIC_NAME"
35
- if val , ok := os .LookupEnv (envVarName ); ok {
36
- previousValue = val
37
- wasSet = true
38
- }
39
- os .Setenv (envVarName , "/path/to/some_bin.exe" )
42
+ Expect (os .Setenv (EnvAssetsPath , "/global/path" )).To (Succeed ())
40
43
})
41
- AfterEach (func () {
42
- if wasSet {
43
- os .Setenv ("TEST_ASSET_ANOTHER_SYMBOLIC_NAME" , previousValue )
44
- } else {
45
- os .Unsetenv ("TEST_ASSET_ANOTHER_SYMBOLIC_NAME" )
46
- }
44
+ It ("should prefer the global override, appending the name to that path" , func () {
45
+ Expect (BinPathFinder ("some-fake" , "/hardcoded/path" )).To (Equal ("/global/path/some-fake" ))
47
46
})
48
- It ("returns the path from the env" , func () {
49
- binPath := BinPathFinder ("another_symbolic_name" )
50
- Expect (binPath ).To (Equal ("/path/to/some_bin.exe" ))
47
+ })
48
+
49
+ Context ("when an asset directory is given and no overrides are present" , func () {
50
+ It ("should use the asset directory, appending the name to that path" , func () {
51
+ Expect (BinPathFinder ("some-fake" , "/hardcoded/path" )).To (Equal ("/hardcoded/path/some-fake" ))
51
52
})
53
+ })
52
54
53
- It ("sanitizes the environment variable name" , func () {
54
- By ("cleaning all non-underscore punctuation" )
55
- binPath := BinPathFinder ("another-symbolic name" )
56
- Expect (binPath ).To (Equal ("/path/to/some_bin.exe" ))
57
- binPath = BinPathFinder ("another+symbolic\\ name" )
58
- Expect (binPath ).To (Equal ("/path/to/some_bin.exe" ))
59
- binPath = BinPathFinder ("another=symbolic.name" )
60
- Expect (binPath ).To (Equal ("/path/to/some_bin.exe" ))
61
- By ("removing numbers from the beginning of the name" )
62
- binPath = BinPathFinder ("12another_symbolic_name" )
63
- Expect (binPath ).To (Equal ("/path/to/some_bin.exe" ))
55
+ Context ("when no path configuration is given" , func () {
56
+ It ("should just use the default path" , func () {
57
+ Expect (BinPathFinder ("some-fake" , "" )).To (Equal ("/usr/local/kubebuilder/bin/some-fake" ))
64
58
})
65
59
})
66
60
})
0 commit comments