-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e9bb96
commit 7f1d1b8
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |