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

Function TestInjectJSONPropertiesFromBytes_Multiple

base/util_test.go:1139–1207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1137}
1138
1139func TestInjectJSONPropertiesFromBytes_Multiple(t *testing.T) {
1140 newKVBytes := []KVPairBytes{
1141 {
1142 Key: "newval",
1143 Val: []byte(`{"abc":123,"nums":["one","two","three"],"test":true}`),
1144 },
1145 {
1146 Key: "test",
1147 Val: []byte(`true`),
1148 },
1149 {
1150 Key: "asdf",
1151 Val: []byte(`"qwerty"`),
1152 },
1153 }
1154
1155 tests := []struct {
1156 input string
1157 expectedOutput string
1158 expectedErr string
1159 }{
1160 {
1161 input: ``,
1162 expectedErr: `not a JSON object`,
1163 },
1164 {
1165 input: `null`,
1166 expectedErr: `not a JSON object`,
1167 },
1168 {
1169 input: "123",
1170 expectedErr: `not a JSON object`,
1171 },
1172 {
1173 input: "{}",
1174 expectedOutput: `{"newval":{"abc":123,"nums":["one","two","three"],"test":true},"test":true,"asdf":"qwerty"}`,
1175 },
1176 {
1177 input: `{"key":"val"}`,
1178 expectedOutput: `{"key":"val","newval":{"abc":123,"nums":["one","two","three"],"test":true},"test":true,"asdf":"qwerty"}`,
1179 },
1180 {
1181 input: `{"newval":"old"}`,
1182 expectedOutput: `{"newval":"old","newval":{"abc":123,"nums":["one","two","three"],"test":true},"test":true,"asdf":"qwerty"}`,
1183 },
1184 {
1185 input: ` {"key":"val"} `,
1186 expectedOutput: `{"key":"val","newval":{"abc":123,"nums":["one","two","three"],"test":true},"test":true,"asdf":"qwerty"}`,
1187 },
1188 }
1189
1190 for _, test := range tests {
1191 t.Run(test.input, func(tt *testing.T) {
1192 output, err := InjectJSONPropertiesFromBytes([]byte(test.input), newKVBytes...)
1193 if test.expectedErr != "" {
1194 require.Errorf(tt, err, test.expectedErr, "expected error did not match")
1195 return
1196 } else {

Callers

nothing calls this directly

Calls 5

ErrorfMethod · 0.80
JSONUnmarshalFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected