-
Notifications
You must be signed in to change notification settings - Fork 3
/
report_test.go
57 lines (46 loc) · 1.87 KB
/
report_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
57
package envstruct_test
import (
"bytes"
"os"
envstruct "code.cloudfoundry.org/go-envstruct"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Report", func() {
var (
ts SmallTestStruct
outputText string
)
Describe("Report()", func() {
BeforeEach(func() {
for k, v := range baseEnvVars {
os.Setenv(k, v)
}
err := envstruct.Load(&ts)
Expect(err).ToNot(HaveOccurred())
outputBuffer := bytes.NewBuffer(nil)
envstruct.ReportWriter = outputBuffer
err = envstruct.WriteReport(&ts)
Expect(err).ToNot(HaveOccurred())
outputText = outputBuffer.String()
})
It("prints a report of the given envstruct struct", func() {
Expect(outputText).To(Equal(expectedReportOutput))
})
})
})
const (
expectedReportOutput = `FIELD NAME: TYPE: ENV: REQUIRED: VALUE:
SmallTestStruct.HiddenThing string HIDDEN_THING false (OMITTED)
SmallTestStruct.StringThing string STRING_THING false stringy thingy
SmallTestStruct.BoolThing bool BOOL_THING false true
SmallTestStruct.IntThing int INT_THING false 100
SmallTestStruct.FloatThing float64 FLOAT_THING false 3.14159
SmallTestStruct.ComplexThing complex128 COMPLEX_THING false (3+14159i)
SmallTestStruct.URLThing *url.URL URL_THING false http://github.com/some/path
SmallTestStruct.StringSliceThing []string STRING_SLICE_THING false [one two three]
SmallTestStruct.CaseSensitiveThing string CASE_SENSITIVE_THING false case sensitive
SmallTestSubStruct.SecretThing string SECRET_THING false (OMITTED)
SmallTestSubStruct.SecretThing string SECRET_THING false (OMITTED)
`
)