From e2c2151b9b4cac245c2ba494587f25f37af01b25 Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Wed, 3 Jul 2024 07:54:05 +0200 Subject: [PATCH] api/v1: update mock Publish in tests to pass rollup bool parameter --- pkg/api/v1/client/client_test.go | 30 +++++++++++++++--- pkg/api/v1/routes/handlers_test.go | 50 +++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/pkg/api/v1/client/client_test.go b/pkg/api/v1/client/client_test.go index c535a51b..a755246f 100644 --- a/pkg/api/v1/client/client_test.go +++ b/pkg/api/v1/client/client_test.go @@ -14,6 +14,7 @@ import ( "github.com/metal-toolbox/conditionorc/internal/fleetdb" "github.com/metal-toolbox/conditionorc/internal/model" "github.com/metal-toolbox/conditionorc/internal/server" + "github.com/metal-toolbox/conditionorc/internal/store" "github.com/sirupsen/logrus" "github.com/stretchr/testify/mock" @@ -287,7 +288,13 @@ func TestConditionCreate(t *testing.T) { tester.fleetDB.On("GetServer", mock.Anything, mock.Anything).Return(&model.Server{FacilityCode: "facility"}, nil).Once() if tc.expectPublish { - tester.stream.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + tester.stream.On( + "Publish", + mock.Anything, + mock.Anything, + mock.Anything, + false, + ).Return(nil).Once() } got, err := tester.client.ServerConditionCreate(context.TODO(), serverID, rctypes.FirmwareInstall, tc.payload) @@ -385,7 +392,13 @@ func TestFirmwareInstall(t *testing.T) { tester.fleetDB.On("GetServer", mock.Anything, mock.Anything).Return(&model.Server{FacilityCode: "facility"}, nil).Times(1) if tc.expectPublish { - tester.stream.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(1) + tester.stream.On( + "Publish", + mock.Anything, + mock.Anything, + mock.Anything, + false, + ).Return(nil).Times(1) } got, err := tester.client.ServerFirmwareInstall(context.TODO(), tc.payload) @@ -535,7 +548,13 @@ func TestServerEnroll(t *testing.T) { } if tc.expectPublish { - tester.stream.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(1) + tester.stream.On( + "Publish", + mock.Anything, + mock.Anything, + mock.Anything, + false, + ).Return(nil).Times(1) } defer func() { @@ -610,8 +629,9 @@ func TestServerEnrollEmptyUUID(t *testing.T) { tester.stream.On("Publish", mock.Anything, mock.Anything, - mock.Anything). - Return(nil) + mock.Anything, + false, + ).Return(nil) got, err := tester.client.ServerEnroll(context.TODO(), "", v1types.ConditionCreate{Parameters: validParams.MustJSON()}) if err != nil { diff --git a/pkg/api/v1/routes/handlers_test.go b/pkg/api/v1/routes/handlers_test.go index 4a6b2bbe..81e8c8c4 100644 --- a/pkg/api/v1/routes/handlers_test.go +++ b/pkg/api/v1/routes/handlers_test.go @@ -151,9 +151,13 @@ func TestAddServer(t *testing.T) { Once() }, mockStream: func(r *eventsm.MockStream) { - r.On("Publish", mock.Anything, fmt.Sprintf("%s.servers.%s", mockFacilityCode, rctypes.Inventory), mock.Anything). - Return(nil). - Once() + r.On( + "Publish", + mock.Anything, + fmt.Sprintf("%s.servers.%s", mockFacilityCode, rctypes.Inventory), + mock.Anything, + false, + ).Return(nil).Once() }, request: func(t *testing.T) *http.Request { payload, err := json.Marshal(&v1types.ConditionCreate{Parameters: validParams.MustJSON()}) @@ -289,9 +293,13 @@ func TestAddServer(t *testing.T) { Once() }, mockStream: func(r *eventsm.MockStream) { - r.On("Publish", mock.Anything, fmt.Sprintf("%s.servers.%s", mockFacilityCode, rctypes.Inventory), mock.Anything). - Return(nil). - Once() + r.On( + "Publish", + mock.Anything, + fmt.Sprintf("%s.servers.%s", mockFacilityCode, rctypes.Inventory), + mock.Anything, + false, + ).Return(nil).Once() }, request: func(t *testing.T) *http.Request { payload, err := json.Marshal(&v1types.ConditionCreate{Parameters: validParams.MustJSON()}) @@ -606,7 +614,7 @@ func TestAddServerRollback(t *testing.T) { } if tc.mockStreamErr.calledTime > 0 { - stream.On("Publish", mock.Anything, mock.Anything, mock.Anything). + stream.On("Publish", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(tc.mockStreamErr.err). Times(tc.mockStreamErr.calledTime) } @@ -754,9 +762,13 @@ func TestServerConditionCreate(t *testing.T) { Once() }, mockStream: func(r *eventsm.MockStream) { - r.On("Publish", mock.Anything, fmt.Sprintf("%s.servers.%s", facilityCode, rctypes.FirmwareInstall), mock.Anything). - Return(nil). - Once() + r.On( + "Publish", + mock.Anything, + fmt.Sprintf("%s.servers.%s", facilityCode, rctypes.FirmwareInstall), + mock.Anything, + false, + ).Return(nil).Once() }, request: func(t *testing.T) *http.Request { payload, err := json.Marshal(&v1types.ConditionCreate{Parameters: []byte(`{"some param": "1"}`)}) @@ -803,9 +815,13 @@ func TestServerConditionCreate(t *testing.T) { Once() }, mockStream: func(r *eventsm.MockStream) { - r.On("Publish", mock.Anything, fmt.Sprintf("%s.servers.%s", facilityCode, rctypes.FirmwareInstall), mock.Anything). - Return(nil). - Once() + r.On( + "Publish", + mock.Anything, + fmt.Sprintf("%s.servers.%s", facilityCode, rctypes.FirmwareInstall), + mock.Anything, + false, + ).Return(nil).Once() }, request: func(t *testing.T) *http.Request { fault := rctypes.Fault{Panic: true, DelayDuration: "10s", FailAt: "foobar"} @@ -890,7 +906,13 @@ func TestServerConditionCreate(t *testing.T) { Once() }, mockStream: func(r *eventsm.MockStream) { - r.On("Publish", mock.Anything, fmt.Sprintf("%s.servers.%s", facilityCode, rctypes.FirmwareInstall), mock.Anything). + r.On( + "Publish", + mock.Anything, + fmt.Sprintf("%s.servers.%s", facilityCode, rctypes.FirmwareInstall), + mock.Anything, + false, + ). Return(errors.New("gremlins in the pipes")). Once() },