Skip to content

Commit 79c9108

Browse files
committed
fix unittests
1 parent b56d9c3 commit 79c9108

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

pkg/datastore/tree_operation_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ func TestDatastore_populateTree(t *testing.T) {
390390
types.NewUpdate([]string{"interface", "ethernet-1/1", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), prio10, owner2, 0),
391391
types.NewUpdate([]string{"interface", "ethernet-1/1", "admin-state"}, testhelper.GetStringTvProto("enable"), prio10, owner2, 0),
392392
},
393+
runningStoreUpdates: []*types.Update{
394+
types.NewUpdate([]string{"interface", "ethernet-1/1", "name"}, testhelper.GetStringTvProto("ethernet-1/1"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
395+
types.NewUpdate([]string{"interface", "ethernet-1/1", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
396+
types.NewUpdate([]string{"interface", "ethernet-1/1", "admin-state"}, testhelper.GetStringTvProto("enable"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
397+
},
393398
},
394399
{
395400
name: "Delete - aggregate branch via keys, multiple entries (different keys)",
@@ -410,17 +415,17 @@ func TestDatastore_populateTree(t *testing.T) {
410415
SkipValidation: false,
411416
})
412417
},
413-
intentDelete: true,
418+
intentDelete: true,
414419
runningStoreUpdates: []*types.Update{
415-
// cache.NewUpdate([]string{"interface", "ethernet-1/1", "name"}, testhelper.GetStringTvProto("ethernet-1/1"), prio10, owner2, 0),
416-
// cache.NewUpdate([]string{"interface", "ethernet-1/1", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), prio10, owner2, 0),
417-
// cache.NewUpdate([]string{"interface", "ethernet-1/1", "admin-state"}, testhelper.GetStringTvProto("enable"), prio10, owner2, 0),
418-
// cache.NewUpdate([]string{"interface", "ethernet-1/2", "name"}, testhelper.GetStringTvProto("ethernet-1/2"), prio10, owner2, 0),
419-
// cache.NewUpdate([]string{"interface", "ethernet-1/2", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), prio10, owner2, 0),
420-
// cache.NewUpdate([]string{"interface", "ethernet-1/2", "admin-state"}, testhelper.GetStringTvProto("enable"), prio10, owner2, 0),
421-
// cache.NewUpdate([]string{"interface", "ethernet-1/3", "name"}, testhelper.GetStringTvProto("ethernet-1/3"), prio10, owner2, 0),
422-
// cache.NewUpdate([]string{"interface", "ethernet-1/3", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), prio10, owner2, 0),
423-
// cache.NewUpdate([]string{"interface", "ethernet-1/3", "admin-state"}, testhelper.GetStringTvProto("enable"), prio10, owner2, 0),
420+
types.NewUpdate([]string{"interface", "ethernet-1/1", "name"}, testhelper.GetStringTvProto("ethernet-1/1"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
421+
types.NewUpdate([]string{"interface", "ethernet-1/1", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
422+
types.NewUpdate([]string{"interface", "ethernet-1/1", "admin-state"}, testhelper.GetStringTvProto("enable"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
423+
types.NewUpdate([]string{"interface", "ethernet-1/2", "name"}, testhelper.GetStringTvProto("ethernet-1/2"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
424+
types.NewUpdate([]string{"interface", "ethernet-1/2", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
425+
types.NewUpdate([]string{"interface", "ethernet-1/2", "admin-state"}, testhelper.GetStringTvProto("enable"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
426+
types.NewUpdate([]string{"interface", "ethernet-1/3", "name"}, testhelper.GetStringTvProto("ethernet-1/3"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
427+
types.NewUpdate([]string{"interface", "ethernet-1/3", "description"}, testhelper.GetStringTvProto("MyDescriptionOwner2"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
428+
types.NewUpdate([]string{"interface", "ethernet-1/3", "admin-state"}, testhelper.GetStringTvProto("enable"), tree.RunningValuesPrio, tree.RunningIntentName, 0),
424429
},
425430
expectedDeletes: [][]string{
426431
{"interface", "ethernet-1/1", "admin-state"},
@@ -441,7 +446,7 @@ func TestDatastore_populateTree(t *testing.T) {
441446
},
442447
expectedModify: []*types.Update{
443448
types.NewUpdate([]string{"interface", "ethernet-1/1", "description"}, testhelper.GetStringTvProto("MyNonappliedDescription"), prio10, owner2, 0),
444-
types.NewUpdate([]string{"interface", "ethernet-1/1", "name"}, testhelper.GetStringTvProto("ethernet-1/1"), prio10, owner2, 0),
449+
// types.NewUpdate([]string{"interface", "ethernet-1/1", "name"}, testhelper.GetStringTvProto("ethernet-1/1"), prio10, owner2, 0),
445450
},
446451
intendedStoreUpdates: []*types.Update{
447452
types.NewUpdate([]string{"interface", "ethernet-1/1", "name"}, testhelper.GetStringTvProto("ethernet-1/1"), prio10, owner2, 0),

pkg/tree/entry_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,17 @@ func Test_Entry_Delete_Aggregation(t *testing.T) {
668668

669669
// start test add "existing" data
670670
for _, u := range []*types.Update{u1, u2, u3, u4, u5, u6} {
671+
671672
_, err := root.AddUpdateRecursive(ctx, u, flagsExisting)
672673
if err != nil {
673674
t.Fatal(err)
674675
}
676+
// add also as running
677+
runUpd := u.DeepCopy().SetOwner(RunningIntentName).SetPriority(RunningValuesPrio)
678+
_, err = root.AddUpdateRecursive(ctx, runUpd, flagsExisting)
679+
if err != nil {
680+
t.Fatal(err)
681+
}
675682
}
676683

677684
// get ready to add the new intent data

pkg/tree/leaf_variants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (lv *LeafVariants) GetHighestPrecedence(onlyNewOrUpdated bool, includeDefau
258258
if len(lv.les) == 0 {
259259
return nil
260260
}
261-
if onlyNewOrUpdated && lv.canDeleteBranch(false) {
261+
if onlyNewOrUpdated && lv.canDelete() {
262262
return nil
263263
}
264264

pkg/tree/types/update.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ func (u *Update) Owner() string {
4949
return u.intentName
5050
}
5151

52-
func (u *Update) SetOwner(owner string) {
52+
func (u *Update) SetOwner(owner string) *Update {
5353
u.intentName = owner
54+
return u
5455
}
5556

5657
func (u *Update) Priority() int32 {
5758
return u.priority
5859
}
5960

60-
func (u *Update) SetPriority(prio int32) {
61+
func (u *Update) SetPriority(prio int32) *Update {
6162
u.priority = prio
63+
return u
6264
}
6365

6466
func (u *Update) Timestamp() int64 {

pkg/tree/xml_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func TestToXMLTable(t *testing.T) {
8686
c := config1()
8787
return expandUpdateFromConfig(ctx, c, converter)
8888
},
89+
runningConfig: func(ctx context.Context, converter *utils.Converter) ([]*sdcpb.Update, error) {
90+
c := config1()
91+
return expandUpdateFromConfig(ctx, c, converter)
92+
},
8993
newConfig: func(ctx context.Context, converter *utils.Converter) ([]*sdcpb.Update, error) {
9094
c := config2()
9195
return expandUpdateFromConfig(ctx, c, converter)

0 commit comments

Comments
 (0)