Skip to content

Commit fbc4a76

Browse files
authored
Add unit test for resolveConflicts function (#5233)
* Add unit test for resolveConflicts function Signed-off-by: Doğukan Teber <[email protected]> * Clean up the test logic Signed-off-by: Doğukan Teber <[email protected]> --------- Signed-off-by: Doğukan Teber <[email protected]>
1 parent 3b84671 commit fbc4a76

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

pkg/ring/model_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,81 @@ func TestDesc_FindDifference(t *testing.T) {
600600
})
601601
}
602602
}
603+
604+
func Test_resolveConflicts(t *testing.T) {
605+
tests := []struct {
606+
name string
607+
args map[string]InstanceDesc
608+
want map[string]InstanceDesc
609+
}{
610+
{
611+
name: "Empty input",
612+
args: map[string]InstanceDesc{},
613+
want: map[string]InstanceDesc{},
614+
},
615+
{
616+
name: "No conflicts",
617+
args: map[string]InstanceDesc{
618+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
619+
"ing2": {State: ACTIVE, Tokens: []uint32{4, 5, 6}},
620+
},
621+
want: map[string]InstanceDesc{
622+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
623+
"ing2": {State: ACTIVE, Tokens: []uint32{4, 5, 6}},
624+
},
625+
},
626+
{
627+
name: "Conflict resolution with LEFT state",
628+
args: map[string]InstanceDesc{
629+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
630+
"ing2": {State: LEFT, Tokens: []uint32{1, 2, 3, 4}},
631+
},
632+
want: map[string]InstanceDesc{
633+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
634+
"ing2": {State: LEFT, Tokens: nil},
635+
},
636+
},
637+
{
638+
name: "Conflict resolution with LEAVING state",
639+
args: map[string]InstanceDesc{
640+
"ing1": {State: LEAVING, Tokens: []uint32{1, 2, 3}},
641+
"ing2": {State: PENDING, Tokens: []uint32{1, 2, 3, 4}},
642+
},
643+
want: map[string]InstanceDesc{
644+
"ing1": {State: LEAVING, Tokens: nil},
645+
"ing2": {State: PENDING, Tokens: []uint32{1, 2, 3, 4}},
646+
},
647+
},
648+
{
649+
name: "Conflict resolution with JOINING state",
650+
args: map[string]InstanceDesc{
651+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
652+
"ing2": {State: JOINING, Tokens: []uint32{1, 2, 3, 4}},
653+
},
654+
want: map[string]InstanceDesc{
655+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
656+
"ing2": {State: JOINING, Tokens: []uint32{4}},
657+
},
658+
},
659+
{
660+
name: "Conflict resolution with same state",
661+
args: map[string]InstanceDesc{
662+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
663+
"ing2": {State: ACTIVE, Tokens: []uint32{1, 2, 3, 4}},
664+
},
665+
want: map[string]InstanceDesc{
666+
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
667+
"ing2": {State: ACTIVE, Tokens: []uint32{4}},
668+
},
669+
},
670+
}
671+
672+
for _, tt := range tests {
673+
t.Run(tt.name, func(t *testing.T) {
674+
resolveConflicts(tt.args)
675+
for key, actualInstance := range tt.args {
676+
assert.Equal(t, actualInstance, tt.want[key])
677+
}
678+
})
679+
}
680+
}

0 commit comments

Comments
 (0)