forked from Nomon/gonfig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemory_test.go
48 lines (46 loc) · 1.31 KB
/
memory_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
package unicon_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/taybin/unicon"
)
var _ = Describe("MemoryConfig", func() {
var cfg Configurable
BeforeEach(func() {
cfg = NewMemoryConfig()
})
It("Should be able to store and retrieve data", func() {
cfg.Set("test", "abc")
Expect(cfg.Get("test")).To(Equal("abc"))
})
It("Should Reset() to zero length All()", func() {
cfg.Set("test", "abc")
Expect(cfg.Get("test")).To(Equal("abc"))
Expect(len(cfg.All())).To(Equal(1))
cfg.Reset()
Expect(len(cfg.All())).To(Equal(0))
})
It("Should Reset() with data correctly", func() {
cfg.Set("test", "abc")
cfg.Set("test_abc", "123")
Expect(cfg.Get("test")).To(Equal("abc"))
Expect(len(cfg.All())).To(Equal(2))
cfg2 := NewMemoryConfig()
cfg2.Reset(cfg.All())
Expect(cfg.Get("test")).To(Equal(cfg2.Get("test")))
})
It("Should be case insensitive", func() {
cfg.Set("test", "abc")
cfg.Set("TEST", "def")
Expect(cfg.Get("test")).To(Equal("def"))
Expect(cfg.Get("TEST")).To(Equal("def"))
Expect(cfg.Get("TeSt")).To(Equal("def"))
})
It("Should be case preserving", func() {
cfg.Set("tEsT", "abc")
Expect(len(cfg.All())).To(Equal(1))
Expect(cfg.All()["tEsT"]).To(Equal("abc"))
Expect(cfg.All()["test"]).To(BeNil())
Expect(cfg.All()["TEST"]).To(BeNil())
})
})