Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncompressed ordered map tests in mostly ygot package. #872

Merged
merged 40 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c79e185
Add support for ending iteration of subtrees in `ForEachDataField`
wenovus Jun 7, 2023
2fad304
Try adding stringer
wenovus Jun 7, 2023
6765293
install stringer
wenovus Jun 7, 2023
744010e
fix comment
wenovus Jun 7, 2023
b35c210
fix enum name
wenovus Jun 7, 2023
f967992
Add `DiffWithAtomic` to support creating Atomic Notifications.
wenovus Jun 7, 2023
4a399ac
Fix bug when IgnoreAdditions option is turned on
wenovus Jun 7, 2023
ccb9b0d
Add tests for PopulateDefaults for ordered maps
wenovus Jun 8, 2023
e735629
Move TestTogNMINotifications's ordered map tests to exported tests
wenovus Jun 8, 2023
1e61de2
Export ConstructJSON ordered map test
wenovus Jun 9, 2023
2c9655f
Export remaining ordered map tests
wenovus Jun 9, 2023
d7f175c
lint
wenovus Jun 9, 2023
99c53e0
Merge branch 'export-tognmi-tests' into export-constructjson
wenovus Jun 9, 2023
62b74df
Merge branch 'export-constructjson' into export-others-orderedmap
wenovus Jun 9, 2023
1257144
Initial tests for uncompressed structs with ordered maps.
wenovus Jun 9, 2023
233a927
Remove more dead test code
wenovus Jun 9, 2023
7901a8d
Merge branch 'export-others-orderedmap' into uncompressed-orderedmap
wenovus Jun 9, 2023
bdb4312
Uncompressed ordered map test on PopulateDefaults
wenovus Jun 9, 2023
1230b4c
Uncompressed GoStruct tests in mostly `ygot` package.
wenovus Jun 9, 2023
de819a1
Move TestTogNMINotifications's ordered map tests to exported tests (#…
wenovus Jun 12, 2023
35f4c47
Merge branch 'master' into populatedef-om
wenovus Jun 12, 2023
18c8cef
Merge branch 'populatedef-om' into export-constructjson
wenovus Jun 12, 2023
0572c34
Merge branch 'export-constructjson' into export-others-orderedmap
wenovus Jun 12, 2023
3b97314
Merge branch 'export-others-orderedmap' into uncompressed-orderedmap
wenovus Jun 12, 2023
55368df
Add doc comments for test helpers.
wenovus Jun 12, 2023
9c8131e
Merge branch 'uncompressed-orderedmap' into uom-1
wenovus Jun 12, 2023
9f983dd
Merge branch 'uom-1' into uom-2
wenovus Jun 12, 2023
9186a5e
Merge branch 'master' into export-constructjson
wenovus Jun 12, 2023
7cae251
Merge branch 'export-constructjson' into export-others-orderedmap
wenovus Jun 12, 2023
feae932
Merge branch 'export-others-orderedmap' into uncompressed-orderedmap
wenovus Jun 12, 2023
eb9c41c
Merge branch 'uncompressed-orderedmap' into uom-1
wenovus Jun 12, 2023
31ea0c8
Merge branch 'uom-1' into uom-2
wenovus Jun 12, 2023
cfe027b
Merge branch 'master' into export-others-orderedmap
wenovus Jun 12, 2023
4692f74
Merge branch 'export-others-orderedmap' into uncompressed-orderedmap
wenovus Jun 12, 2023
5e337a7
Merge branch 'uncompressed-orderedmap' into uom-1
wenovus Jun 12, 2023
1e5fc20
Merge branch 'uom-1' into uom-2
wenovus Jun 12, 2023
8b5fef7
Merge branch 'master' into uom-1
wenovus Jun 12, 2023
6338570
Merge branch 'uom-1' into uom-2
wenovus Jun 12, 2023
b095e91
add doc comments for ordered map test helpers
wenovus Jun 13, 2023
1073e6f
Merge branch 'master' into uom-2
wenovus Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions integration_tests/schemaops/ctestschema/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (*MapStructTestOneChild) ΛValidate(...ygot.ValidationOption) error {
func (*MapStructTestOneChild) ΛEnumTypeMap() map[string][]reflect.Type { return nil }
func (*MapStructTestOneChild) ΛBelongingModule() string { return "test-one" }

// GetOrderedMap returns a populated ordered map with dummy values.
//
// - foo: foo-val
// - bar: bar-val
func GetOrderedMap(t *testing.T) *OrderedList_OrderedMap {
orderedMap := &OrderedList_OrderedMap{}
v, err := orderedMap.AppendNew("foo")
Expand All @@ -73,6 +77,11 @@ func GetOrderedMap(t *testing.T) *OrderedList_OrderedMap {
return orderedMap
}

// GetOrderedMapLonger returns a populated ordered map with more dummy values.
//
// - foo: foo-val
// - bar: bar-val
// - baz: baz-val
func GetOrderedMapLonger(t *testing.T) *OrderedList_OrderedMap {
orderedMap := &OrderedList_OrderedMap{}
v, err := orderedMap.AppendNew("foo")
Expand All @@ -93,6 +102,10 @@ func GetOrderedMapLonger(t *testing.T) *OrderedList_OrderedMap {
return orderedMap
}

// GetOrderedMap2 returns a populated ordered map with different dummy values.
//
// - wee: wee-val
// - woo: woo-val
func GetOrderedMap2(t *testing.T) *OrderedList_OrderedMap {
orderedMap := &OrderedList_OrderedMap{}
v, err := orderedMap.AppendNew("wee")
Expand All @@ -108,6 +121,12 @@ func GetOrderedMap2(t *testing.T) *OrderedList_OrderedMap {
return orderedMap
}

// GetNestedOrderedMap returns a populated nested ordered map with dummy
// values.
//
// - foo: foo-val
// - foo: foo-val
// - bar: bar-val
func GetNestedOrderedMap(t *testing.T) *OrderedList_OrderedMap {
om := GetOrderedMap(t)

Expand All @@ -127,6 +146,12 @@ func GetNestedOrderedMap(t *testing.T) *OrderedList_OrderedMap {
return om
}

// GetOrderedMapMultikeyed returns a populated multi-keyed ordered map with
// dummy values.
//
// - foo, 42: foo-val
// - bar, 42: bar-val
// - baz, 84: baz-val
func GetOrderedMapMultikeyed(t *testing.T) *OrderedMultikeyedList_OrderedMap {
orderedMap := &OrderedMultikeyedList_OrderedMap{}
v, err := orderedMap.AppendNew("foo", 42)
Expand Down
61 changes: 61 additions & 0 deletions integration_tests/schemaops/utestschema/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,64 @@ func GetDeviceWithOrderedMap(t *testing.T) *Device {
},
}
}

// GetOrderedMap2 returns a populated ordered map with different dummy values.
//
// - wee: wee-val
// - woo: woo-val
func GetOrderedMap2(t *testing.T) *Ctestschema_OrderedLists_OrderedList_OrderedMap {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godoc
nit: i don't like "2" suffix, it's unclear what makes this func different from other func without looking at the code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I've added a godoc. I think in this case it's ok to leave it like this rather than GetOrderedMapWeeWoo as the readers are mostly ygot maintainers and the code is fairly easy to understand. The "2" as a indicator for a different ordered map I think is sufficient. Let me know if you have other thoughts on this.

orderedMap := &Ctestschema_OrderedLists_OrderedList_OrderedMap{}
v, err := orderedMap.AppendNew("wee")
if err != nil {
t.Error(err)
}
// Config value
v.GetOrCreateConfig().Value = ygot.String("wee-val")
v, err = orderedMap.AppendNew("woo")
if err != nil {
t.Error(err)
}
// State value
v.GetOrCreateState().Value = ygot.String("woo-val")
return orderedMap
}

// GetDeviceWithOrderedMap returns a Device object with a ordered map
// field populated with different values.
func GetDeviceWithOrderedMap2(t *testing.T) *Device {
return &Device{
OrderedLists: &Ctestschema_OrderedLists{
OrderedList: GetOrderedMap2(t),
},
}
}

// GetOrderedMultikeyedMap returns a populated multi-keyed ordered map with
// dummy values.
//
// - foo, 42: foo-val
// - bar, 42: bar-val
// - baz, 84: baz-val
func GetOrderedMultikeyedMap(t *testing.T) *CtestschemaRootmod_OrderedMultikeyedLists_OrderedMultikeyedList_OrderedMap {
orderedMap := &CtestschemaRootmod_OrderedMultikeyedLists_OrderedMultikeyedList_OrderedMap{}
v, err := orderedMap.AppendNew("foo", 42)
if err != nil {
t.Error(err)
}
// Config value
v.GetOrCreateConfig().Value = ygot.String("foo-val")
v, err = orderedMap.AppendNew("bar", 42)
if err != nil {
t.Error(err)
}
// State value
v.GetOrCreateState().Value = ygot.String("bar-val")
v, err = orderedMap.AppendNew("baz", 84)
if err != nil {
t.Error(err)
}
// Config & State value
v.GetOrCreateConfig().Value = ygot.String("baz-val")
v.GetOrCreateState().Value = ygot.String("baz-val")
return orderedMap
}
77 changes: 73 additions & 4 deletions ygot/diff_exported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/openconfig/gnmi/errdiff"
"github.com/openconfig/ygot/integration_tests/schemaops/ctestschema"
"github.com/openconfig/ygot/integration_tests/schemaops/utestschema"
"github.com/openconfig/ygot/internal/ytestutil"
"github.com/openconfig/ygot/testutil"
"github.com/openconfig/ygot/ygot"
Expand All @@ -44,7 +45,7 @@ func TestDiffOrderedMap(t *testing.T) {
// TODO: Test for uncompressed structs.
tests := []struct {
name string
inOrig, inMod *ctestschema.Device
inOrig, inMod ygot.GoStruct
inOpts []ygot.DiffOpt
// skipTestUnmarshal determines whether the unmarshal test is skipped.
skipTestUnmarshal bool
Expand Down Expand Up @@ -287,6 +288,65 @@ func TestDiffOrderedMap(t *testing.T) {
mustPath(`/ordered-lists`),
},
},
}, {
name: "empty-modified-uncompressed",
inOrig: utestschema.GetDeviceWithOrderedMap(t),
inMod: &utestschema.Device{},
want: &gnmipb.Notification{
Delete: []*gnmipb.Path{
mustPath(`/ordered-lists/ordered-list[key=foo]/key`),
mustPath(`/ordered-lists/ordered-list[key=foo]/config/value`),
mustPath(`/ordered-lists/ordered-list[key=bar]/key`),
mustPath(`/ordered-lists/ordered-list[key=bar]/state/value`),
},
},
wantNonAtomic: &gnmipb.Notification{
Delete: []*gnmipb.Path{
mustPath(`/ordered-lists`),
},
},
}, {
name: "empty-disjoint-uncompressed",
inOrig: utestschema.GetDeviceWithOrderedMap2(t),
inMod: utestschema.GetDeviceWithOrderedMap(t),
want: &gnmipb.Notification{
Update: []*gnmipb.Update{{
Path: mustPath(`/ordered-lists/ordered-list[key=foo]/key`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "foo"}},
}, {
Path: mustPath(`/ordered-lists/ordered-list[key=foo]/config/value`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "foo-val"}},
}, {
Path: mustPath(`/ordered-lists/ordered-list[key=bar]/key`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "bar"}},
}, {
Path: mustPath(`/ordered-lists/ordered-list[key=bar]/state/value`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "bar-val"}},
}},
Delete: []*gnmipb.Path{
mustPath(`/ordered-lists/ordered-list[key=wee]/key`),
mustPath(`/ordered-lists/ordered-list[key=wee]/config/value`),
mustPath(`/ordered-lists/ordered-list[key=woo]/key`),
mustPath(`/ordered-lists/ordered-list[key=woo]/state/value`),
},
},
wantAtomic: []*gnmipb.Notification{{
Prefix: mustPath(`ordered-lists`),
Atomic: true,
Update: []*gnmipb.Update{{
Path: mustPath(`ordered-list[key=foo]/config/value`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "foo-val"}},
}, {
Path: mustPath(`ordered-list[key=foo]/key`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "foo"}},
}, {
Path: mustPath(`ordered-list[key=bar]/key`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "bar"}},
}, {
Path: mustPath(`ordered-list[key=bar]/state/value`),
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_StringVal{StringVal: "bar-val"}},
}},
}},
}, {
name: "empty-modified-with-other-data-in-orig",
inOrig: &ctestschema.Device{
Expand Down Expand Up @@ -642,9 +702,18 @@ func TestDiffOrderedMap(t *testing.T) {
return
}
// Test that unmarshalling into original gets back to modified.
schema, err := ctestschema.Schema()
if err != nil {
t.Fatal(err)
var schema *ytypes.Schema
switch tt.inOrig.(type) {
case *ctestschema.Device:
if schema, err = ctestschema.Schema(); err != nil {
t.Fatal(err)
}
case *utestschema.Device:
if schema, err = utestschema.Schema(); err != nil {
t.Fatal(err)
}
default:
t.Fatalf("Unexpected type: %T", tt.inOrig)
}
schema.Root = tt.inOrig
if err := ytypes.UnmarshalNotifications(schema, got); err != nil {
Expand Down
29 changes: 29 additions & 0 deletions ygot/gostruct_exported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/integration_tests/schemaops/ctestschema"
"github.com/openconfig/ygot/integration_tests/schemaops/utestschema"
"github.com/openconfig/ygot/internal/ytestutil"
"github.com/openconfig/ygot/ygot"
)
Expand Down Expand Up @@ -55,6 +56,34 @@ func TestPruneConfigFalseOrderedMap(t *testing.T) {
return om
}(),
},
}, {
desc: "prune through ordered map uncompressed",
inSchema: utestschema.SchemaTree["Device"],
inStruct: &utestschema.Device{
OrderedLists: &utestschema.Ctestschema_OrderedLists{
OrderedList: func() *utestschema.Ctestschema_OrderedLists_OrderedList_OrderedMap {
om := &utestschema.Ctestschema_OrderedLists_OrderedList_OrderedMap{}
ome, err := om.AppendNew("foo")
if err != nil {
t.Fatal(err)
}
ome.GetOrCreateState().RoValue = ygot.String("ro-value")
return om
}(),
},
},
want: &utestschema.Device{
OrderedLists: &utestschema.Ctestschema_OrderedLists{
OrderedList: func() *utestschema.Ctestschema_OrderedLists_OrderedList_OrderedMap {
om := &utestschema.Ctestschema_OrderedLists_OrderedList_OrderedMap{}
_, err := om.AppendNew("foo")
if err != nil {
t.Fatal(err)
}
return om
}(),
},
},
}}

for _, tt := range tests {
Expand Down
Loading