MCPcopy
hub / github.com/TomWright/dasel / TestMap

Function TestMap

model/value_map_test.go:11–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestMap(t *testing.T) {
12 standardMap := func() *model.Value {
13 return model.NewValue(map[string]interface{}{
14 "foo": "foo1",
15 "bar": "bar1",
16 })
17 }
18
19 dencodingMap := func() *model.Value {
20 return model.NewValue(orderedmap.NewMap().
21 Set("foo", "foo1").
22 Set("bar", "bar1"))
23 }
24
25 modelMap := func() *model.Value {
26 res := model.NewMapValue()
27 if err := res.SetMapKey("foo", model.NewValue("foo1")); err != nil {
28 t.Fatalf("unexpected error: %s", err)
29 }
30 if err := res.SetMapKey("bar", model.NewValue("bar1")); err != nil {
31 t.Fatalf("unexpected error: %s", err)
32 }
33 return res
34 }
35
36 runTests := func(v func() *model.Value) func(t *testing.T) {
37 return func(t *testing.T) {
38 t.Run("IsMap", func(t *testing.T) {
39 v := v()
40 if !v.IsMap() {
41 t.Errorf("expected value to be a map")
42 }
43 })
44 t.Run("GetMapKey", func(t *testing.T) {
45 v := v()
46 foo, err := v.GetMapKey("foo")
47 if err != nil {
48 t.Errorf("unexpected error: %s", err)
49 return
50 }
51 got, err := foo.StringValue()
52 if err != nil {
53 t.Errorf("unexpected error: %s", err)
54 return
55 }
56 if got != "foo1" {
57 t.Errorf("expected foo1, got %s", got)
58 }
59 })
60 t.Run("SetMapKey", func(t *testing.T) {
61 v := v()
62 if err := v.SetMapKey("baz", model.NewValue("baz1")); err != nil {
63 t.Errorf("unexpected error: %s", err)
64 return
65 }
66 baz, err := v.GetMapKey("baz")
67 if err != nil {
68 t.Errorf("unexpected error: %s", err)

Callers

nothing calls this directly

Calls 12

NewValueFunction · 0.92
NewMapFunction · 0.92
NewMapValueFunction · 0.92
SetMapKeyMethod · 0.80
IsMapMethod · 0.80
GetMapKeyMethod · 0.80
StringValueMethod · 0.80
MapKeysMethod · 0.80
RangeMapMethod · 0.80
DeleteMapKeyMethod · 0.80
SetMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected