Skip to content

Commit 26f06dc

Browse files
authored
fix: do stable comparison of TestWorkflow (#6310)
1 parent 11a5df6 commit 26f06dc

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

pkg/api/v1/testkube/model_test_workflow_extended.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package testkube
22

33
import (
4-
"bytes"
54
"encoding/json"
65
"time"
76

7+
"github.com/google/go-cmp/cmp"
8+
89
"github.com/kubeshop/testkube/pkg/utils"
910
)
1011

@@ -132,7 +133,6 @@ func (w *TestWorkflow) DeepCopy() *TestWorkflow {
132133
return &result
133134
}
134135

135-
// TODO: do it stable
136136
func (w *TestWorkflow) Equals(other *TestWorkflow) bool {
137137
// Avoid check when there is one existing and the other one not
138138
if (w == nil) != (other == nil) {
@@ -146,10 +146,7 @@ func (w *TestWorkflow) Equals(other *TestWorkflow) bool {
146146
other.Created = time.Time{}
147147

148148
// Compare
149-
w1, _ := json.Marshal(w)
150-
w.Created = time.Time{}
151-
w2, _ := json.Marshal(other)
152-
result := bytes.Equal(w1, w2)
149+
result := cmp.Equal(w, other)
153150

154151
// Restore values
155152
w.Created = wCreated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package testkube
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestTestWorkflowEqualsUnorderedMap(t *testing.T) {
10+
o := &TestWorkflow{
11+
Spec: &TestWorkflowSpec{
12+
Config: map[string]TestWorkflowParameterSchema{
13+
"name1": {Description: "some name"},
14+
"name2": {Description: "another name"},
15+
"name3": {Description: "another name"},
16+
"name6": {Description: "another name"},
17+
"name7": {Description: "another name"},
18+
"name4": {Description: "another name"},
19+
"name5": {Description: "another name"},
20+
"name8": {Description: "another name"},
21+
"name9": {Description: "another name"},
22+
"name10": {Description: "another name"},
23+
"name11": {Description: "another name"},
24+
"name12": {Description: "another name"},
25+
"name13": {Description: "another name"},
26+
},
27+
},
28+
}
29+
assert.Equal(t, true, o.Equals(o.DeepCopy()))
30+
}

pkg/api/v1/testkube/model_test_workflow_template_extended.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package testkube
22

33
import (
4-
"bytes"
54
"encoding/json"
65
"strings"
76
"time"
87

8+
"github.com/google/go-cmp/cmp"
9+
910
"github.com/kubeshop/testkube/pkg/utils"
1011
)
1112

@@ -94,7 +95,6 @@ func (w *TestWorkflowTemplate) DeepCopy() *TestWorkflowTemplate {
9495
return &result
9596
}
9697

97-
// TODO: do it stable
9898
func (w *TestWorkflowTemplate) Equals(other *TestWorkflowTemplate) bool {
9999
// Avoid check when there is one existing and the other one not
100100
if (w == nil) != (other == nil) {
@@ -108,10 +108,7 @@ func (w *TestWorkflowTemplate) Equals(other *TestWorkflowTemplate) bool {
108108
other.Created = time.Time{}
109109

110110
// Compare
111-
w1, _ := json.Marshal(w)
112-
w.Created = time.Time{}
113-
w2, _ := json.Marshal(other)
114-
result := bytes.Equal(w1, w2)
111+
result := cmp.Equal(w, other)
115112

116113
// Restore values
117114
w.Created = wCreated

0 commit comments

Comments
 (0)