diff options
| author | ewy <ewy0@protonmail.com> | 2026-05-16 23:14:31 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-05-16 23:14:31 +0200 |
| commit | 12660587d91f8f1b063a3f94ad14b54456dce214 (patch) | |
| tree | 02b84418ce0c28ca5bed6e48c25c3b257bd20fa4 | |
| parent | 00379affbb5f8483fcda9bcf2291106fac574110 (diff) | |
add methods for overriding paths during tests
| -rw-r--r-- | paths/paths.go | 8 | ||||
| -rw-r--r-- | paths/paths_test.go | 45 |
2 files changed, 52 insertions, 1 deletions
diff --git a/paths/paths.go b/paths/paths.go index 9f27385..cc0c878 100644 --- a/paths/paths.go +++ b/paths/paths.go @@ -7,7 +7,13 @@ import ( "strings" ) -var Home, This, Cache, Config, Ifs string +var ( + Ifs string + Config string + Cache string + This string + Home string +) type paths struct { Initialized bool diff --git a/paths/paths_test.go b/paths/paths_test.go new file mode 100644 index 0000000..8ab3461 --- /dev/null +++ b/paths/paths_test.go @@ -0,0 +1,45 @@ +//go:build test + +package paths + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +var bHome, bThis, bCache, bConfig string + +// Set temporarily sets the paths for unit test purposes +// remember to defer Reset +func Set(home, this, cache, config string) { + bHome = Home + bThis = This + bCache = Cache + bConfig = Config + + Home = home + This = this + Cache = cache + Config = config +} + +// Reset sets the path variables back to before the unit test +func Reset() { + Home = bHome + This = bThis + Cache = bCache + Config = bConfig +} + +func TestSetAndReset(t *testing.T) { + Set("1", "2", "3", "4") + assert.Equal(t, Home, "1") + assert.Equal(t, This, "2") + assert.Equal(t, Cache, "3") + assert.Equal(t, Config, "4") + Reset() + assert.NotEqual(t, Home, "1") + assert.NotEqual(t, This, "2") + assert.NotEqual(t, Cache, "3") + assert.NotEqual(t, Config, "4") +} |
