Skip to content

Commit a11521a

Browse files
committed
fix tests
Signed-off-by: Pavel Okhlopkov <[email protected]>
1 parent cc6d879 commit a11521a

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

internal/common-hooks/readiness/hook_test.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package readiness_test
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"testing"
2324
"time"
@@ -27,6 +28,7 @@ import (
2728
"github.com/stretchr/testify/assert"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
31+
"k8s.io/apimachinery/pkg/types"
3032

3133
"github.com/deckhouse/deckhouse/pkg/log"
3234

@@ -64,27 +66,27 @@ func Test_CheckModuleReadiness(t *testing.T) {
6466
},
6567
}
6668

67-
updatedResource := &unstructured.Unstructured{
68-
Object: map[string]interface{}{
69-
"status": map[string]interface{}{
70-
"conditions": []interface{}{
71-
map[string]interface{}{
72-
"type": "IsReady",
73-
"status": "True",
74-
"lastTransitionTime": "2006-01-02T15:04:05Z",
75-
},
69+
patch, err := json.Marshal(map[string]any{
70+
"status": map[string]interface{}{
71+
"conditions": []interface{}{
72+
map[string]interface{}{
73+
"type": "IsReady",
74+
"status": "True",
75+
"lastTransitionTime": "2006-01-02T15:04:05Z",
76+
"lastProbeTime": "2006-01-02T15:04:05Z",
7677
},
77-
"phase": "Ready",
7878
},
79+
"phase": "Ready",
7980
},
80-
}
81+
})
82+
assert.NoError(t, err)
8183

8284
resourceMock := mock.NewKubernetesNamespaceableResourceInterfaceMock(mc)
8385
resourceMock.GetMock.
8486
Expect(minimock.AnyContext, "stub", metav1.GetOptions{}).
8587
Return(resource, nil)
86-
resourceMock.ApplyStatusMock.
87-
Expect(minimock.AnyContext, "stub", updatedResource, metav1.ApplyOptions{}).
88+
resourceMock.PatchMock.
89+
Expect(minimock.AnyContext, "stub", types.MergePatchType, patch, metav1.PatchOptions{}, "status").
8890
Return(nil, nil)
8991

9092
dynamicClientMock := mock.NewKubernetesDynamicClientMock(mc)
@@ -215,27 +217,27 @@ func Test_CheckModuleReadiness(t *testing.T) {
215217
},
216218
}
217219

218-
updatedResource := &unstructured.Unstructured{
219-
Object: map[string]interface{}{
220-
"status": map[string]interface{}{
221-
"conditions": []interface{}{
222-
map[string]interface{}{
223-
"type": "IsReady",
224-
"status": "True",
225-
"lastTransitionTime": "2006-01-02T15:04:05Z",
226-
},
220+
patch, err := json.Marshal(map[string]any{
221+
"status": map[string]interface{}{
222+
"conditions": []interface{}{
223+
map[string]interface{}{
224+
"type": "IsReady",
225+
"status": "True",
226+
"lastTransitionTime": "2006-01-02T15:04:05Z",
227+
"lastProbeTime": "2006-01-02T15:04:05Z",
227228
},
228-
"phase": "Ready",
229229
},
230+
"phase": "Ready",
230231
},
231-
}
232+
})
233+
assert.NoError(t, err)
232234

233235
resourceMock := mock.NewKubernetesNamespaceableResourceInterfaceMock(mc)
234236
resourceMock.GetMock.
235237
Expect(minimock.AnyContext, "stub", metav1.GetOptions{}).
236238
Return(resource, nil)
237-
resourceMock.ApplyStatusMock.
238-
Expect(minimock.AnyContext, "stub", updatedResource, metav1.ApplyOptions{}).
239+
resourceMock.PatchMock.
240+
Expect(minimock.AnyContext, "stub", types.MergePatchType, patch, metav1.PatchOptions{}, "status").
239241
Return(nil, fmt.Errorf("update error"))
240242

241243
dynamicClientMock := mock.NewKubernetesDynamicClientMock(mc)

0 commit comments

Comments
 (0)