@@ -2,16 +2,17 @@ package service
2
2
3
3
import (
4
4
"fmt"
5
- "reflect"
6
5
"testing"
7
6
7
+ "github.com/stretchr/testify/assert"
8
+
8
9
"github.com/Southclaws/wadsworth/service/task"
9
10
)
10
11
11
12
func Test_diffTargets (t * testing.T ) {
12
13
type args struct {
13
- newTargets []task.Target
14
14
oldTargets []task.Target
15
+ newTargets []task.Target
15
16
}
16
17
tests := []struct {
17
18
args args
@@ -34,6 +35,38 @@ func Test_diffTargets(t *testing.T) {
34
35
nil ,
35
36
nil ,
36
37
},
38
+ {
39
+ args {
40
+ oldTargets : []task.Target {},
41
+ newTargets : []task.Target {
42
+ {Name : "one" },
43
+ {Name : "two" },
44
+ {Name : "three" },
45
+ },
46
+ },
47
+ []task.Target {
48
+ {Name : "one" },
49
+ {Name : "two" },
50
+ {Name : "three" },
51
+ },
52
+ nil ,
53
+ },
54
+ {
55
+ args {
56
+ oldTargets : []task.Target {
57
+ {Name : "one" },
58
+ {Name : "two" },
59
+ {Name : "three" },
60
+ },
61
+ newTargets : []task.Target {},
62
+ },
63
+ nil ,
64
+ []task.Target {
65
+ {Name : "one" },
66
+ {Name : "two" },
67
+ {Name : "three" },
68
+ },
69
+ },
37
70
{
38
71
args {
39
72
oldTargets : []task.Target {
@@ -89,13 +122,9 @@ func Test_diffTargets(t *testing.T) {
89
122
}
90
123
for ii , tt := range tests {
91
124
t .Run (fmt .Sprint (ii ), func (t * testing.T ) {
92
- gotAdditions , gotRemovals := diffTargets (tt .args .newTargets , tt .args .oldTargets )
93
- if ! reflect .DeepEqual (gotAdditions , tt .wantAdditions ) {
94
- t .Errorf ("diffTargets() gotAdditions = %v, want %v" , gotAdditions , tt .wantAdditions )
95
- }
96
- if ! reflect .DeepEqual (gotRemovals , tt .wantRemovals ) {
97
- t .Errorf ("diffTargets() gotRemovals = %v, want %v" , gotRemovals , tt .wantRemovals )
98
- }
125
+ gotAdditions , gotRemovals := diffTargets (tt .args .oldTargets , tt .args .newTargets )
126
+ assert .Equal (t , tt .wantAdditions , gotAdditions , "additions mismatch" )
127
+ assert .Equal (t , tt .wantRemovals , gotRemovals , "removals mismatch" )
99
128
})
100
129
}
101
130
}
0 commit comments