forked from realvnc-labs/tacoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_test.go
More file actions
135 lines (128 loc) · 2.51 KB
/
diff_test.go
File metadata and controls
135 lines (128 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package pkg
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCalcDiff(t *testing.T) {
testCases := []struct {
name string
linesBefore string
linesAfter string
expectedDiff *Diff
}{
{
name: "no diff, single line",
linesBefore: "readline-common 7.0-3",
linesAfter: "readline-common 7.0-3",
expectedDiff: nil,
},
{
name: "no diff, multi line",
linesBefore: `readline-common 7.0-3
sed/now 4.4-2
`,
linesAfter: `readline-common 7.0-3
sed/now 4.4-2
`,
expectedDiff: nil,
},
{
name: "possibly conflicting names, multi line",
linesBefore: `readline-common 7.0-3
sed/now 4.4-2
`,
linesAfter: `readline-common 7.0-3
sed/now 4.4-2
readline 7.0-3
seda 4.4-2
`,
expectedDiff: &Diff{
Added: []string{
"readline 7.0-3",
"seda 4.4-2",
},
Removed: []string{},
},
},
{
name: "one added one removed, one changed, multi line",
linesBefore: `readline-common 7.0-3
sed/now 4.4-2
`,
linesAfter: `readline-common 7.0-4
util-linux/now 2.31.1-0.4ubuntu3.7
`,
expectedDiff: &Diff{
Added: []string{
"readline-common 7.0-4",
"util-linux/now 2.31.1-0.4ubuntu3.7",
},
Removed: []string{
"readline-common 7.0-3",
"sed/now 4.4-2",
},
},
},
{
name: "all removed, multi line",
linesBefore: `readline-common 7.0-3
sed/now 4.4-2
`,
linesAfter: "",
expectedDiff: &Diff{
Added: []string{},
Removed: []string{
"readline-common 7.0-3",
"sed/now 4.4-2",
},
},
},
{
name: "all added, multi line",
linesBefore: "",
linesAfter: `readline-common 7.0-3
sed/now 4.4-2
`,
expectedDiff: &Diff{
Added: []string{
"readline-common 7.0-3",
"sed/now 4.4-2",
},
Removed: []string{},
},
},
{
name: "all changed, multi line",
linesBefore: `readline-common 7.0-3
sed/now 4.4-2
`,
linesAfter: `readline-common 7.0-4
sed/now 4.4-3
`,
expectedDiff: &Diff{
Added: []string{
"readline-common 7.0-4",
"sed/now 4.4-3",
},
Removed: []string{
"readline-common 7.0-3",
"sed/now 4.4-2",
},
},
},
}
for i := range testCases {
tc := testCases[i]
t.Run(tc.name, func(t *testing.T) {
packagesBefore := strings.Split(tc.linesBefore, "\n")
packagesAfter := strings.Split(tc.linesAfter, "\n")
actualDiff := CalcDiff(packagesBefore, packagesAfter)
if tc.expectedDiff == nil {
assert.Nil(t, actualDiff)
return
}
assert.EqualValues(t, tc.expectedDiff, actualDiff)
})
}
}