(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func TestContainer(t *testing.T) { |
| 47 | ctx := context.Background() |
| 48 | t.Run("method=NewFromJSON", func(t *testing.T) { |
| 49 | for k, tc := range []struct { |
| 50 | r string |
| 51 | prefix string |
| 52 | expect *Container |
| 53 | }{ |
| 54 | { |
| 55 | r: `{"numby":1.5,"stringy":"foobar","objy":{"objy":{},"numby":1.5,"stringy":"foobar"}}`, |
| 56 | expect: &Container{ |
| 57 | Nodes: node.Nodes{ |
| 58 | node.NewInputFieldFromJSON("numby", 1.5, node.DefaultGroup), |
| 59 | node.NewInputFieldFromJSON("objy.numby", 1.5, node.DefaultGroup), |
| 60 | node.NewInputFieldFromJSON("objy.stringy", "foobar", node.DefaultGroup), |
| 61 | node.NewInputFieldFromJSON("stringy", "foobar", node.DefaultGroup), |
| 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | { |
| 66 | r: `{"numby":1.5,"stringy":"foobar","objy":{"objy":{},"numby":1.5,"stringy":"foobar"}}`, |
| 67 | prefix: "traits", |
| 68 | expect: &Container{ |
| 69 | Nodes: node.Nodes{ |
| 70 | node.NewInputFieldFromJSON("traits.numby", 1.5, node.DefaultGroup), |
| 71 | node.NewInputFieldFromJSON("traits.objy.numby", 1.5, node.DefaultGroup), |
| 72 | node.NewInputFieldFromJSON("traits.objy.stringy", "foobar", node.DefaultGroup), |
| 73 | node.NewInputFieldFromJSON("traits.stringy", "foobar", node.DefaultGroup), |
| 74 | }, |
| 75 | }, |
| 76 | }, |
| 77 | } { |
| 78 | t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) { |
| 79 | actual := NewFromJSON("action", node.DefaultGroup, json.RawMessage(tc.r), tc.prefix) |
| 80 | |
| 81 | // sort actual.fields lexicographically to have a deterministic order |
| 82 | sort.SliceStable(actual.Nodes, func(i, j int) bool { |
| 83 | return actual.Nodes[i].ID() < actual.Nodes[j].ID() |
| 84 | }) |
| 85 | |
| 86 | assert.Equal(t, "action", actual.Action) |
| 87 | assert.EqualValues(t, tc.expect.Nodes, actual.Nodes) |
| 88 | }) |
| 89 | } |
| 90 | }) |
| 91 | |
| 92 | t.Run("method=NewFromHTTPRequest", func(t *testing.T) { |
| 93 | for k, tc := range []struct { |
| 94 | ref string |
| 95 | r *http.Request |
| 96 | expect *Container |
| 97 | }{ |
| 98 | { |
| 99 | ref: "./stub/simple.schema.json", |
| 100 | r: newJSONRequest(t, `{"numby":1.5,"stringy":"foobar","objy":{"objy":{},"numby":1.5,"stringy":"foobar"}}`), |
| 101 | expect: &Container{ |
| 102 | Nodes: node.Nodes{ |
| 103 | node.NewInputFieldFromJSON("numby", 1.5, node.DefaultGroup), |
nothing calls this directly
no test coverage detected