1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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")
}
|