MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestGetValueWithKeyFromJSONString

Function TestGetValueWithKeyFromJSONString

backend/plugin/idp/util_test.go:42–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func 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}

Callers

nothing calls this directly

Calls 3

GetValueWithKeyFunction · 0.85
UnmarshalMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected