File tree 4 files changed +61
-2
lines changed
4 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ package config
5
5
import (
6
6
"context"
7
7
"io/fs"
8
+ "os"
9
+ "runtime"
8
10
"strconv"
9
11
"strings"
10
12
@@ -39,7 +41,7 @@ type Config struct {
39
41
// Unclear if this value will be needed with the golang implementation.
40
42
// AsdfDir string
41
43
DataDir string `env:"ASDF_DATA_DIR, overwrite"`
42
- ForcePrepend bool `env:"ASDF_FORCE_PREPEND, overwrite"`
44
+ ForcePrepend bool
43
45
// Field that stores the settings struct if it is loaded
44
46
Settings Settings
45
47
PluginIndexURL string
@@ -59,8 +61,13 @@ type Settings struct {
59
61
}
60
62
61
63
func defaultConfig (dataDir , configFile string ) * Config {
64
+ forcePrepend := forcePrependDefault
65
+ forcePrependEnv := os .Getenv ("ASDF_FORCE_PREPEND" )
66
+ if forcePrependEnv == "yes" || (forcePrependEnv == "" && runtime .GOOS == "darwin" ) {
67
+ forcePrepend = true
68
+ }
62
69
return & Config {
63
- ForcePrepend : forcePrependDefault ,
70
+ ForcePrepend : forcePrepend ,
64
71
DataDir : dataDir ,
65
72
ConfigFile : configFile ,
66
73
DefaultToolVersionsFilename : defaultToolVersionsFilenameDefault ,
Original file line number Diff line number Diff line change
1
+ //go:build darwin
2
+
3
+ package config
4
+
5
+ import (
6
+ "testing"
7
+
8
+ "github.com/stretchr/testify/assert"
9
+ )
10
+
11
+ func TestLoadConfigEnv_WithForcePrependEnv_OnDarwin (t * testing.T ) {
12
+ t .Run ("When ASDF_FORCE_PREPEND env does not given on macOS" , func (t * testing.T ) {
13
+ config , _ := loadConfigEnv ()
14
+
15
+ assert .True (t , config .ForcePrepend , "Then ForcePrepend property is true" )
16
+ })
17
+ }
Original file line number Diff line number Diff line change
1
+ //go:build linux
2
+
3
+ package config
4
+
5
+ import (
6
+ "testing"
7
+
8
+ "github.com/stretchr/testify/assert"
9
+ )
10
+
11
+ func TestLoadConfigEnv_WithForcePrependEnv_OnLinux (t * testing.T ) {
12
+ t .Run ("When ASDF_FORCE_PREPEND env does not given on Linux" , func (t * testing.T ) {
13
+ config , _ := loadConfigEnv ()
14
+
15
+ assert .False (t , config .ForcePrepend , "Then ForcePrepend property is false" )
16
+ })
17
+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,24 @@ func TestLoadConfigEnv(t *testing.T) {
22
22
assert .Zero (t , config .Home , "Shouldn't set Home property when loading config" )
23
23
}
24
24
25
+ func TestLoadConfigEnv_WithForcePrependEnv (t * testing.T ) {
26
+ t .Run ("When ASDF_FORCE_PREPEND env given yes" , func (t * testing.T ) {
27
+ t .Setenv ("ASDF_FORCE_PREPEND" , "yes" )
28
+
29
+ config , _ := loadConfigEnv ()
30
+
31
+ assert .True (t , config .ForcePrepend , "Then ForcePrepend property is true" )
32
+ })
33
+
34
+ t .Run ("When ASDF_FORCE_PREPEND env given any string other than yes" , func (t * testing.T ) {
35
+ t .Setenv ("ASDF_FORCE_PREPEND" , "no" )
36
+
37
+ config , _ := loadConfigEnv ()
38
+
39
+ assert .False (t , config .ForcePrepend , "Then ForcePrepend property is false" )
40
+ })
41
+ }
42
+
25
43
func TestLoadSettings (t * testing.T ) {
26
44
t .Run ("When given invalid path returns error" , func (t * testing.T ) {
27
45
settings , err := loadSettings ("./foobar" )
You can’t perform that action at this time.
0 commit comments