(t *testing.T)
| 44 | ) |
| 45 | |
| 46 | func 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 |
nothing calls this directly
no test coverage detected