forked from Nomon/gonfig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflagset_test.go
45 lines (43 loc) · 1.29 KB
/
flagset_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
package unicon_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/pflag"
. "github.com/taybin/unicon"
)
var _ = Describe("FlagSetConfig", func() {
var (
err error
cfg ReadableConfig
)
BeforeEach(func() {
fs := pflag.NewFlagSet("arguments", pflag.ContinueOnError)
cfg = NewFlagSetConfig(fs, "")
err = cfg.Load()
Expect(err).ToNot(HaveOccurred())
})
It("Should load variables from commandline", func() {
Expect(len(cfg.All()) >= 0).To(BeTrue())
fs := pflag.NewFlagSet("arguments", pflag.ContinueOnError)
fs.Int("test", 1, "")
cfg2 := NewFlagSetConfig(fs, "")
cfg2.Load()
Expect(len(cfg2.All()) >= len(cfg.All())).To(BeTrue())
})
It("Should remove prefix from arguments", func() {
fs := pflag.NewFlagSet("arguments", pflag.ContinueOnError)
fs.Int("test-a", 1, "")
cfg2 := NewFlagSetConfig(fs, "test-")
cfg2.Load()
Expect(cfg2.GetInt("a")).To(Equal(1))
})
It("Should namespace arguments appropriately", func() {
fs := pflag.NewFlagSet("arguments", pflag.ContinueOnError)
fs.String("postgres-host", "localhost", "")
fs.Int("postgres-port", 5432, "")
cfg2 := NewFlagSetConfig(fs, "", "postgres")
cfg2.Load()
Expect(cfg2.Get("postgres.host")).To(Equal("localhost"))
Expect(cfg2.GetInt("postgres.port")).To(Equal(5432))
})
})