Skip to content

Commit

Permalink
tests: TestFindSetLeaves updated with presence container tests
Browse files Browse the repository at this point in the history
Co-authored-by: Terje Lafton <terje@lafton.io>
  • Loading branch information
JonasKs and TerjeLafton committed Oct 2, 2024
1 parent 8c252eb commit 688c727
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion ygot/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ type basicStructThree struct {
StringValue *string `path:"third-string-value|config/third-string-value"`
}

type basicStructPresence struct {
StringValue *string `path:"string-value" yangPresence:"true"`
}

func (*basicStructPresence) IsYANGGoStruct() {}

type basicStructPresenceWithStruct struct {
StructField *basicStructThree `path:"struct-value" yangPresence:"true"`
}

func (*basicStructPresenceWithStruct) IsYANGGoStruct() {}

func TestNodeValuePath(t *testing.T) {
cmplx := complex(float64(1), float64(2))
tests := []struct {
Expand Down Expand Up @@ -624,7 +636,44 @@ func TestFindSetLeaves(t *testing.T) {
}},
}: String("baz"),
},
}}
}, {
desc: "struct with presence container",
inStruct: &basicStructPresence{StringValue: String("foo")},
inOpts: []DiffOpt{&WithRespectPresenceContainers{}},
want: map[*pathSpec]interface{}{
{
gNMIPaths: []*gnmipb.Path{{
Elem: []*gnmipb.PathElem{{Name: "string-value"}},
}},
}: nil,
},
}, {
desc: "struct with presence container but no diff opt",
inStruct: &basicStructPresence{StringValue: String("foo")},
want: map[*pathSpec]interface{}{
{
gNMIPaths: []*gnmipb.Path{{
Elem: []*gnmipb.PathElem{{Name: "string-value"}},
}},
}: String("foo"),
},
}, {
desc: "struct with presence container, empty struct as value",
inStruct: &basicStructPresenceWithStruct{StructField: &basicStructThree{}},
inOpts: []DiffOpt{&WithRespectPresenceContainers{}},
want: map[*pathSpec]interface{}{
{
gNMIPaths: []*gnmipb.Path{{
Elem: []*gnmipb.PathElem{{Name: "struct-value"}},
}},
}: nil,
},
}, {
desc: "struct with presence container, empty struct as a value and no diff opt should be ignored",
inStruct: &basicStructPresenceWithStruct{StructField: &basicStructThree{}},
want: map[*pathSpec]interface{}{},
},
}

for _, tt := range tests {
got, err := findSetLeaves(tt.inStruct, false, tt.inOpts...)
Expand Down

0 comments on commit 688c727

Please sign in to comment.