Skip to content

Commit

Permalink
Add test for getMinTargets()
Browse files Browse the repository at this point in the history
  • Loading branch information
chez-shanpu committed Apr 4, 2023
1 parent 2e9bb96 commit 7f1d1b8
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions server/pkg/api/server_add_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package api

import (
"reflect"
"testing"
)

func Test_getMinTargets(t *testing.T) {
var (
hostA = targetHost{percentOverCommit: 1}
hostA2 = targetHost{percentOverCommit: 1}
hostB = targetHost{percentOverCommit: 2}
hostC = targetHost{percentOverCommit: 3}
)

type args struct {
hosts []targetHost
}
tests := []struct {
name string
args args
want []targetHost
}{
{
name: "Single host",
args: args{
hosts: []targetHost{hostA},
},
want: []targetHost{hostA},
},
{
name: "Multiple host",
args: args{
hosts: []targetHost{hostA, hostB, hostC},
},
want: []targetHost{hostA},
},
{
name: "Multiple host (random order)",
args: args{
hosts: []targetHost{hostC, hostA, hostB},
},
want: []targetHost{hostA},
},
{
name: "Multiple host result",
args: args{
hosts: []targetHost{hostA, hostA2, hostB, hostC},
},
want: []targetHost{hostA, hostA2},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getMinTargets(tt.args.hosts); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getMinTargets() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 7f1d1b8

Please sign in to comment.