-
Notifications
You must be signed in to change notification settings - Fork 5
/
config_test.go
56 lines (53 loc) · 1.77 KB
/
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
48
49
50
51
52
53
54
55
56
package main
import (
"flag"
"os"
"testing"
"github.com/g4s8/envdoc/testutils"
)
func TestConfig(t *testing.T) {
t.Run("parse flags", func(t *testing.T) {
var c Config
fs := flag.NewFlagSet("test", flag.ContinueOnError)
os.Args = []string{
"test",
"-types", "foo,bar",
"-files", "*",
"-output", "out.txt",
"-format", "plaintext",
"-env-prefix", "FOO",
"-no-styles",
"-field-names",
"-debug",
"-tag-name", "xenv",
"-tag-default", "default",
"-required-if-no-def",
}
if err := c.parseFlags(fs); err != nil {
t.Fatalf("unexpected error: %v", err)
}
testutils.AssertError(t, c.TypeGlob == "foo,bar", "unexpected TypeGlob: %q", c.TypeGlob)
testutils.AssertError(t, c.FileGlob == "*", "unexpected FileGlob: %q", c.FileGlob)
testutils.AssertError(t, c.OutFile == "out.txt", "unexpected OutFile: %q", c.OutFile)
testutils.AssertError(t, c.OutFormat == "plaintext", "unexpected OutFormat: %q", c.OutFormat)
testutils.AssertError(t, c.EnvPrefix == "FOO", "unexpected EnvPrefix: %q", c.EnvPrefix)
testutils.AssertError(t, c.NoStyles, "unexpected NoStyles: false")
testutils.AssertError(t, c.FieldNames, "unexpected FieldNames: false")
testutils.AssertError(t, c.Debug, "unexpected Debug: false")
testutils.AssertError(t, c.TagName == "xenv", "unexpected TagName: %q", c.TagName)
testutils.AssertError(t, c.TagDefault == "default", "unexpected TagDefault: %q", c.TagDefault)
testutils.AssertError(t, c.RequiredIfNoDef, "unexpected RequiredIfNoDef: false")
})
t.Run("normalize", func(t *testing.T) {
var c Config
c.TypeGlob = `"foo"`
c.FileGlob = `"*"`
c.normalize()
if c.TypeGlob != "foo" {
t.Errorf("unexpected TypeGlob: %q", c.TypeGlob)
}
if c.FileGlob != "*" {
t.Errorf("unexpected FileGlob: %q", c.FileGlob)
}
})
}