MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestReadServerConfig

Function TestReadServerConfig

rest/config_test.go:46–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44)
45
46func TestReadServerConfig(t *testing.T) {
47
48 tests := []struct {
49 name string
50 config string
51 errStdlib string
52 errJSONIter string
53 }{
54 {
55 name: "nil",
56 config: ``,
57 errStdlib: "EOF",
58 errJSONIter: "EOF",
59 },
60 {
61 name: "valid empty",
62 config: `{}`,
63 },
64 {
65 name: "valid minimal",
66 config: `{"logging": {"console": {"enabled": true}}}`,
67 },
68 {
69 name: "unknown field",
70 config: `{"invalid": true}`,
71 errStdlib: `json: unknown field "invalid": unrecognized JSON field`,
72 errJSONIter: `found unknown field: invalid`,
73 },
74 {
75 name: "incorrect type",
76 config: `{"logging": true}`,
77 errStdlib: `json: cannot unmarshal bool into Go struct field LegacyServerConfig.Logging of type base.LegacyLoggingConfig`,
78 errJSONIter: `expect { or n, but found t`,
79 },
80 {
81 name: "invalid JSON",
82 config: `{true}`,
83 errStdlib: `invalid character 't' looking for beginning of object key string`,
84 errJSONIter: `expects " or n, but found t`,
85 },
86 {
87 name: "sync fn backquotes",
88 config: "{\"databases\": {\"db\": {\"sync\": `function(doc, oldDoc) {channel(doc.channels)}`}}}",
89 },
90 }
91
92 for _, test := range tests {
93 t.Run(test.name, func(tt *testing.T) {
94 buf := bytes.NewBufferString(test.config)
95 _, err := readLegacyServerConfig(base.TestCtx(t), buf)
96
97 // stdlib/CE specific error checking
98 expectedErr := test.errStdlib
99 if !base.UseStdlibJSON && base.IsEnterpriseEdition() {
100 // jsoniter specific error checking
101 expectedErr = test.errJSONIter
102 }
103

Callers

nothing calls this directly

Calls 6

TestCtxFunction · 0.92
IsEnterpriseEditionFunction · 0.92
readLegacyServerConfigFunction · 0.85
RunMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected