Skip to content

Commit

Permalink
#9 fix flaky tests
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Dammeier <alexander.dammeier@cloudogu.com>
  • Loading branch information
jelemux and alexander-dammeier committed Jan 5, 2024
1 parent 1fdcc7b commit a086b36
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pkg/adapter/serializer/stateDiffV1/stateDiffV1_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package stateDiffV1

import (
"cmp"
"github.com/cloudogu/cesapp-lib/core"
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain"
"github.com/stretchr/testify/assert"
"reflect"
"slices"
"testing"
)

Expand Down Expand Up @@ -368,29 +370,29 @@ func TestConvertToDomainModel(t *testing.T) {
},
want: domain.StateDiff{DoguDiffs: []domain.DoguDiff{
{
DoguName: "postfix",
Actual: domain.DoguDiffState{Namespace: "official",
DoguName: "ldap",
Actual: domain.DoguDiffState{
Namespace: "official",
Version: mustParseVersion("1.2.3-4"),
InstallationState: domain.TargetStatePresent,
},
Expected: domain.DoguDiffState{
Namespace: "official",
Version: mustParseVersion("2.3.4-5"),
InstallationState: domain.TargetStatePresent,
},
NeededAction: domain.ActionUpgrade,
InstallationState: domain.TargetStateAbsent,
}, NeededAction: domain.ActionUninstall,
},
{
DoguName: "ldap",
Actual: domain.DoguDiffState{
Namespace: "official",
DoguName: "postfix",
Actual: domain.DoguDiffState{Namespace: "official",
Version: mustParseVersion("1.2.3-4"),
InstallationState: domain.TargetStatePresent,
},
Expected: domain.DoguDiffState{
Namespace: "official",
InstallationState: domain.TargetStateAbsent,
}, NeededAction: domain.ActionUninstall,
Version: mustParseVersion("2.3.4-5"),
InstallationState: domain.TargetStatePresent,
},
NeededAction: domain.ActionUpgrade,
},
}},
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
Expand All @@ -402,6 +404,10 @@ func TestConvertToDomainModel(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
got, err := ConvertToDomainModel(tt.dto)
tt.wantErr(t, err)
// sort to avoid flaky tests
slices.SortFunc(got.DoguDiffs, func(a, b domain.DoguDiff) int {
return cmp.Compare(a.DoguName, b.DoguName)
})
assert.Equal(t, tt.want, got)
})
}
Expand Down

0 comments on commit a086b36

Please sign in to comment.