Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do stable comparison of TestWorkflow #6310

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions pkg/api/v1/testkube/model_test_workflow_extended.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package testkube

import (
"bytes"
"encoding/json"
"time"

"github.com/google/go-cmp/cmp"

"github.com/kubeshop/testkube/pkg/utils"
)

Expand Down Expand Up @@ -132,7 +133,6 @@ func (w *TestWorkflow) DeepCopy() *TestWorkflow {
return &result
}

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

// Compare
w1, _ := json.Marshal(w)
w.Created = time.Time{}
w2, _ := json.Marshal(other)
result := bytes.Equal(w1, w2)
result := cmp.Equal(w, other)

// Restore values
w.Created = wCreated
Expand Down
30 changes: 30 additions & 0 deletions pkg/api/v1/testkube/model_test_workflow_extended_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package testkube

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestTestWorkflowEqualsUnorderedMap(t *testing.T) {
o := &TestWorkflow{
Spec: &TestWorkflowSpec{
Config: map[string]TestWorkflowParameterSchema{
"name1": {Description: "some name"},
"name2": {Description: "another name"},
"name3": {Description: "another name"},
"name6": {Description: "another name"},
"name7": {Description: "another name"},
"name4": {Description: "another name"},
"name5": {Description: "another name"},
"name8": {Description: "another name"},
"name9": {Description: "another name"},
"name10": {Description: "another name"},
"name11": {Description: "another name"},
"name12": {Description: "another name"},
"name13": {Description: "another name"},
},
},
}
assert.Equal(t, true, o.Equals(o.DeepCopy()))
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package testkube

import (
"bytes"
"encoding/json"
"strings"
"time"

"github.com/google/go-cmp/cmp"

"github.com/kubeshop/testkube/pkg/utils"
)

Expand Down Expand Up @@ -94,7 +95,6 @@ func (w *TestWorkflowTemplate) DeepCopy() *TestWorkflowTemplate {
return &result
}

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

// Compare
w1, _ := json.Marshal(w)
w.Created = time.Time{}
w2, _ := json.Marshal(other)
result := bytes.Equal(w1, w2)
result := cmp.Equal(w, other)

// Restore values
w.Created = wCreated
Expand Down
Loading