github.com/harryzcy/snuuze@v0.3.3-0.20240314015559-83a8fc5627a8/config/config_test.go (about) 1 package config 2 3 import ( 4 "os" 5 "path/filepath" 6 "runtime" 7 "strings" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 var ( 14 _, b, _, _ = runtime.Caller(0) 15 basepath = filepath.Dir(b) 16 ) 17 18 func TestMain(m *testing.M) { 19 if strings.HasSuffix(basepath, "snuuze/config") { 20 err := os.Chdir("../") 21 if err != nil { 22 panic(err) 23 } 24 } 25 26 err := os.Chdir("./testdata") 27 if err != nil { 28 panic(err) 29 } 30 os.Exit(m.Run()) 31 } 32 33 func TestConfig(t *testing.T) { 34 err := LoadConfig() 35 if err != nil { 36 t.Error(err) 37 } 38 39 config := GetConfig() 40 assert.Equal(t, "1", config.Version) 41 42 rules := GetRules() 43 assert.Len(t, rules, 1) 44 }