-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig_test.go
47 lines (33 loc) · 948 Bytes
/
config_test.go
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
46
47
package check
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func ExampleConfig() {
config := NewConfig()
config.Name = "check_test"
config.Readme = `Test Plugin`
config.Version = "1.0.0"
_ = config.FlagSet.StringP("hostname", "H", "localhost", "Hostname to check")
config.ParseArguments()
// Some checking should be done here
Exitf(OK, "Everything is fine - answer=%d", 42)
// Output: [OK] - Everything is fine - answer=42
// would exit with code 0
}
type ConfigForTesting struct {
Auth string `env:"AUTH"`
Bearer string `env:"EXAMPLE"`
OneMoreThanTags string
}
func TestLoadFromEnv(t *testing.T) {
c := ConfigForTesting{}
err := os.Setenv("EXAMPLE", "foobar")
defer os.Unsetenv("EXAMPLE") // just to not create any side effects
assert.NoError(t, err)
LoadFromEnv(&c)
assert.Equal(t, "foobar", c.Bearer)
assert.Equal(t, "", c.Auth)
assert.Equal(t, "", c.OneMoreThanTags)
}