Skip to content

Commit 2a298f8

Browse files
authored
Compare test results using json diff (#743)
Use json diff to compare results of pipeline tests. This avoids failures caused by different format of equal numbers. After this change two json documents are equal if their values are, independently of their format. Diff returned is not a unified diff anymore, it makes reference now to the different fields following a json-like format.
1 parent 61362f7 commit 2a298f8

File tree

17 files changed

+294
-350
lines changed

17 files changed

+294
-350
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ require (
1616
github.com/fatih/color v1.13.0
1717
github.com/go-git/go-billy/v5 v5.3.1
1818
github.com/go-git/go-git/v5 v5.4.2
19-
github.com/google/go-cmp v0.5.7
2019
github.com/google/go-github/v32 v32.1.0
2120
github.com/google/go-querystring v1.1.0
2221
github.com/jedib0t/go-pretty v4.3.0+incompatible
23-
github.com/kylelemons/godebug v1.1.0
2422
github.com/magefile/mage v1.13.0
2523
github.com/mholt/archiver/v3 v3.5.1
24+
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
2625
github.com/olekukonko/tablewriter v0.0.5
2726
github.com/pkg/errors v0.9.1
2827
github.com/spf13/cobra v1.4.0
@@ -75,6 +74,7 @@ require (
7574
github.com/golang/protobuf v1.5.2 // indirect
7675
github.com/golang/snappy v0.0.3 // indirect
7776
github.com/google/btree v1.0.1 // indirect
77+
github.com/google/go-cmp v0.5.7 // indirect
7878
github.com/google/gofuzz v1.1.0 // indirect
7979
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
8080
github.com/google/uuid v1.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,6 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
783783
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
784784
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
785785
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
786-
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
787-
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
788786
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
789787
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
790788
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@@ -902,6 +900,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
902900
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
903901
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
904902
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
903+
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 h1:NHrXEjTNQY7P0Zfx1aMrNhpgxHmow66XQtm0aQLY0AE=
904+
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8=
905905
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
906906
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
907907
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=

internal/testrunner/runners/pipeline/runner_test.go

Lines changed: 0 additions & 278 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/google/go-cmp/cmp"
1413
"github.com/stretchr/testify/require"
1514
)
1615

@@ -44,283 +43,6 @@ func TestStripEmptyTestResults(t *testing.T) {
4443
require.Equal(t, actual.events[3], json.RawMessage(thirdTestResult))
4544
}
4645

47-
var diffUliteTests = []struct {
48-
name string
49-
a, b string
50-
u int
51-
want string
52-
}{
53-
{
54-
name: "no diff",
55-
u: 3,
56-
a: `a
57-
b
58-
c
59-
d
60-
`,
61-
b: `a
62-
b
63-
c
64-
d
65-
`,
66-
want: "",
67-
},
68-
{
69-
name: "first line",
70-
u: 3,
71-
a: `a change
72-
b
73-
c
74-
d
75-
e
76-
`,
77-
b: `a
78-
b
79-
c
80-
d
81-
e
82-
`,
83-
want: `--- want
84-
+++ got
85-
@@ -1 +1 @@
86-
- a change
87-
+ a
88-
b
89-
c
90-
d`,
91-
},
92-
{
93-
name: "last line",
94-
u: 3,
95-
a: `a
96-
b
97-
c
98-
d
99-
e change
100-
`,
101-
b: `a
102-
b
103-
c
104-
d
105-
e
106-
`,
107-
want: `--- want
108-
+++ got
109-
@@ -2 +2 @@
110-
b
111-
c
112-
d
113-
- e change
114-
+ e
115-
`,
116-
},
117-
{
118-
name: "middle",
119-
u: 3,
120-
a: `a
121-
b
122-
c
123-
d change
124-
e
125-
f
126-
g
127-
h
128-
`,
129-
b: `a
130-
b
131-
c
132-
d
133-
e
134-
f
135-
g
136-
h
137-
`,
138-
want: `--- want
139-
+++ got
140-
@@ -1 +1 @@
141-
a
142-
b
143-
c
144-
- d change
145-
+ d
146-
e
147-
f
148-
g`,
149-
},
150-
{
151-
name: "close pair",
152-
u: 3,
153-
a: `a
154-
b
155-
c
156-
d change
157-
e
158-
f
159-
g
160-
h
161-
i
162-
j
163-
k
164-
l
165-
m
166-
`,
167-
b: `a
168-
b
169-
c
170-
d
171-
e
172-
f
173-
g
174-
h
175-
i change
176-
j
177-
k
178-
l
179-
m
180-
`,
181-
want: `--- want
182-
+++ got
183-
@@ -1 +1 @@
184-
a
185-
b
186-
c
187-
- d change
188-
+ d
189-
e
190-
f
191-
g
192-
h
193-
- i
194-
+ i change
195-
j
196-
k
197-
l`,
198-
},
199-
{
200-
name: "far pair",
201-
u: 3,
202-
a: `a
203-
b
204-
c change
205-
d
206-
e
207-
f
208-
g
209-
h
210-
i
211-
j
212-
k
213-
l
214-
m
215-
`,
216-
b: `a
217-
b
218-
c
219-
d
220-
e
221-
f
222-
g
223-
h
224-
i
225-
j
226-
k
227-
l change
228-
m
229-
`,
230-
want: `--- want
231-
+++ got
232-
@@ -1 +1 @@
233-
a
234-
b
235-
- c change
236-
+ c
237-
d
238-
e
239-
f
240-
@@ -9 +9 @@
241-
i
242-
j
243-
k
244-
- l
245-
+ l change
246-
m
247-
`,
248-
},
249-
{
250-
name: "far pair addition",
251-
u: 3,
252-
a: `a
253-
b
254-
c change
255-
d
256-
e
257-
f
258-
g
259-
a
260-
b
261-
c
262-
d
263-
e
264-
f
265-
g
266-
h
267-
i
268-
j
269-
k
270-
l
271-
m
272-
`,
273-
b: `a
274-
b
275-
c
276-
d
277-
e
278-
f
279-
g
280-
h
281-
i
282-
j
283-
k
284-
l change
285-
m
286-
`,
287-
want: `--- want
288-
+++ got
289-
@@ -1 +1 @@
290-
a
291-
b
292-
- c change
293-
- d
294-
- e
295-
- f
296-
- g
297-
- a
298-
- b
299-
c
300-
d
301-
e
302-
@@ -16 +9 @@
303-
i
304-
j
305-
k
306-
- l
307-
+ l change
308-
m
309-
`,
310-
},
311-
}
312-
313-
func TestDiffUlite(t *testing.T) {
314-
for _, test := range diffUliteTests {
315-
t.Run(test.name, func(t *testing.T) {
316-
got := diffUlite(test.a, test.b, test.u)
317-
if got != test.want {
318-
t.Errorf("unexpected result\n%s", cmp.Diff(got, test.want))
319-
}
320-
})
321-
}
322-
}
323-
32446
var jsonUnmarshalUsingNumberTests = []struct {
32547
name string
32648
msg string

0 commit comments

Comments
 (0)