77
88 "github.com/beevik/etree"
99 "github.com/iptecharch/data-server/mocks/mockschema"
10+ "github.com/iptecharch/data-server/pkg/utils"
1011 sdcpb "github.com/iptecharch/sdc-protos/sdcpb"
1112 "go.uber.org/mock/gomock"
1213 "google.golang.org/grpc"
@@ -41,7 +42,7 @@ func TestXML2sdcpbConfigAdapter_Transform(t *testing.T) {
4142 }
4243 tests := []struct {
4344 name string
44- getXML2sdcpbConfigAdapter func (ctrl * gomock.Controller ) * XML2sdcpbConfigAdapter
45+ getXML2sdcpbConfigAdapter func (ctrl * gomock.Controller , t * testing. T ) * XML2sdcpbConfigAdapter
4546 args args
4647 want * sdcpb.Notification
4748 wantErr bool
@@ -52,20 +53,28 @@ func TestXML2sdcpbConfigAdapter_Transform(t *testing.T) {
5253 ctx : TestCtx ,
5354 doc : GetNewDoc (),
5455 },
55- getXML2sdcpbConfigAdapter : func (ctrl * gomock.Controller ) * XML2sdcpbConfigAdapter {
56+ getXML2sdcpbConfigAdapter : func (ctrl * gomock.Controller , t * testing.T ) * XML2sdcpbConfigAdapter {
57+
58+ var expectedPath []* sdcpb.PathElem
5659
5760 schemaClientMock := mockschema .NewMockClient (ctrl )
5861 counter := 0
5962 schemaClientMock .EXPECT ().GetSchema (TestCtx , gomock .Any (), gomock .Any ()).AnyTimes ().DoAndReturn (
6063 func (ctx context.Context , in * sdcpb.GetSchemaRequest , opts ... grpc.CallOption ) (* sdcpb.GetSchemaResponse , error ) {
6164 selem := & sdcpb.SchemaElem {}
65+ // Test that the provided schema equals the expected Schema
66+ if in .Schema != TestSchema {
67+ t .Errorf ("Schema provide to GetSchema is wrong %s vs. %s" , in .Schema .String (), TestSchema .String ())
68+ }
69+
6270 switch counter {
6371 case 0 :
6472 selem .Schema = & sdcpb.SchemaElem_Container {
6573 Container : & sdcpb.ContainerSchema {
6674 Name : "interfaces" ,
6775 },
6876 }
77+ expectedPath = []* sdcpb.PathElem {{Name : "interfaces" }}
6978 case 1 :
7079 selem .Schema = & sdcpb.SchemaElem_Container {
7180 Container : & sdcpb.ContainerSchema {
@@ -77,6 +86,7 @@ func TestXML2sdcpbConfigAdapter_Transform(t *testing.T) {
7786 },
7887 },
7988 }
89+ expectedPath = []* sdcpb.PathElem {{Name : "interfaces" }, {Name : "interface" }}
8090 case 2 :
8191 selem .Schema = & sdcpb.SchemaElem_Field {
8292 Field : & sdcpb.LeafSchema {
@@ -86,9 +96,15 @@ func TestXML2sdcpbConfigAdapter_Transform(t *testing.T) {
8696 },
8797 },
8898 }
99+ expectedPath = []* sdcpb.PathElem {{Name : "interfaces" }, {Name : "interface" , Key : map [string ]string {"name" : "eth0" }}, {Name : "name" }}
89100 }
90- counter ++
91101
102+ // check for the right input
103+ if ! reflect .DeepEqual (in .GetPath ().Elem , expectedPath ) {
104+ t .Errorf ("getSchema expected path %s but got %s" , utils .ToStrings (& sdcpb.Path {Elem : expectedPath }, false , false ), utils .ToStrings (in .GetPath (), false , false ))
105+ }
106+
107+ counter ++
92108 return & sdcpb.GetSchemaResponse {
93109 Schema : selem ,
94110 }, nil
@@ -130,7 +146,7 @@ func TestXML2sdcpbConfigAdapter_Transform(t *testing.T) {
130146 t .Run (tt .name , func (t * testing.T ) {
131147 mockCtrl := gomock .NewController (t )
132148
133- x := tt .getXML2sdcpbConfigAdapter (mockCtrl )
149+ x := tt .getXML2sdcpbConfigAdapter (mockCtrl , t )
134150 // tt.args.doc.Indent(2)
135151 // s, _ := tt.args.doc.WriteToString()
136152 // fmt.Println(s)
0 commit comments