MCPcopy Create free account
hub / github.com/amp-labs/connectors / TestStringMap

Function TestStringMap

common/stringMap_test.go:13–179  ·  view source on GitHub ↗

nolint:funlen,gocognit, cyclop

(t *testing.T)

Source from the content-addressed store, hash-verified

11
12//nolint:funlen,gocognit, cyclop
13func TestStringMap(t *testing.T) {
14 t.Parallel()
15
16 //nolint:varnamelen
17 m := StringMap{
18 "string": "string",
19 "int": 1,
20 "float": 1.1,
21 "map": map[string]any{"key": "value"},
22 "bool": true,
23 }
24
25 t.Run("Get", func(t *testing.T) {
26 t.Parallel()
27
28 want := "string"
29 got, err := m.Get("string")
30
31 require.NoError(t, err)
32 assert.Equal(t, want, got)
33
34 var want2 any = nil
35
36 got2, err2 := m.Get("notfound")
37
38 require.Error(t, err2)
39 assert.Equal(t, want2, got2)
40
41 want3 := map[string]any{"key": "value"}
42 got3, err3 := m.Get("map")
43
44 require.NoError(t, err3)
45 assert.Equal(t, want3, got3)
46 })
47
48 t.Run("GetInt", func(t *testing.T) {
49 t.Parallel()
50
51 want := int64(1)
52 got, err := m.GetInt("int")
53
54 require.NoError(t, err)
55 assert.Equal(t, want, got)
56
57 keysWithIntValues := []string{"int"}
58
59 for k := range m {
60 got, err := m.GetInt(k)
61 if !slices.Contains(keysWithIntValues, k) {
62 require.Error(t, err)
63 assert.Equal(t, int64(0), got)
64 }
65 }
66 })
67
68 t.Run("GetFloat", func(t *testing.T) {
69 t.Parallel()
70

Callers

nothing calls this directly

Calls 10

GetMethod · 0.95
GetIntMethod · 0.95
GetFloatMethod · 0.95
AsIntMethod · 0.95
AsFloatMethod · 0.95
GetBoolMethod · 0.95
GetStringMethod · 0.95
ContainsMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected