(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func 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) |
nothing calls this directly
no test coverage detected