(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func TestGetValueWithKeyFromJSONString(t *testing.T) { |
| 43 | tests := []struct { |
| 44 | data string |
| 45 | key string |
| 46 | want any |
| 47 | }{ |
| 48 | { |
| 49 | data: `{"user": "test"}`, |
| 50 | key: "user", |
| 51 | want: "test", |
| 52 | }, |
| 53 | { |
| 54 | data: `{"user":"test","data":{"user":"data-user"}}`, |
| 55 | key: "data.user", |
| 56 | want: "data-user", |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | for _, test := range tests { |
| 61 | var data map[string]any |
| 62 | err := json.Unmarshal([]byte(test.data), &data) |
| 63 | require.NoError(t, err) |
| 64 | got := GetValueWithKey(data, test.key) |
| 65 | if test.want != got { |
| 66 | t.Errorf("GetValueWithKey got %v but want %v", got, test.want) |
| 67 | } |
| 68 | } |
| 69 | } |
nothing calls this directly
no test coverage detected