diff --git a/node/action_test.go b/node/action_test.go index e1f042ba..445216e3 100644 --- a/node/action_test.go +++ b/node/action_test.go @@ -44,7 +44,7 @@ module m { prefix ""; namespace ""; revision 0; return nodeutil.ReflectChild(out), nil }, }) - in := nodeutil.ReadJSON(`{"name":"joe"}`) + in, _ := nodeutil.ReadJSON(`{"name":"joe"}`) sel, err := b.Root().Find("sayHello") fc.RequireEqual(t, nil, err) out, err := sel.Action(in) diff --git a/node/check_when_test.go b/node/check_when_test.go index 103d2aa2..415ebbd0 100644 --- a/node/check_when_test.go +++ b/node/check_when_test.go @@ -69,7 +69,8 @@ func TestWhen(t *testing.T) { t.Fatal(err) } for _, d := range test.data { - b := node.NewBrowser(m, nodeutil.ReadJSON(d.in)) + n, _ := nodeutil.ReadJSON(d.in) + b := node.NewBrowser(m, n) actual, err := nodeutil.WriteJSON(b.Root()) if err != nil { t.Error(err) diff --git a/node/edit_test.go b/node/edit_test.go index c21ca45d..316245be 100644 --- a/node/edit_test.go +++ b/node/edit_test.go @@ -27,7 +27,7 @@ func TestChoiceInAction(t *testing.T) { leaf y { type string; } - } + } } } }` @@ -44,7 +44,7 @@ func TestChoiceInAction(t *testing.T) { } root := node.NewBrowser(m, n).Root() expected := `{"x":"hello"}` - in := nodeutil.ReadJSON(expected) + in, _ := nodeutil.ReadJSON(expected) sel, err := root.Find("r") fc.RequireEqual(t, nil, err) _, err = sel.Action(in) @@ -157,11 +157,12 @@ func TestChoiceLeafUpsert(t *testing.T) { b := node.NewBrowser(m, nodeutil.ReflectChild(data)) sel, err := b.Root().Find("a") fc.RequireEqual(t, nil, err) - err = sel.UpsertFrom(nodeutil.ReadJSON(` + n, _ := nodeutil.ReadJSON(` { "bb" : "y" } - `)) + `) + err = sel.UpsertFrom(n) fc.RequireEqual(t, nil, err) actual, err := nodeutil.WriteJSON(sel) fc.RequireEqual(t, nil, err) @@ -205,11 +206,12 @@ func TestChoiceContainerUpsert(t *testing.T) { } b := node.NewBrowser(m, nodeutil.ReflectChild(data)) sel := b.Root() - err = sel.UpsertFrom(nodeutil.ReadJSON(` + n, _ := nodeutil.ReadJSON(` { "b" : {"bb" : "y"} } - `)) + `) + err = sel.UpsertFrom(n) fc.AssertEqual(t, nil, err) actual, err := nodeutil.WriteJSON(sel) fc.AssertEqual(t, nil, err) @@ -380,7 +382,7 @@ func TestEditListItem(t *testing.T) { } root := testDataRoot() bd := nodeutil.ReflectChild(root) - json := nodeutil.ReadJSON(`{"origin":{"country":"Canada"}}`) + json, _ := nodeutil.ReadJSON(`{"origin":{"country":"Canada"}}`) // UPDATE // Here we're testing editing a specific list item. With FindTarget walk controller @@ -414,7 +416,7 @@ func TestEditListItem(t *testing.T) { } ] }` - json = nodeutil.ReadJSON(insertData) + json, _ = nodeutil.ReadJSON(insertData) sel, err = rootSel.Find("fruits") fc.RequireEqual(t, nil, err) fc.RequireEqual(t, nil, sel.InsertFrom(json)) @@ -441,7 +443,7 @@ func TestEditChoiceInGroup(t *testing.T) { } } } - + uses g; `, data: `{"a":"hi"}`, @@ -453,19 +455,19 @@ func TestEditChoiceInGroup(t *testing.T) { leaf e { type string; } - choice q { + choice q { case a { container a { leaf aa { type string; - } + } } } case b { container b { leaf bb { type string; - } + } } } } @@ -495,7 +497,8 @@ func TestEditChoiceInGroup(t *testing.T) { data := make(map[string]interface{}) n := nodeutil.ReflectChild(data) b := node.NewBrowser(m, n) - err = b.Root().UpsertFromSetDefaults(nodeutil.ReadJSON(test.data)) + in, _ := nodeutil.ReadJSON(test.data) + err = b.Root().UpsertFromSetDefaults(in) if err != nil { t.Fatal(err) } diff --git a/node/field_constraints_browser_test.go b/node/field_constraints_browser_test.go index 211376de..1db52e5c 100644 --- a/node/field_constraints_browser_test.go +++ b/node/field_constraints_browser_test.go @@ -34,7 +34,8 @@ func TestFieldConstraintsRequests(t *testing.T) { data := make(map[string]interface{}) b := node.NewBrowser(m, nodeutil.ReflectChild(data)) root := b.Root() - err = root.UpsertFrom(nodeutil.ReadJSON(test.JSON)) + n, _ := nodeutil.ReadJSON(test.JSON) + err = root.UpsertFrom(n) fc.AssertEqual(t, test.valid, err == nil, test.JSON) } } diff --git a/node/fields_matcher_test.go b/node/fields_matcher_test.go index 10c128ab..2ed02ad7 100644 --- a/node/fields_matcher_test.go +++ b/node/fields_matcher_test.go @@ -25,7 +25,7 @@ module x { if err != nil { t.Fatal(err) } - n := nodeutil.ReadJSON(` + n, _ := nodeutil.ReadJSON(` { "a" : { "a": "A", @@ -58,7 +58,7 @@ module x { if err != nil { t.Fatal(err) } - n := nodeutil.ReadJSON(` + n, _ := nodeutil.ReadJSON(` { "a" : [{ "id" : "1", diff --git a/node/selection_test.go b/node/selection_test.go index 5993e082..f993881d 100644 --- a/node/selection_test.go +++ b/node/selection_test.go @@ -83,9 +83,10 @@ func TestReplaceFrom(t *testing.T) { // container sel, err := root.Find("bird=robin/species") fc.RequireEqual(t, nil, err) - err = sel.ReplaceFrom(nodeutil.ReadJSON(` + n, _ := nodeutil.ReadJSON(` {"species":{"name":"dragon"}} - `)) + `) + err = sel.ReplaceFrom(n) fc.AssertEqual(t, nil, err) sel, err = root.Find("bird=robin") fc.RequireEqual(t, nil, err) @@ -96,9 +97,10 @@ func TestReplaceFrom(t *testing.T) { // list item sel, err = root.Find("bird=robin") fc.RequireEqual(t, nil, err) - sel.ReplaceFrom(nodeutil.ReadJSON(` + n, _ = nodeutil.ReadJSON(` {"bird":[{"name": "robin", "wingspan":11}]} - `)) + `) + sel.ReplaceFrom(n) fc.AssertEqual(t, nil, err) actual, err = js.JSON(root) fc.AssertEqual(t, nil, err) diff --git a/node/walk_test.go b/node/walk_test.go index 543a053d..d3034c88 100644 --- a/node/walk_test.go +++ b/node/walk_test.go @@ -23,7 +23,7 @@ func TestWalkJson(t *testing.T) { }` ypath := source.Dir("../parser/testdata") m := parser.RequireModule(ypath, "rtstone") - rdr := nodeutil.ReadJSON(config) + rdr, _ := nodeutil.ReadJSON(config) sel := node.NewBrowser(m, rdr).Root() if actual, err := nodeutil.WriteJSON(sel); err != nil { t.Error(err) diff --git a/node/xpath_test.go b/node/xpath_test.go index 1c2d6b65..2c901e80 100644 --- a/node/xpath_test.go +++ b/node/xpath_test.go @@ -12,7 +12,7 @@ import ( func TestXFind(t *testing.T) { //fc.DebugLog(true) - mstr := ` module m { namespace ""; prefix ""; revision 0; + mstr := ` module m { namespace ""; prefix ""; revision 0; container a { leaf b { type int32; @@ -27,11 +27,11 @@ func TestXFind(t *testing.T) { leaf bbb { type boolean; } - } + } list list { leaf leaf { type int32; - } + } } } ` @@ -39,12 +39,13 @@ func TestXFind(t *testing.T) { if err != nil { t.Fatal(err) } - b := node.NewBrowser(m, nodeutil.ReadJSON(`{ + n, _ := nodeutil.ReadJSON(`{ "a":{"b":10}, "aa":{"bb":"hello"}, "aaa":{"bbb":true}, "list":[{"leaf":99},{"leaf":100}] - }`)) + }`) + b := node.NewBrowser(m, n) tests := []struct { xpath string expected string diff --git a/nodeutil/config_proxy_test.go b/nodeutil/config_proxy_test.go index cb9b6ea4..14eeedc8 100644 --- a/nodeutil/config_proxy_test.go +++ b/nodeutil/config_proxy_test.go @@ -35,7 +35,7 @@ func TestConfigProxy(t *testing.T) { }) t.Run("editContainer", func(t *testing.T) { - edit := nodeutil.ReadJSON(`{"class":"thrush"}`) + edit, _ := nodeutil.ReadJSON(`{"class":"thrush"}`) sel, err := proxy.Root().Find("bird=robin/species") fc.RequireEqual(t, nil, err) fc.RequireEqual(t, nil, sel.InsertFrom(edit)) @@ -43,7 +43,7 @@ func TestConfigProxy(t *testing.T) { }) t.Run("editList", func(t *testing.T) { - edit := nodeutil.ReadJSON(`{"wingspan":10}`) + edit, _ := nodeutil.ReadJSON(`{"wingspan":10}`) sel, err := proxy.Root().Find("bird=robin") fc.RequireEqual(t, nil, err) fc.RequireEqual(t, nil, sel.UpsertFrom(edit)) @@ -51,7 +51,7 @@ func TestConfigProxy(t *testing.T) { }) t.Run("addListItem", func(t *testing.T) { - edit := nodeutil.ReadJSON(`{"bird":[{"name":"owl"}]}`) + edit, _ := nodeutil.ReadJSON(`{"bird":[{"name":"owl"}]}`) sel, err := proxy.Root().Find("bird") fc.RequireEqual(t, nil, err) fc.RequireEqual(t, nil, sel.InsertFrom(edit)) diff --git a/nodeutil/copy_on_write_test.go b/nodeutil/copy_on_write_test.go index 14fab799..f8bcdfbc 100644 --- a/nodeutil/copy_on_write_test.go +++ b/nodeutil/copy_on_write_test.go @@ -56,7 +56,8 @@ func TestCopyOnWrite(t *testing.T) { sel, err = sel.Find(test.sel) fc.RequireEqual(t, nil, err) } - fc.RequireEqual(t, nil, sel.UpsertFrom(nodeutil.ReadJSON(test.change))) + n, _ := nodeutil.ReadJSON(test.change) + fc.RequireEqual(t, nil, sel.UpsertFrom(n)) fc.AssertEqual(t, 1, len(aBirds)) actual, _ := nodeutil.WritePrettyJSON(b.Root()) fc.Gold(t, *updateFlag, []byte(actual), test.gold) diff --git a/nodeutil/diff_test.go b/nodeutil/diff_test.go index 1fdf033c..b8390236 100644 --- a/nodeutil/diff_test.go +++ b/nodeutil/diff_test.go @@ -46,7 +46,7 @@ module m { } // new - a := ReadJSON(`{ + a, _ := ReadJSON(`{ "movie" : { "mame" : "StarWars", "character" : { @@ -60,7 +60,7 @@ module m { `) // old - b := ReadJSON(`{ + b, _ := ReadJSON(`{ "movie" : { "mame" : "StarWars", "character" : { diff --git a/nodeutil/example_basic_test.go b/nodeutil/example_basic_test.go index 6ba159d5..d3a1fb80 100644 --- a/nodeutil/example_basic_test.go +++ b/nodeutil/example_basic_test.go @@ -19,8 +19,8 @@ import ( // that confirms to the model. func ExampleBasic_onField() { model := ` - leaf foo { - type string; + leaf foo { + type string; }` data := &nodeutil.Basic{ @@ -43,7 +43,8 @@ func ExampleBasic_onField() { examplePrint(sel) - sel.UpsertFrom(nodeutil.ReadJSON(`{"foo":"WRITE"}`)) + n, _ := nodeutil.ReadJSON(`{"foo":"WRITE"}`) + sel.UpsertFrom(n) // Output: // {"foo":"READ"} // WRITE @@ -58,8 +59,8 @@ type foo struct { func ExampleBasic_onChild() { model := ` container foo { - leaf bar { - type string; + leaf bar { + type string; } } ` @@ -100,7 +101,8 @@ func ExampleBasic_onChild() { examplePrint(sel) fmt.Println("Creating") - sel.InsertFrom(nodeutil.ReadJSON(`{"foo":{"bar":"y"}}`)) + n, _ := nodeutil.ReadJSON(`{"foo":{"bar":"y"}}`) + sel.InsertFrom(n) examplePrint(sel) // Output: @@ -122,7 +124,7 @@ func ExampleBasic_onNext() { model := ` list foo { key "bar"; - leaf bar { + leaf bar { type string; } }` @@ -192,7 +194,8 @@ func ExampleBasic_onNext() { examplePrint(sel) fmt.Println("Creating") - err = sel.UpsertFrom(nodeutil.ReadJSON(`{"foo":[{"bar":"b"}]}`)) + n, _ := nodeutil.ReadJSON(`{"foo":[{"bar":"b"}]}`) + err = sel.UpsertFrom(n) if err != nil { panic(err) } @@ -256,7 +259,8 @@ func ExampleBasic_onAction() { // JSON is a useful format to use as input, but this can come from any node // that would return "a" and "b" leaves. - result, err := sel.Action(nodeutil.ReadJSON(`{"a":10,"b":32}`)) + n, _ := nodeutil.ReadJSON(`{"a":10,"b":32}`) + result, err := sel.Action(n) if err != nil { panic(err) } diff --git a/nodeutil/example_json_test.go b/nodeutil/example_json_test.go index b408b42f..c1e0a276 100644 --- a/nodeutil/example_json_test.go +++ b/nodeutil/example_json_test.go @@ -38,7 +38,7 @@ func ExampleReadJSON() { myApp := make(map[string]interface{}) sel := exampleSelection(model, nodeutil.ReflectChild(myApp)) - data := `{ + n, _ := nodeutil.ReadJSON(`{ "bird" : [{ "name": "swallow", "wingSpan" : 10 @@ -48,8 +48,8 @@ func ExampleReadJSON() { "continent" : "africa" } } - ` - if err := sel.InsertFrom(nodeutil.ReadJSON(data)); err != nil { + `) + if err := sel.InsertFrom(n); err != nil { fmt.Print(err.Error()) } out, _ := nodeutil.WriteJSON(sel) diff --git a/nodeutil/json_rdr.go b/nodeutil/json_rdr.go index e06ea65f..d413f1fd 100644 --- a/nodeutil/json_rdr.go +++ b/nodeutil/json_rdr.go @@ -18,30 +18,30 @@ type JSONRdr struct { values map[string]interface{} } -func ReadJSONIO(rdr io.Reader) node.Node { +func ReadJSONIO(rdr io.Reader) (node.Node, error) { jrdr := &JSONRdr{In: rdr} return jrdr.Node() } -func ReadJSONValues(values map[string]interface{}) node.Node { +func ReadJSONValues(values map[string]interface{}) (node.Node, error) { jrdr := &JSONRdr{values: values} return jrdr.Node() } -func ReadJSON(data string) node.Node { +func ReadJSON(data string) (node.Node, error) { rdr := &JSONRdr{In: strings.NewReader(data)} return rdr.Node() } -func (self *JSONRdr) Node() node.Node { +func (self *JSONRdr) Node() (node.Node, error) { var err error if self.values == nil { self.values, err = self.decode() if err != nil { - return node.ErrorNode{Err: err} + return nil, err } } - return JsonContainerReader(self.values) + return JsonContainerReader(self.values), nil } func (self *JSONRdr) decode() (map[string]interface{}, error) { diff --git a/nodeutil/json_rdr_test.go b/nodeutil/json_rdr_test.go index 3d1def87..3bf2e62d 100644 --- a/nodeutil/json_rdr_test.go +++ b/nodeutil/json_rdr_test.go @@ -46,7 +46,9 @@ module json-test { "hobbies=birding/favorite", } for _, test := range tests { - sel := node.NewBrowser(module, ReadJSON(json)).Root() + n, err := ReadJSON(json) + fc.AssertEqual(t, nil, err) + sel := node.NewBrowser(module, n).Root() found, err := sel.Find(test) fc.RequireEqual(t, nil, err, "failed to transmit json") fc.RequireEqual(t, true, found != nil, "target not found") @@ -79,7 +81,9 @@ func TestJsonRdrUnion(t *testing.T) { } for _, json := range tests { t.Log(json.in) - actual, err := WriteJSON(node.NewBrowser(m, ReadJSON(json.in)).Root()) + n, err := ReadJSON(json.in) + fc.AssertEqual(t, nil, err) + actual, err := WriteJSON(node.NewBrowser(m, n).Root()) if err != nil { t.Error(err) } @@ -116,7 +120,9 @@ func TestJsonRdrTypedefUnionList(t *testing.T) { } for _, json := range tests { t.Log(json.in) - actual, err := WriteJSON(node.NewBrowser(m, ReadJSON(json.in)).Root()) + n, err := ReadJSON(json.in) + fc.AssertEqual(t, nil, err) + actual, err := WriteJSON(node.NewBrowser(m, n).Root()) if err != nil { t.Error(err) } @@ -156,7 +162,9 @@ func TestJsonRdrTypedefMixedUnion(t *testing.T) { } for _, json := range tests { t.Log(json.in) - actual, err := WriteJSON(node.NewBrowser(m, ReadJSON(json.in)).Root()) + n, err := ReadJSON(json.in) + fc.AssertEqual(t, nil, err) + actual, err := WriteJSON(node.NewBrowser(m, n).Root()) if err != nil { t.Error(err) } @@ -190,7 +198,7 @@ module json-test { if err != nil { t.Fatal(err) } - json := `{ "data": { + n, err := ReadJSON(`{ "data": { "id": 4, "idstr": "4", "idstrwrong": "4s", @@ -200,9 +208,10 @@ module json-test { 324545.04 ] } - }` + }`) + fc.AssertEqual(t, nil, err) - root := node.NewBrowser(module, ReadJSON(json)).Root() + root := node.NewBrowser(module, n).Root() //test get id sel, err := root.Find("data/id") @@ -248,21 +257,23 @@ module json-test { fc.AssertEqual(t, nil, err) actual := make(map[string]interface{}) b := node.NewBrowser(m, ReflectChild(actual)) - in := `{"x":{}}` - fc.AssertEqual(t, nil, b.Root().InsertFrom(ReadJSON(in))) + n, err := ReadJSON(`{"x":{}}`) + fc.AssertEqual(t, nil, err) + fc.AssertEqual(t, nil, b.Root().InsertFrom(n)) fc.AssertEqual(t, val.NotEmpty, actual["x"]) } func TestReadQualifiedJsonIdentRef(t *testing.T) { ypath := source.Dir("./testdata") m := parser.RequireModule(ypath, "module-test") - in := `{ + n, err := ReadJSON(`{ "module-test:type":"module-types:derived-type", "module-test:type2":"local-type" - }` + }`) + fc.AssertEqual(t, nil, err) actual := make(map[string]interface{}) b := node.NewBrowser(m, ReflectChild(actual)) - fc.AssertEqual(t, nil, b.Root().InsertFrom(ReadJSON(in))) + fc.AssertEqual(t, nil, b.Root().InsertFrom(n)) fc.AssertEqual(t, "derived-type", actual["type"].(val.IdentRef).Label) fc.AssertEqual(t, "local-type", actual["type2"].(val.IdentRef).Label) } diff --git a/nodeutil/node_action_test.go b/nodeutil/node_action_test.go index d4c7d811..bd14c0ce 100644 --- a/nodeutil/node_action_test.go +++ b/nodeutil/node_action_test.go @@ -11,7 +11,7 @@ import ( "github.com/freeconf/yang/parser" ) -var testActionMstr = `module x { +var testActionMstr = `module x { rpc noArgs {} rpc withArgs { @@ -102,7 +102,7 @@ func TestAction(t *testing.T) { }) t.Run("withArgs", func(t *testing.T) { - in := ReadJSON(`{"bar":"x"}`) + in, _ := ReadJSON(`{"bar":"x"}`) resp, err := sel(b.Root().Find("withArgs")).Action(in) fc.AssertEqual(t, nil, err) actual, err := WriteJSON(resp) @@ -111,7 +111,7 @@ func TestAction(t *testing.T) { }) t.Run("withArgsStruct", func(t *testing.T) { - in := ReadJSON(`{"bar":"x"}`) + in, _ := ReadJSON(`{"bar":"x"}`) resp := sel(sel(b.Root().Find("withArgsStruct")).Action(in)) actual, err := WriteJSON(resp) fc.AssertEqual(t, nil, err) @@ -119,19 +119,19 @@ func TestAction(t *testing.T) { }) t.Run("withArgsAndErr", func(t *testing.T) { - in := ReadJSON(`{"bar":"x"}`) + in, _ := ReadJSON(`{"bar":"x"}`) resp := sel(sel(b.Root().Find("withArgsAndErr")).Action(in)) actual, err := WriteJSON(resp) fc.AssertEqual(t, nil, err) fc.AssertEqual(t, `{"foo":"x"}`, actual) - in = ReadJSON(`{"bar":"bad-input"}`) + in, _ = ReadJSON(`{"bar":"bad-input"}`) _, errExpected := sel(b.Root().Find("withArgsAndErr")).Action(in) fc.AssertEqual(t, "bad-input", errExpected.Error()) }) t.Run("exploded", func(t *testing.T) { - in := ReadJSON(`{"bar":"x"}`) + in, _ := ReadJSON(`{"bar":"x"}`) resp := sel(sel(b.Root().Find("exploded")).Action(in)) actual, err := WriteJSON(resp) fc.AssertEqual(t, nil, err) @@ -139,13 +139,13 @@ func TestAction(t *testing.T) { }) t.Run("explodedWithErr", func(t *testing.T) { - in := ReadJSON(`{"bar":"x"}`) + in, _ := ReadJSON(`{"bar":"x"}`) resp := sel(sel(b.Root().Find("explodedWithErr")).Action(in)) actual, err := WriteJSON(resp) fc.AssertEqual(t, nil, err) fc.AssertEqual(t, `{"foo":"x"}`, actual) - in = ReadJSON(`{"bar":"bad-input"}`) + in, _ = ReadJSON(`{"bar":"bad-input"}`) _, errExpected := sel(b.Root().Find("explodedWithErr")).Action(in) fc.AssertEqual(t, "bad-input", errExpected.Error()) }) diff --git a/nodeutil/node_map_test.go b/nodeutil/node_map_test.go index b2cbb117..64cf990a 100644 --- a/nodeutil/node_map_test.go +++ b/nodeutil/node_map_test.go @@ -17,11 +17,11 @@ func TestMapAsContainer(t *testing.T) { }, "l": "before", } - mstr := `module x { + mstr := `module x { container c { leaf z { type string; - } + } } leaf l { type string; @@ -82,13 +82,15 @@ func TestMapAsList(t *testing.T) { fc.RequireEqual(t, nil, byKey.Delete()) fc.AssertEqual(t, 2, len(app.P)) - err = b.Root().UpsertFrom(ReadJSON(`{"p":[{"g":1000}]}`)) + n, _ := ReadJSON(`{"p":[{"g":1000}]}`) + err = b.Root().UpsertFrom(n) fc.RequireEqual(t, nil, err) fc.AssertEqual(t, 3, len(app.P)) app = mapAsListApp{} b = node.NewBrowser(m, &Node{Object: &app}) - err = b.Root().UpsertFrom(ReadJSON(`{"p":[{"g":100}]}`)) + n, _ = ReadJSON(`{"p":[{"g":100}]}`) + err = b.Root().UpsertFrom(n) fc.RequireEqual(t, nil, err) fc.AssertEqual(t, 1, len(app.P)) } diff --git a/nodeutil/node_slice_test.go b/nodeutil/node_slice_test.go index cd814e93..e7abc665 100644 --- a/nodeutil/node_slice_test.go +++ b/nodeutil/node_slice_test.go @@ -41,13 +41,15 @@ func TestSliceAsList(t *testing.T) { fc.RequireEqual(t, nil, byKey.Delete()) fc.AssertEqual(t, 2, len(app.P)) - err = b.Root().UpsertFrom(ReadJSON(`{"p":[{"g":1000}]}`)) + n, _ := ReadJSON(`{"p":[{"g":1000}]}`) + err = b.Root().UpsertFrom(n) fc.RequireEqual(t, nil, err) fc.AssertEqual(t, 3, len(app.P)) app = &sliceAsListApp{} b = node.NewBrowser(m, &Node{Object: app}) - err = b.Root().UpsertFrom(ReadJSON(`{"p":[{"g":100}]}`)) + n, _ = ReadJSON(`{"p":[{"g":100}]}`) + err = b.Root().UpsertFrom(n) fc.RequireEqual(t, nil, err) fc.AssertEqual(t, 1, len(app.P)) } diff --git a/nodeutil/node_struct_test.go b/nodeutil/node_struct_test.go index 1f2e9568..7d85a3c4 100644 --- a/nodeutil/node_struct_test.go +++ b/nodeutil/node_struct_test.go @@ -11,11 +11,11 @@ import ( "github.com/freeconf/yang/parser" ) -var testStructMstr = `module x { +var testStructMstr = `module x { container c { leaf z { type string; - } + } } leaf l { type string; @@ -98,7 +98,8 @@ func TestStructAsContainer2(t *testing.T) { b := node.NewBrowser(m, &Node{Object: app}) t.Run("replace container", func(t *testing.T) { - sel(b.Root().Find("z")).UpsertFrom(ReadJSON(`{"zz":"bye"}`)) + n, _ := ReadJSON(`{"zz":"bye"}`) + sel(b.Root().Find("z")).UpsertFrom(n) fc.AssertEqual(t, "bye", app.Z.Zz) }) diff --git a/nodeutil/node_test.go b/nodeutil/node_test.go index f96135e0..c33ff4b8 100644 --- a/nodeutil/node_test.go +++ b/nodeutil/node_test.go @@ -16,7 +16,7 @@ func TestReflectBasics(t *testing.T) { container c { leaf l { type string; - } + } } }` m, err := parser.LoadModuleFromString(nil, mstr) @@ -33,7 +33,8 @@ func TestReflectBasics(t *testing.T) { app = &reflectTestApp{} b = node.NewBrowser(m, &Node{Object: app}) - err = b.Root().UpsertFrom(ReadJSON(`{"c":{"l":"hi"}}`)) + in, _ := ReadJSON(`{"c":{"l":"hi"}}`) + err = b.Root().UpsertFrom(in) fc.RequireEqual(t, nil, err) fc.AssertEqual(t, true, app.C != nil) fc.AssertEqual(t, "hi", app.C.L) @@ -63,7 +64,8 @@ func TestReflectBasics(t *testing.T) { fc.RequireEqual(t, nil, err) fc.AssertEqual(t, `{"c":{"l":"HI"}}`, actual) - err = b.Root().UpsertFrom(ReadJSON(`{"c":{"l":"BYE"}}`)) + in, _ = ReadJSON(`{"c":{"l":"BYE"}}`) + err = b.Root().UpsertFrom(in) fc.RequireEqual(t, nil, err) fc.AssertEqual(t, true, app.C != nil) fc.AssertEqual(t, "bye", app.C.L) @@ -74,7 +76,7 @@ func TestReflect(t *testing.T) { container c { leaf l { type string; - } + } } container z { leaf l { @@ -105,7 +107,8 @@ func TestReflect(t *testing.T) { // write wtrInto := &reflectTestApp{} bwtr := node.NewBrowser(m, &Node{Object: wtrInto}) - err = bwtr.Root().UpsertFrom(ReadJSON(expected)) + n, _ := ReadJSON(expected) + err = bwtr.Root().UpsertFrom(n) fc.RequireEqual(t, nil, err) } diff --git a/nodeutil/pipe_test.go b/nodeutil/pipe_test.go index 9f636d6b..443ae300 100644 --- a/nodeutil/pipe_test.go +++ b/nodeutil/pipe_test.go @@ -109,7 +109,8 @@ func TestPipeFull(t *testing.T) { go func() { sel := node.NewBrowser(m, push).Root() - pipe.Close(sel.InsertFrom(ReadJSON(test.in))) + n, _ := ReadJSON(test.in) + pipe.Close(sel.InsertFrom(n)) }() actual, err := WriteJSON(node.NewBrowser(m, pull).Root()) if err != nil { diff --git a/nodeutil/reflect_test.go b/nodeutil/reflect_test.go index e42b4ed7..e1a2cd8b 100644 --- a/nodeutil/reflect_test.go +++ b/nodeutil/reflect_test.go @@ -114,7 +114,8 @@ func TestReflect2Write(t *testing.T) { } b = node.NewBrowser(m, n) sel := b.Root() - fc.RequireEqual(t, nil, sel.UpsertFrom(nodeutil.ReadJSON(data))) + in, _ := nodeutil.ReadJSON(data) + fc.RequireEqual(t, nil, sel.UpsertFrom(in)) } // leaflist with derived type { @@ -438,7 +439,7 @@ module m { var obj TestMessage c := nodeutil.ReflectChild(&obj) sel := node.NewBrowser(m, c).Root() - r := nodeutil.ReadJSON(`{"message":{"hello":"bob"}}`) + r, _ := nodeutil.ReadJSON(`{"message":{"hello":"bob"}}`) fc.RequireEqual(t, nil, sel.UpsertFrom(r)) if obj.Message.Hello != "bob" { t.Fatal("Not selected") @@ -502,7 +503,8 @@ func TestCollectionWrite(t *testing.T) { root := make(map[string]interface{}) bd := nodeutil.ReflectChild(root) sel := node.NewBrowser(m, bd).Root() - fc.RequireEqual(t, nil, sel.InsertFrom(nodeutil.ReadJSON(test.data))) + n, _ := nodeutil.ReadJSON(test.data) + fc.RequireEqual(t, nil, sel.InsertFrom(n)) actual := fc.MapValue(root, test.path...) if actual != "waldo" { t.Error(actual) @@ -662,7 +664,8 @@ func TestStructReplace(t *testing.T) { b := node.NewBrowser(m, n) z, err := b.Root().Find("z") fc.RequireEqual(t, nil, err) - err = z.UpdateFrom(nodeutil.ReadJSON(`{"y":"change"}`)) + in, _ := nodeutil.ReadJSON(`{"y":"change"}`) + err = z.UpdateFrom(in) fc.AssertEqual(t, nil, err) fc.AssertEqual(t, "change", app.Zee.Why) } diff --git a/testdata/bird.go b/testdata/bird.go index 536f363e..ff255953 100644 --- a/testdata/bird.go +++ b/testdata/bird.go @@ -38,7 +38,11 @@ func BirdBrowser(json string) (*node.Browser, map[string]*Bird) { data := make(map[string]*Bird) b := node.NewBrowser(BirdModule(), BirdNode(data)) if json != "" { - if err := b.Root().UpsertFrom(nodeutil.ReadJSON(json)); err != nil { + node, err := nodeutil.ReadJSON(json) + if err != nil { + panic(err) + } + if err := b.Root().UpsertFrom(node); err != nil { panic(err) } }