/
key_test.go
52 lines (42 loc) · 1.44 KB
/
key_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
package flatpack_test
import (
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/xeger/flatpack"
)
func key(expr string) flatpack.Key {
parts := strings.Split(expr, ".")
return flatpack.Key(parts)
}
var _ = Describe("Key", func() {
It("has a useful zero value", func() {
Expect(flatpack.Key(nil).AsEnv()).To(Equal(""))
Expect(flatpack.Key(nil).String()).To(Equal(""))
Expect(flatpack.Key([]string{}).AsEnv()).To(Equal(""))
Expect(flatpack.Key([]string{}).String()).To(Equal(""))
})
Describe(".String()", func() {
It("uses dot notation", func() {
Expect(key("Dot.Separated").String()).To(Equal("Dot.Separated"))
})
})
Describe(".AsEnv()", func() {
It("separates pieces with underscore", func() {
Expect(key("Dot.Separated").AsEnv()).To(Equal("DOT_SEPARATED"))
Expect(key("Dot...Separated").AsEnv()).To(Equal("DOT_SEPARATED"))
})
It("separates CamelCase words with underscore", func() {
Expect(key("CamelCase").AsEnv()).To(Equal("CAMEL_CASE"))
Expect(key("CamelCASE").AsEnv()).To(Equal("CAMEL_CASE"))
})
It("leaves UPPERCASE words alone", func() {
Expect(key("URL").AsEnv()).To(Equal("URL"))
Expect(key("MyService.URL").AsEnv()).To(Equal("MY_SERVICE_URL"))
})
It("translates non-alphanumerics to underscore", func() {
Expect(key("weird-words-here").AsEnv()).To(Equal("WEIRD_WORDS_HERE"))
Expect(key("weird!@#@$words#$%(*here").AsEnv()).To(Equal("WEIRD_WORDS_HERE"))
})
})
})