(t *testing.T)
| 1007 | } |
| 1008 | |
| 1009 | func TestInjectJSONProperties_Multiple(t *testing.T) { |
| 1010 | newKVs := []KVPair{ |
| 1011 | { |
| 1012 | Key: "newval", |
| 1013 | Val: 123, |
| 1014 | }, |
| 1015 | { |
| 1016 | Key: "test", |
| 1017 | Val: true, |
| 1018 | }, |
| 1019 | { |
| 1020 | Key: "asdf", |
| 1021 | Val: "qwerty", |
| 1022 | }, |
| 1023 | } |
| 1024 | |
| 1025 | tests := []struct { |
| 1026 | input string |
| 1027 | expectedOutput string |
| 1028 | expectedErr string |
| 1029 | }{ |
| 1030 | { |
| 1031 | input: ``, |
| 1032 | expectedErr: `not a JSON object`, |
| 1033 | }, |
| 1034 | { |
| 1035 | input: `null`, |
| 1036 | expectedErr: `not a JSON object`, |
| 1037 | }, |
| 1038 | { |
| 1039 | input: "123", |
| 1040 | expectedErr: `not a JSON object`, |
| 1041 | }, |
| 1042 | { |
| 1043 | input: "{}", |
| 1044 | expectedOutput: `{"newval":123,"test":true,"asdf":"qwerty"}`, |
| 1045 | }, |
| 1046 | { |
| 1047 | input: `{"key":"val"}`, |
| 1048 | expectedOutput: `{"key":"val","newval":123,"test":true,"asdf":"qwerty"}`, |
| 1049 | }, |
| 1050 | { |
| 1051 | input: `{"newval":"old"}`, |
| 1052 | expectedOutput: `{"newval":"old","newval":123,"test":true,"asdf":"qwerty"}`, |
| 1053 | }, |
| 1054 | { |
| 1055 | input: ` {"key":"val"} `, |
| 1056 | expectedOutput: `{"key":"val","newval":123,"test":true,"asdf":"qwerty"}`, |
| 1057 | }, |
| 1058 | } |
| 1059 | |
| 1060 | for _, test := range tests { |
| 1061 | t.Run(test.input, func(tt *testing.T) { |
| 1062 | output, err := InjectJSONProperties([]byte(test.input), newKVs...) |
| 1063 | if test.expectedErr != "" { |
| 1064 | require.Errorf(tt, err, test.expectedErr, "expected error did not match") |
| 1065 | return |
| 1066 | } else { |
nothing calls this directly
no test coverage detected