diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 2faede0b09..8e8a998849 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -50,7 +50,7 @@ const ( var _ = Describe("Central", func() { var client *fleetmanager.Client - var adminAPI *private.DefaultApiService + var adminAPI fleetmanager.AdminAPI var notes []string BeforeEach(func() { diff --git a/pkg/client/fleetmanager/api_moq.go b/pkg/client/fleetmanager/api_moq.go new file mode 100644 index 0000000000..875314748b --- /dev/null +++ b/pkg/client/fleetmanager/api_moq.go @@ -0,0 +1,659 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package fleetmanager + +import ( + "context" + admin "github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/admin/private" + "github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/private" + "github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public" + "net/http" + "sync" +) + +// Ensure, that PublicAPIMock does implement PublicAPI. +// If this is not the case, regenerate this file with moq. +var _ PublicAPI = &PublicAPIMock{} + +// PublicAPIMock is a mock implementation of PublicAPI. +// +// func TestSomethingThatUsesPublicAPI(t *testing.T) { +// +// // make and configure a mocked PublicAPI +// mockedPublicAPI := &PublicAPIMock{ +// CreateCentralFunc: func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { +// panic("mock out the CreateCentral method") +// }, +// DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { +// panic("mock out the DeleteCentralById method") +// }, +// GetCentralByIdFunc: func(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) { +// panic("mock out the GetCentralById method") +// }, +// GetCentralsFunc: func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { +// panic("mock out the GetCentrals method") +// }, +// } +// +// // use mockedPublicAPI in code that requires PublicAPI +// // and then make assertions. +// +// } +type PublicAPIMock struct { + // CreateCentralFunc mocks the CreateCentral method. + CreateCentralFunc func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) + + // DeleteCentralByIdFunc mocks the DeleteCentralById method. + DeleteCentralByIdFunc func(ctx context.Context, id string, async bool) (*http.Response, error) + + // GetCentralByIdFunc mocks the GetCentralById method. + GetCentralByIdFunc func(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) + + // GetCentralsFunc mocks the GetCentrals method. + GetCentralsFunc func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) + + // calls tracks calls to the methods. + calls struct { + // CreateCentral holds details about calls to the CreateCentral method. + CreateCentral []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Async is the async argument value. + Async bool + // Request is the request argument value. + Request public.CentralRequestPayload + } + // DeleteCentralById holds details about calls to the DeleteCentralById method. + DeleteCentralById []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + // Async is the async argument value. + Async bool + } + // GetCentralById holds details about calls to the GetCentralById method. + GetCentralById []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + } + // GetCentrals holds details about calls to the GetCentrals method. + GetCentrals []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // LocalVarOptionals is the localVarOptionals argument value. + LocalVarOptionals *public.GetCentralsOpts + } + } + lockCreateCentral sync.RWMutex + lockDeleteCentralById sync.RWMutex + lockGetCentralById sync.RWMutex + lockGetCentrals sync.RWMutex +} + +// CreateCentral calls CreateCentralFunc. +func (mock *PublicAPIMock) CreateCentral(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { + if mock.CreateCentralFunc == nil { + panic("PublicAPIMock.CreateCentralFunc: method is nil but PublicAPI.CreateCentral was just called") + } + callInfo := struct { + Ctx context.Context + Async bool + Request public.CentralRequestPayload + }{ + Ctx: ctx, + Async: async, + Request: request, + } + mock.lockCreateCentral.Lock() + mock.calls.CreateCentral = append(mock.calls.CreateCentral, callInfo) + mock.lockCreateCentral.Unlock() + return mock.CreateCentralFunc(ctx, async, request) +} + +// CreateCentralCalls gets all the calls that were made to CreateCentral. +// Check the length with: +// +// len(mockedPublicAPI.CreateCentralCalls()) +func (mock *PublicAPIMock) CreateCentralCalls() []struct { + Ctx context.Context + Async bool + Request public.CentralRequestPayload +} { + var calls []struct { + Ctx context.Context + Async bool + Request public.CentralRequestPayload + } + mock.lockCreateCentral.RLock() + calls = mock.calls.CreateCentral + mock.lockCreateCentral.RUnlock() + return calls +} + +// DeleteCentralById calls DeleteCentralByIdFunc. +func (mock *PublicAPIMock) DeleteCentralById(ctx context.Context, id string, async bool) (*http.Response, error) { + if mock.DeleteCentralByIdFunc == nil { + panic("PublicAPIMock.DeleteCentralByIdFunc: method is nil but PublicAPI.DeleteCentralById was just called") + } + callInfo := struct { + Ctx context.Context + ID string + Async bool + }{ + Ctx: ctx, + ID: id, + Async: async, + } + mock.lockDeleteCentralById.Lock() + mock.calls.DeleteCentralById = append(mock.calls.DeleteCentralById, callInfo) + mock.lockDeleteCentralById.Unlock() + return mock.DeleteCentralByIdFunc(ctx, id, async) +} + +// DeleteCentralByIdCalls gets all the calls that were made to DeleteCentralById. +// Check the length with: +// +// len(mockedPublicAPI.DeleteCentralByIdCalls()) +func (mock *PublicAPIMock) DeleteCentralByIdCalls() []struct { + Ctx context.Context + ID string + Async bool +} { + var calls []struct { + Ctx context.Context + ID string + Async bool + } + mock.lockDeleteCentralById.RLock() + calls = mock.calls.DeleteCentralById + mock.lockDeleteCentralById.RUnlock() + return calls +} + +// GetCentralById calls GetCentralByIdFunc. +func (mock *PublicAPIMock) GetCentralById(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) { + if mock.GetCentralByIdFunc == nil { + panic("PublicAPIMock.GetCentralByIdFunc: method is nil but PublicAPI.GetCentralById was just called") + } + callInfo := struct { + Ctx context.Context + ID string + }{ + Ctx: ctx, + ID: id, + } + mock.lockGetCentralById.Lock() + mock.calls.GetCentralById = append(mock.calls.GetCentralById, callInfo) + mock.lockGetCentralById.Unlock() + return mock.GetCentralByIdFunc(ctx, id) +} + +// GetCentralByIdCalls gets all the calls that were made to GetCentralById. +// Check the length with: +// +// len(mockedPublicAPI.GetCentralByIdCalls()) +func (mock *PublicAPIMock) GetCentralByIdCalls() []struct { + Ctx context.Context + ID string +} { + var calls []struct { + Ctx context.Context + ID string + } + mock.lockGetCentralById.RLock() + calls = mock.calls.GetCentralById + mock.lockGetCentralById.RUnlock() + return calls +} + +// GetCentrals calls GetCentralsFunc. +func (mock *PublicAPIMock) GetCentrals(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { + if mock.GetCentralsFunc == nil { + panic("PublicAPIMock.GetCentralsFunc: method is nil but PublicAPI.GetCentrals was just called") + } + callInfo := struct { + Ctx context.Context + LocalVarOptionals *public.GetCentralsOpts + }{ + Ctx: ctx, + LocalVarOptionals: localVarOptionals, + } + mock.lockGetCentrals.Lock() + mock.calls.GetCentrals = append(mock.calls.GetCentrals, callInfo) + mock.lockGetCentrals.Unlock() + return mock.GetCentralsFunc(ctx, localVarOptionals) +} + +// GetCentralsCalls gets all the calls that were made to GetCentrals. +// Check the length with: +// +// len(mockedPublicAPI.GetCentralsCalls()) +func (mock *PublicAPIMock) GetCentralsCalls() []struct { + Ctx context.Context + LocalVarOptionals *public.GetCentralsOpts +} { + var calls []struct { + Ctx context.Context + LocalVarOptionals *public.GetCentralsOpts + } + mock.lockGetCentrals.RLock() + calls = mock.calls.GetCentrals + mock.lockGetCentrals.RUnlock() + return calls +} + +// Ensure, that PrivateAPIMock does implement PrivateAPI. +// If this is not the case, regenerate this file with moq. +var _ PrivateAPI = &PrivateAPIMock{} + +// PrivateAPIMock is a mock implementation of PrivateAPI. +// +// func TestSomethingThatUsesPrivateAPI(t *testing.T) { +// +// // make and configure a mocked PrivateAPI +// mockedPrivateAPI := &PrivateAPIMock{ +// GetCentralsFunc: func(ctx context.Context, id string) (private.ManagedCentralList, *http.Response, error) { +// panic("mock out the GetCentrals method") +// }, +// GetDataPlaneClusterAgentConfigFunc: func(ctx context.Context, id string) (private.DataplaneClusterAgentConfig, *http.Response, error) { +// panic("mock out the GetDataPlaneClusterAgentConfig method") +// }, +// UpdateCentralClusterStatusFunc: func(ctx context.Context, id string, requestBody map[string]private.DataPlaneCentralStatus) (*http.Response, error) { +// panic("mock out the UpdateCentralClusterStatus method") +// }, +// } +// +// // use mockedPrivateAPI in code that requires PrivateAPI +// // and then make assertions. +// +// } +type PrivateAPIMock struct { + // GetCentralsFunc mocks the GetCentrals method. + GetCentralsFunc func(ctx context.Context, id string) (private.ManagedCentralList, *http.Response, error) + + // GetDataPlaneClusterAgentConfigFunc mocks the GetDataPlaneClusterAgentConfig method. + GetDataPlaneClusterAgentConfigFunc func(ctx context.Context, id string) (private.DataplaneClusterAgentConfig, *http.Response, error) + + // UpdateCentralClusterStatusFunc mocks the UpdateCentralClusterStatus method. + UpdateCentralClusterStatusFunc func(ctx context.Context, id string, requestBody map[string]private.DataPlaneCentralStatus) (*http.Response, error) + + // calls tracks calls to the methods. + calls struct { + // GetCentrals holds details about calls to the GetCentrals method. + GetCentrals []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + } + // GetDataPlaneClusterAgentConfig holds details about calls to the GetDataPlaneClusterAgentConfig method. + GetDataPlaneClusterAgentConfig []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + } + // UpdateCentralClusterStatus holds details about calls to the UpdateCentralClusterStatus method. + UpdateCentralClusterStatus []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + // RequestBody is the requestBody argument value. + RequestBody map[string]private.DataPlaneCentralStatus + } + } + lockGetCentrals sync.RWMutex + lockGetDataPlaneClusterAgentConfig sync.RWMutex + lockUpdateCentralClusterStatus sync.RWMutex +} + +// GetCentrals calls GetCentralsFunc. +func (mock *PrivateAPIMock) GetCentrals(ctx context.Context, id string) (private.ManagedCentralList, *http.Response, error) { + if mock.GetCentralsFunc == nil { + panic("PrivateAPIMock.GetCentralsFunc: method is nil but PrivateAPI.GetCentrals was just called") + } + callInfo := struct { + Ctx context.Context + ID string + }{ + Ctx: ctx, + ID: id, + } + mock.lockGetCentrals.Lock() + mock.calls.GetCentrals = append(mock.calls.GetCentrals, callInfo) + mock.lockGetCentrals.Unlock() + return mock.GetCentralsFunc(ctx, id) +} + +// GetCentralsCalls gets all the calls that were made to GetCentrals. +// Check the length with: +// +// len(mockedPrivateAPI.GetCentralsCalls()) +func (mock *PrivateAPIMock) GetCentralsCalls() []struct { + Ctx context.Context + ID string +} { + var calls []struct { + Ctx context.Context + ID string + } + mock.lockGetCentrals.RLock() + calls = mock.calls.GetCentrals + mock.lockGetCentrals.RUnlock() + return calls +} + +// GetDataPlaneClusterAgentConfig calls GetDataPlaneClusterAgentConfigFunc. +func (mock *PrivateAPIMock) GetDataPlaneClusterAgentConfig(ctx context.Context, id string) (private.DataplaneClusterAgentConfig, *http.Response, error) { + if mock.GetDataPlaneClusterAgentConfigFunc == nil { + panic("PrivateAPIMock.GetDataPlaneClusterAgentConfigFunc: method is nil but PrivateAPI.GetDataPlaneClusterAgentConfig was just called") + } + callInfo := struct { + Ctx context.Context + ID string + }{ + Ctx: ctx, + ID: id, + } + mock.lockGetDataPlaneClusterAgentConfig.Lock() + mock.calls.GetDataPlaneClusterAgentConfig = append(mock.calls.GetDataPlaneClusterAgentConfig, callInfo) + mock.lockGetDataPlaneClusterAgentConfig.Unlock() + return mock.GetDataPlaneClusterAgentConfigFunc(ctx, id) +} + +// GetDataPlaneClusterAgentConfigCalls gets all the calls that were made to GetDataPlaneClusterAgentConfig. +// Check the length with: +// +// len(mockedPrivateAPI.GetDataPlaneClusterAgentConfigCalls()) +func (mock *PrivateAPIMock) GetDataPlaneClusterAgentConfigCalls() []struct { + Ctx context.Context + ID string +} { + var calls []struct { + Ctx context.Context + ID string + } + mock.lockGetDataPlaneClusterAgentConfig.RLock() + calls = mock.calls.GetDataPlaneClusterAgentConfig + mock.lockGetDataPlaneClusterAgentConfig.RUnlock() + return calls +} + +// UpdateCentralClusterStatus calls UpdateCentralClusterStatusFunc. +func (mock *PrivateAPIMock) UpdateCentralClusterStatus(ctx context.Context, id string, requestBody map[string]private.DataPlaneCentralStatus) (*http.Response, error) { + if mock.UpdateCentralClusterStatusFunc == nil { + panic("PrivateAPIMock.UpdateCentralClusterStatusFunc: method is nil but PrivateAPI.UpdateCentralClusterStatus was just called") + } + callInfo := struct { + Ctx context.Context + ID string + RequestBody map[string]private.DataPlaneCentralStatus + }{ + Ctx: ctx, + ID: id, + RequestBody: requestBody, + } + mock.lockUpdateCentralClusterStatus.Lock() + mock.calls.UpdateCentralClusterStatus = append(mock.calls.UpdateCentralClusterStatus, callInfo) + mock.lockUpdateCentralClusterStatus.Unlock() + return mock.UpdateCentralClusterStatusFunc(ctx, id, requestBody) +} + +// UpdateCentralClusterStatusCalls gets all the calls that were made to UpdateCentralClusterStatus. +// Check the length with: +// +// len(mockedPrivateAPI.UpdateCentralClusterStatusCalls()) +func (mock *PrivateAPIMock) UpdateCentralClusterStatusCalls() []struct { + Ctx context.Context + ID string + RequestBody map[string]private.DataPlaneCentralStatus +} { + var calls []struct { + Ctx context.Context + ID string + RequestBody map[string]private.DataPlaneCentralStatus + } + mock.lockUpdateCentralClusterStatus.RLock() + calls = mock.calls.UpdateCentralClusterStatus + mock.lockUpdateCentralClusterStatus.RUnlock() + return calls +} + +// Ensure, that AdminAPIMock does implement AdminAPI. +// If this is not the case, regenerate this file with moq. +var _ AdminAPI = &AdminAPIMock{} + +// AdminAPIMock is a mock implementation of AdminAPI. +// +// func TestSomethingThatUsesAdminAPI(t *testing.T) { +// +// // make and configure a mocked AdminAPI +// mockedAdminAPI := &AdminAPIMock{ +// CreateCentralFunc: func(ctx context.Context, async bool, centralRequestPayload admin.CentralRequestPayload) (admin.CentralRequest, *http.Response, error) { +// panic("mock out the CreateCentral method") +// }, +// DeleteDbCentralByIdFunc: func(ctx context.Context, id string) (*http.Response, error) { +// panic("mock out the DeleteDbCentralById method") +// }, +// GetCentralsFunc: func(ctx context.Context, localVarOptionals *admin.GetCentralsOpts) (admin.CentralList, *http.Response, error) { +// panic("mock out the GetCentrals method") +// }, +// UpdateCentralByIdFunc: func(ctx context.Context, id string, centralUpdateRequest admin.CentralUpdateRequest) (admin.Central, *http.Response, error) { +// panic("mock out the UpdateCentralById method") +// }, +// } +// +// // use mockedAdminAPI in code that requires AdminAPI +// // and then make assertions. +// +// } +type AdminAPIMock struct { + // CreateCentralFunc mocks the CreateCentral method. + CreateCentralFunc func(ctx context.Context, async bool, centralRequestPayload admin.CentralRequestPayload) (admin.CentralRequest, *http.Response, error) + + // DeleteDbCentralByIdFunc mocks the DeleteDbCentralById method. + DeleteDbCentralByIdFunc func(ctx context.Context, id string) (*http.Response, error) + + // GetCentralsFunc mocks the GetCentrals method. + GetCentralsFunc func(ctx context.Context, localVarOptionals *admin.GetCentralsOpts) (admin.CentralList, *http.Response, error) + + // UpdateCentralByIdFunc mocks the UpdateCentralById method. + UpdateCentralByIdFunc func(ctx context.Context, id string, centralUpdateRequest admin.CentralUpdateRequest) (admin.Central, *http.Response, error) + + // calls tracks calls to the methods. + calls struct { + // CreateCentral holds details about calls to the CreateCentral method. + CreateCentral []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Async is the async argument value. + Async bool + // CentralRequestPayload is the centralRequestPayload argument value. + CentralRequestPayload admin.CentralRequestPayload + } + // DeleteDbCentralById holds details about calls to the DeleteDbCentralById method. + DeleteDbCentralById []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + } + // GetCentrals holds details about calls to the GetCentrals method. + GetCentrals []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // LocalVarOptionals is the localVarOptionals argument value. + LocalVarOptionals *admin.GetCentralsOpts + } + // UpdateCentralById holds details about calls to the UpdateCentralById method. + UpdateCentralById []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // ID is the id argument value. + ID string + // CentralUpdateRequest is the centralUpdateRequest argument value. + CentralUpdateRequest admin.CentralUpdateRequest + } + } + lockCreateCentral sync.RWMutex + lockDeleteDbCentralById sync.RWMutex + lockGetCentrals sync.RWMutex + lockUpdateCentralById sync.RWMutex +} + +// CreateCentral calls CreateCentralFunc. +func (mock *AdminAPIMock) CreateCentral(ctx context.Context, async bool, centralRequestPayload admin.CentralRequestPayload) (admin.CentralRequest, *http.Response, error) { + if mock.CreateCentralFunc == nil { + panic("AdminAPIMock.CreateCentralFunc: method is nil but AdminAPI.CreateCentral was just called") + } + callInfo := struct { + Ctx context.Context + Async bool + CentralRequestPayload admin.CentralRequestPayload + }{ + Ctx: ctx, + Async: async, + CentralRequestPayload: centralRequestPayload, + } + mock.lockCreateCentral.Lock() + mock.calls.CreateCentral = append(mock.calls.CreateCentral, callInfo) + mock.lockCreateCentral.Unlock() + return mock.CreateCentralFunc(ctx, async, centralRequestPayload) +} + +// CreateCentralCalls gets all the calls that were made to CreateCentral. +// Check the length with: +// +// len(mockedAdminAPI.CreateCentralCalls()) +func (mock *AdminAPIMock) CreateCentralCalls() []struct { + Ctx context.Context + Async bool + CentralRequestPayload admin.CentralRequestPayload +} { + var calls []struct { + Ctx context.Context + Async bool + CentralRequestPayload admin.CentralRequestPayload + } + mock.lockCreateCentral.RLock() + calls = mock.calls.CreateCentral + mock.lockCreateCentral.RUnlock() + return calls +} + +// DeleteDbCentralById calls DeleteDbCentralByIdFunc. +func (mock *AdminAPIMock) DeleteDbCentralById(ctx context.Context, id string) (*http.Response, error) { + if mock.DeleteDbCentralByIdFunc == nil { + panic("AdminAPIMock.DeleteDbCentralByIdFunc: method is nil but AdminAPI.DeleteDbCentralById was just called") + } + callInfo := struct { + Ctx context.Context + ID string + }{ + Ctx: ctx, + ID: id, + } + mock.lockDeleteDbCentralById.Lock() + mock.calls.DeleteDbCentralById = append(mock.calls.DeleteDbCentralById, callInfo) + mock.lockDeleteDbCentralById.Unlock() + return mock.DeleteDbCentralByIdFunc(ctx, id) +} + +// DeleteDbCentralByIdCalls gets all the calls that were made to DeleteDbCentralById. +// Check the length with: +// +// len(mockedAdminAPI.DeleteDbCentralByIdCalls()) +func (mock *AdminAPIMock) DeleteDbCentralByIdCalls() []struct { + Ctx context.Context + ID string +} { + var calls []struct { + Ctx context.Context + ID string + } + mock.lockDeleteDbCentralById.RLock() + calls = mock.calls.DeleteDbCentralById + mock.lockDeleteDbCentralById.RUnlock() + return calls +} + +// GetCentrals calls GetCentralsFunc. +func (mock *AdminAPIMock) GetCentrals(ctx context.Context, localVarOptionals *admin.GetCentralsOpts) (admin.CentralList, *http.Response, error) { + if mock.GetCentralsFunc == nil { + panic("AdminAPIMock.GetCentralsFunc: method is nil but AdminAPI.GetCentrals was just called") + } + callInfo := struct { + Ctx context.Context + LocalVarOptionals *admin.GetCentralsOpts + }{ + Ctx: ctx, + LocalVarOptionals: localVarOptionals, + } + mock.lockGetCentrals.Lock() + mock.calls.GetCentrals = append(mock.calls.GetCentrals, callInfo) + mock.lockGetCentrals.Unlock() + return mock.GetCentralsFunc(ctx, localVarOptionals) +} + +// GetCentralsCalls gets all the calls that were made to GetCentrals. +// Check the length with: +// +// len(mockedAdminAPI.GetCentralsCalls()) +func (mock *AdminAPIMock) GetCentralsCalls() []struct { + Ctx context.Context + LocalVarOptionals *admin.GetCentralsOpts +} { + var calls []struct { + Ctx context.Context + LocalVarOptionals *admin.GetCentralsOpts + } + mock.lockGetCentrals.RLock() + calls = mock.calls.GetCentrals + mock.lockGetCentrals.RUnlock() + return calls +} + +// UpdateCentralById calls UpdateCentralByIdFunc. +func (mock *AdminAPIMock) UpdateCentralById(ctx context.Context, id string, centralUpdateRequest admin.CentralUpdateRequest) (admin.Central, *http.Response, error) { + if mock.UpdateCentralByIdFunc == nil { + panic("AdminAPIMock.UpdateCentralByIdFunc: method is nil but AdminAPI.UpdateCentralById was just called") + } + callInfo := struct { + Ctx context.Context + ID string + CentralUpdateRequest admin.CentralUpdateRequest + }{ + Ctx: ctx, + ID: id, + CentralUpdateRequest: centralUpdateRequest, + } + mock.lockUpdateCentralById.Lock() + mock.calls.UpdateCentralById = append(mock.calls.UpdateCentralById, callInfo) + mock.lockUpdateCentralById.Unlock() + return mock.UpdateCentralByIdFunc(ctx, id, centralUpdateRequest) +} + +// UpdateCentralByIdCalls gets all the calls that were made to UpdateCentralById. +// Check the length with: +// +// len(mockedAdminAPI.UpdateCentralByIdCalls()) +func (mock *AdminAPIMock) UpdateCentralByIdCalls() []struct { + Ctx context.Context + ID string + CentralUpdateRequest admin.CentralUpdateRequest +} { + var calls []struct { + Ctx context.Context + ID string + CentralUpdateRequest admin.CentralUpdateRequest + } + mock.lockUpdateCentralById.RLock() + calls = mock.calls.UpdateCentralById + mock.lockUpdateCentralById.RUnlock() + return calls +} diff --git a/pkg/client/fleetmanager/client.go b/pkg/client/fleetmanager/client.go index 12f5353539..5fea323532 100644 --- a/pkg/client/fleetmanager/client.go +++ b/pkg/client/fleetmanager/client.go @@ -11,21 +11,50 @@ import ( "github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public" ) -// PublicClient is a wrapper interface for the fleetmanager client public API. -// -//go:generate moq -out client_moq.go . PublicClient -type PublicClient interface { +//go:generate moq -out api_moq.go . PublicAPI PrivateAPI AdminAPI + +// PublicAPI is a wrapper interface for the fleetmanager client public API. +type PublicAPI interface { CreateCentral(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) DeleteCentralById(ctx context.Context, id string, async bool) (*http.Response, error) GetCentralById(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) GetCentrals(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) } +// PrivateAPI is a wrapper interface for the fleetmanager client private API. +type PrivateAPI interface { + GetDataPlaneClusterAgentConfig(ctx context.Context, id string) (private.DataplaneClusterAgentConfig, *http.Response, error) + GetCentrals(ctx context.Context, id string) (private.ManagedCentralList, *http.Response, error) + UpdateCentralClusterStatus(ctx context.Context, id string, requestBody map[string]private.DataPlaneCentralStatus) (*http.Response, error) +} + +// AdminAPI is a wrapper interface for the fleetmanager client admin API. +type AdminAPI interface { + GetCentrals(ctx context.Context, localVarOptionals *admin.GetCentralsOpts) (admin.CentralList, *http.Response, error) + CreateCentral(ctx context.Context, async bool, centralRequestPayload admin.CentralRequestPayload) (admin.CentralRequest, *http.Response, error) + UpdateCentralById(ctx context.Context, id string, centralUpdateRequest admin.CentralUpdateRequest) (admin.Central, *http.Response, error) + DeleteDbCentralById(ctx context.Context, id string) (*http.Response, error) +} + var ( _ http.RoundTripper = (*authTransport)(nil) - _ PublicClient = (*public.DefaultApiService)(nil) + _ PublicAPI = (*publicAPIDelegate)(nil) + _ PrivateAPI = (*privateAPIDelegate)(nil) + _ AdminAPI = (*adminAPIDelegate)(nil) ) +type publicAPIDelegate struct { + *public.DefaultApiService +} + +type privateAPIDelegate struct { + *private.AgentClustersApiService +} + +type adminAPIDelegate struct { + *admin.DefaultApiService +} + type authTransport struct { transport http.RoundTripper auth Auth @@ -50,9 +79,9 @@ func newAuthTransport(auth Auth) *authTransport { // Client is a helper struct that wraps around the API clients generated from // OpenAPI spec for the three different API groups of fleet manager: public, private, admin. type Client struct { - public *public.APIClient - private *private.APIClient - admin *admin.APIClient + publicAPI PublicAPI + privateAPI PrivateAPI + adminAPI AdminAPI } // ClientOption to configure the Client. @@ -104,39 +133,45 @@ func NewClient(endpoint string, auth Auth, opts ...ClientOption) (*Client, error Transport: newAuthTransport(auth), } - client.public = public.NewAPIClient(&public.Configuration{ - BasePath: endpoint, - UserAgent: o.userAgent, - Debug: o.debug, - HTTPClient: httpClient, - }) - client.private = private.NewAPIClient(&private.Configuration{ - BasePath: endpoint, - UserAgent: o.userAgent, - Debug: o.debug, - HTTPClient: httpClient, - }) - client.admin = admin.NewAPIClient(&admin.Configuration{ - BasePath: endpoint, - UserAgent: o.userAgent, - Debug: o.debug, - HTTPClient: httpClient, - }) + client.publicAPI = &publicAPIDelegate{ + DefaultApiService: public.NewAPIClient(&public.Configuration{ + BasePath: endpoint, + UserAgent: o.userAgent, + Debug: o.debug, + HTTPClient: httpClient, + }).DefaultApi, + } + client.privateAPI = &privateAPIDelegate{ + AgentClustersApiService: private.NewAPIClient(&private.Configuration{ + BasePath: endpoint, + UserAgent: o.userAgent, + Debug: o.debug, + HTTPClient: httpClient, + }).AgentClustersApi, + } + client.adminAPI = &adminAPIDelegate{ + DefaultApiService: admin.NewAPIClient(&admin.Configuration{ + BasePath: endpoint, + UserAgent: o.userAgent, + Debug: o.debug, + HTTPClient: httpClient, + }).DefaultApi, + } return client, nil } // PublicAPI returns the service to interact with fleet manager's public API. -func (c *Client) PublicAPI() *public.DefaultApiService { - return c.public.DefaultApi +func (c *Client) PublicAPI() PublicAPI { + return c.publicAPI } // PrivateAPI returns the service to interact with fleet manager's private API. -func (c *Client) PrivateAPI() *private.AgentClustersApiService { - return c.private.AgentClustersApi +func (c *Client) PrivateAPI() PrivateAPI { + return c.privateAPI } // AdminAPI returns the service to interact with fleet manager's admin API. -func (c *Client) AdminAPI() *admin.DefaultApiService { - return c.admin.DefaultApi +func (c *Client) AdminAPI() AdminAPI { + return c.adminAPI } diff --git a/pkg/client/fleetmanager/client_mock.go b/pkg/client/fleetmanager/client_mock.go new file mode 100644 index 0000000000..cb66ccd105 --- /dev/null +++ b/pkg/client/fleetmanager/client_mock.go @@ -0,0 +1,26 @@ +package fleetmanager + +// ClientMock API mocks holder. +type ClientMock struct { + PublicAPIMock *PublicAPIMock + PrivateAPIMock *PrivateAPIMock + AdminAPIMock *AdminAPIMock +} + +// NewClientMock creates a new instance of ClientMock +func NewClientMock() *ClientMock { + return &ClientMock{ + PublicAPIMock: &PublicAPIMock{}, + PrivateAPIMock: &PrivateAPIMock{}, + AdminAPIMock: &AdminAPIMock{}, + } +} + +// Client returns new Client instance +func (m *ClientMock) Client() *Client { + return &Client{ + privateAPI: m.PrivateAPIMock, + publicAPI: m.PublicAPIMock, + adminAPI: m.AdminAPIMock, + } +} diff --git a/pkg/client/fleetmanager/client_moq.go b/pkg/client/fleetmanager/client_moq.go deleted file mode 100644 index c3d7ec1580..0000000000 --- a/pkg/client/fleetmanager/client_moq.go +++ /dev/null @@ -1,245 +0,0 @@ -// Code generated by moq; DO NOT EDIT. -// github.com/matryer/moq - -package fleetmanager - -import ( - "context" - "github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public" - "net/http" - "sync" -) - -// Ensure, that PublicClientMock does implement PublicClient. -// If this is not the case, regenerate this file with moq. -var _ PublicClient = &PublicClientMock{} - -// PublicClientMock is a mock implementation of PublicClient. -// -// func TestSomethingThatUsesPublicClient(t *testing.T) { -// -// // make and configure a mocked PublicClient -// mockedPublicClient := &PublicClientMock{ -// CreateCentralFunc: func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { -// panic("mock out the CreateCentral method") -// }, -// DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { -// panic("mock out the DeleteCentralById method") -// }, -// GetCentralByIdFunc: func(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) { -// panic("mock out the GetCentralById method") -// }, -// GetCentralsFunc: func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { -// panic("mock out the GetCentrals method") -// }, -// } -// -// // use mockedPublicClient in code that requires PublicClient -// // and then make assertions. -// -// } -type PublicClientMock struct { - // CreateCentralFunc mocks the CreateCentral method. - CreateCentralFunc func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) - - // DeleteCentralByIdFunc mocks the DeleteCentralById method. - DeleteCentralByIdFunc func(ctx context.Context, id string, async bool) (*http.Response, error) - - // GetCentralByIdFunc mocks the GetCentralById method. - GetCentralByIdFunc func(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) - - // GetCentralsFunc mocks the GetCentrals method. - GetCentralsFunc func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) - - // calls tracks calls to the methods. - calls struct { - // CreateCentral holds details about calls to the CreateCentral method. - CreateCentral []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Async is the async argument value. - Async bool - // Request is the request argument value. - Request public.CentralRequestPayload - } - // DeleteCentralById holds details about calls to the DeleteCentralById method. - DeleteCentralById []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID string - // Async is the async argument value. - Async bool - } - // GetCentralById holds details about calls to the GetCentralById method. - GetCentralById []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // ID is the id argument value. - ID string - } - // GetCentrals holds details about calls to the GetCentrals method. - GetCentrals []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // LocalVarOptionals is the localVarOptionals argument value. - LocalVarOptionals *public.GetCentralsOpts - } - } - lockCreateCentral sync.RWMutex - lockDeleteCentralById sync.RWMutex - lockGetCentralById sync.RWMutex - lockGetCentrals sync.RWMutex -} - -// CreateCentral calls CreateCentralFunc. -func (mock *PublicClientMock) CreateCentral(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { - if mock.CreateCentralFunc == nil { - panic("PublicClientMock.CreateCentralFunc: method is nil but PublicClient.CreateCentral was just called") - } - callInfo := struct { - Ctx context.Context - Async bool - Request public.CentralRequestPayload - }{ - Ctx: ctx, - Async: async, - Request: request, - } - mock.lockCreateCentral.Lock() - mock.calls.CreateCentral = append(mock.calls.CreateCentral, callInfo) - mock.lockCreateCentral.Unlock() - return mock.CreateCentralFunc(ctx, async, request) -} - -// CreateCentralCalls gets all the calls that were made to CreateCentral. -// Check the length with: -// -// len(mockedPublicClient.CreateCentralCalls()) -func (mock *PublicClientMock) CreateCentralCalls() []struct { - Ctx context.Context - Async bool - Request public.CentralRequestPayload -} { - var calls []struct { - Ctx context.Context - Async bool - Request public.CentralRequestPayload - } - mock.lockCreateCentral.RLock() - calls = mock.calls.CreateCentral - mock.lockCreateCentral.RUnlock() - return calls -} - -// DeleteCentralById calls DeleteCentralByIdFunc. -func (mock *PublicClientMock) DeleteCentralById(ctx context.Context, id string, async bool) (*http.Response, error) { - if mock.DeleteCentralByIdFunc == nil { - panic("PublicClientMock.DeleteCentralByIdFunc: method is nil but PublicClient.DeleteCentralById was just called") - } - callInfo := struct { - Ctx context.Context - ID string - Async bool - }{ - Ctx: ctx, - ID: id, - Async: async, - } - mock.lockDeleteCentralById.Lock() - mock.calls.DeleteCentralById = append(mock.calls.DeleteCentralById, callInfo) - mock.lockDeleteCentralById.Unlock() - return mock.DeleteCentralByIdFunc(ctx, id, async) -} - -// DeleteCentralByIdCalls gets all the calls that were made to DeleteCentralById. -// Check the length with: -// -// len(mockedPublicClient.DeleteCentralByIdCalls()) -func (mock *PublicClientMock) DeleteCentralByIdCalls() []struct { - Ctx context.Context - ID string - Async bool -} { - var calls []struct { - Ctx context.Context - ID string - Async bool - } - mock.lockDeleteCentralById.RLock() - calls = mock.calls.DeleteCentralById - mock.lockDeleteCentralById.RUnlock() - return calls -} - -// GetCentralById calls GetCentralByIdFunc. -func (mock *PublicClientMock) GetCentralById(ctx context.Context, id string) (public.CentralRequest, *http.Response, error) { - if mock.GetCentralByIdFunc == nil { - panic("PublicClientMock.GetCentralByIdFunc: method is nil but PublicClient.GetCentralById was just called") - } - callInfo := struct { - Ctx context.Context - ID string - }{ - Ctx: ctx, - ID: id, - } - mock.lockGetCentralById.Lock() - mock.calls.GetCentralById = append(mock.calls.GetCentralById, callInfo) - mock.lockGetCentralById.Unlock() - return mock.GetCentralByIdFunc(ctx, id) -} - -// GetCentralByIdCalls gets all the calls that were made to GetCentralById. -// Check the length with: -// -// len(mockedPublicClient.GetCentralByIdCalls()) -func (mock *PublicClientMock) GetCentralByIdCalls() []struct { - Ctx context.Context - ID string -} { - var calls []struct { - Ctx context.Context - ID string - } - mock.lockGetCentralById.RLock() - calls = mock.calls.GetCentralById - mock.lockGetCentralById.RUnlock() - return calls -} - -// GetCentrals calls GetCentralsFunc. -func (mock *PublicClientMock) GetCentrals(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { - if mock.GetCentralsFunc == nil { - panic("PublicClientMock.GetCentralsFunc: method is nil but PublicClient.GetCentrals was just called") - } - callInfo := struct { - Ctx context.Context - LocalVarOptionals *public.GetCentralsOpts - }{ - Ctx: ctx, - LocalVarOptionals: localVarOptionals, - } - mock.lockGetCentrals.Lock() - mock.calls.GetCentrals = append(mock.calls.GetCentrals, callInfo) - mock.lockGetCentrals.Unlock() - return mock.GetCentralsFunc(ctx, localVarOptionals) -} - -// GetCentralsCalls gets all the calls that were made to GetCentrals. -// Check the length with: -// -// len(mockedPublicClient.GetCentralsCalls()) -func (mock *PublicClientMock) GetCentralsCalls() []struct { - Ctx context.Context - LocalVarOptionals *public.GetCentralsOpts -} { - var calls []struct { - Ctx context.Context - LocalVarOptionals *public.GetCentralsOpts - } - mock.lockGetCentrals.RLock() - calls = mock.calls.GetCentrals - mock.lockGetCentrals.RUnlock() - return calls -} diff --git a/probe/internal/cli/cli.go b/probe/internal/cli/cli.go index 9df7e9bb07..c19c92fd16 100644 --- a/probe/internal/cli/cli.go +++ b/probe/internal/cli/cli.go @@ -29,14 +29,14 @@ type CLI struct { // New creates a CLI. func New(config *config.Config) (*CLI, error) { - fleetManagerClient, err := fleetmanager.New(config) + fleetManagerPublicAPI, err := fleetmanager.New(config) if err != nil { return nil, errors.Wrap(err, "failed to create fleet manager client") } httpClient := &http.Client{Timeout: config.ProbeHTTPRequestTimeout} - probe := probe.New(config, fleetManagerClient, httpClient) + probe := probe.New(config, fleetManagerPublicAPI, httpClient) runtime, err := runtime.New(config, probe) if err != nil { diff --git a/probe/pkg/fleetmanager/client.go b/probe/pkg/fleetmanager/client.go index 50d6f5be6a..a9b76b5dc5 100644 --- a/probe/pkg/fleetmanager/client.go +++ b/probe/pkg/fleetmanager/client.go @@ -8,7 +8,7 @@ import ( ) // New creates a new fleet manager client. -func New(config *config.Config) (fleetmanager.PublicClient, error) { +func New(config *config.Config) (fleetmanager.PublicAPI, error) { auth, err := fleetmanager.NewAuth(config.AuthType, fleetmanager.OptionFromEnv()) if err != nil { return nil, errors.Wrap(err, "failed to create fleet manager authentication") diff --git a/probe/pkg/probe/probe.go b/probe/pkg/probe/probe.go index 4fb8c995b9..9a642f20f9 100644 --- a/probe/pkg/probe/probe.go +++ b/probe/pkg/probe/probe.go @@ -33,17 +33,17 @@ var _ Probe = (*ProbeImpl)(nil) // ProbeImpl executes a probe run against fleet manager. type ProbeImpl struct { - config *config.Config - fleetManagerClient fleetmanager.PublicClient - httpClient *http.Client + config *config.Config + fleetManagerPublicAPI fleetmanager.PublicAPI + httpClient *http.Client } // New creates a new probe. -func New(config *config.Config, fleetManagerClient fleetmanager.PublicClient, httpClient *http.Client) *ProbeImpl { +func New(config *config.Config, fleetManagerPublicAPI fleetmanager.PublicAPI, httpClient *http.Client) *ProbeImpl { return &ProbeImpl{ - config: config, - fleetManagerClient: fleetManagerClient, - httpClient: httpClient, + config: config, + fleetManagerPublicAPI: fleetManagerPublicAPI, + httpClient: httpClient, } } @@ -89,7 +89,7 @@ func (p *ProbeImpl) CleanUp(ctx context.Context) error { } func (p *ProbeImpl) cleanupFunc(ctx context.Context) error { - centralList, _, err := p.fleetManagerClient.GetCentrals(ctx, nil) + centralList, _, err := p.fleetManagerPublicAPI.GetCentrals(ctx, nil) if err != nil { err = errors.Wrap(err, "could not list centrals") glog.Error(err) @@ -127,7 +127,7 @@ func (p *ProbeImpl) createCentral(ctx context.Context) (*public.CentralRequest, CloudProvider: p.config.DataCloudProvider, Region: p.config.DataPlaneRegion, } - central, _, err := p.fleetManagerClient.CreateCentral(ctx, true, request) + central, _, err := p.fleetManagerPublicAPI.CreateCentral(ctx, true, request) glog.Infof("creation of central instance requested") if err != nil { return nil, errors.Wrap(err, "creation of central instance failed") @@ -155,7 +155,7 @@ func (p *ProbeImpl) verifyCentral(ctx context.Context, centralRequest *public.Ce // Delete the Central instance and verify that it transitioned to 'deprovision' state. func (p *ProbeImpl) deleteCentral(ctx context.Context, centralRequest *public.CentralRequest) error { - _, err := p.fleetManagerClient.DeleteCentralById(ctx, centralRequest.Id, true) + _, err := p.fleetManagerPublicAPI.DeleteCentralById(ctx, centralRequest.Id, true) glog.Infof("deletion of central instance %s requested", centralRequest.Id) if err != nil { return errors.Wrapf(err, "deletion of central instance %s failed", centralRequest.Id) @@ -180,7 +180,7 @@ func (p *ProbeImpl) ensureCentralState(ctx context.Context, centralRequest *publ } func (p *ProbeImpl) ensureStateFunc(ctx context.Context, centralRequest *public.CentralRequest, targetState string) (*public.CentralRequest, error) { - centralResp, _, err := p.fleetManagerClient.GetCentralById(ctx, centralRequest.Id) + centralResp, _, err := p.fleetManagerPublicAPI.GetCentralById(ctx, centralRequest.Id) if err != nil { err = errors.Wrapf(err, "central instance %s not reachable", centralRequest.Id) glog.Error(err) @@ -208,7 +208,7 @@ func (p *ProbeImpl) ensureCentralDeleted(ctx context.Context, centralRequest *pu } func (p *ProbeImpl) ensureDeletedFunc(ctx context.Context, centralRequest *public.CentralRequest) error { - _, response, err := p.fleetManagerClient.GetCentralById(ctx, centralRequest.Id) + _, response, err := p.fleetManagerPublicAPI.GetCentralById(ctx, centralRequest.Id) if err != nil { if response != nil && response.StatusCode == http.StatusNotFound { glog.Infof("central instance %s has been deleted", centralRequest.Id) diff --git a/probe/pkg/probe/probe_test.go b/probe/pkg/probe/probe_test.go index 6738461f60..7a9ef9ae3f 100644 --- a/probe/pkg/probe/probe_test.go +++ b/probe/pkg/probe/probe_test.go @@ -47,15 +47,15 @@ func newHTTPClientMock(fn httputil.RoundTripperFunc) *http.Client { func TestCreateCentral(t *testing.T) { tt := []struct { - testName string - wantErr bool - errType *error - mockFMClient *fleetmanager.PublicClientMock + testName string + wantErr bool + errType *error + mockFMAPI *fleetmanager.PublicAPIMock }{ { testName: "create central happy path", wantErr: false, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ CreateCentralFunc: func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { central := public.CentralRequest{ Status: constants.CentralRequestStatusAccepted.String(), @@ -75,7 +75,7 @@ func TestCreateCentral(t *testing.T) { { testName: "create central fails on internal server error", wantErr: true, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ CreateCentralFunc: func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { central := public.CentralRequest{} err := errors.Errorf("%d", http.StatusInternalServerError) @@ -87,7 +87,7 @@ func TestCreateCentral(t *testing.T) { testName: "central not ready on internal server error", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ CreateCentralFunc: func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { central := public.CentralRequest{ Id: "id-42", @@ -108,7 +108,7 @@ func TestCreateCentral(t *testing.T) { testName: "create central times out", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ CreateCentralFunc: func(ctx context.Context, async bool, request public.CentralRequestPayload) (public.CentralRequest, *http.Response, error) { concurrency.WaitWithTimeout(ctx, 2*testConfig.ProbeRunTimeout) return public.CentralRequest{}, nil, ctx.Err() @@ -119,7 +119,7 @@ func TestCreateCentral(t *testing.T) { for _, tc := range tt { t.Run(tc.testName, func(t *testing.T) { - probe := New(testConfig, tc.mockFMClient, nil) + probe := New(testConfig, tc.mockFMAPI, nil) ctx, cancel := context.WithTimeout(context.TODO(), testConfig.ProbeRunTimeout) defer cancel() @@ -208,12 +208,12 @@ func TestDeleteCentral(t *testing.T) { testName string wantErr bool errType *error - mockFMClient *fleetmanager.PublicClientMock + mockFMClient *fleetmanager.PublicAPIMock }{ { testName: "delete central happy path", wantErr: false, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMClient: &fleetmanager.PublicAPIMock{ DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { return nil, nil }, @@ -238,7 +238,7 @@ func TestDeleteCentral(t *testing.T) { { testName: "delete central fails on internal server error", wantErr: true, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMClient: &fleetmanager.PublicAPIMock{ DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { err := errors.Errorf("%d", http.StatusInternalServerError) return nil, err @@ -249,7 +249,7 @@ func TestDeleteCentral(t *testing.T) { testName: "central not deprovision on internal server error", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMClient: &fleetmanager.PublicAPIMock{ DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { return nil, nil }, @@ -264,7 +264,7 @@ func TestDeleteCentral(t *testing.T) { testName: "central not deleted if no 404 response", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMClient: &fleetmanager.PublicAPIMock{ DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { return nil, nil }, @@ -291,7 +291,7 @@ func TestDeleteCentral(t *testing.T) { testName: "delete central times out", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMClient: &fleetmanager.PublicAPIMock{ DeleteCentralByIdFunc: func(ctx context.Context, id string, async bool) (*http.Response, error) { concurrency.WaitWithTimeout(ctx, 2*testConfig.ProbeRunTimeout) return nil, ctx.Err() @@ -334,13 +334,13 @@ func TestCleanUp(t *testing.T) { wantErr bool errType *error numDeleteCalled int - mockFMClient *fleetmanager.PublicClientMock + mockFMAPI *fleetmanager.PublicAPIMock }{ { testName: "clean up happy path", wantErr: false, numDeleteCalled: 1, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ GetCentralsFunc: func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { centralItems := []public.CentralRequest{ { @@ -377,7 +377,7 @@ func TestCleanUp(t *testing.T) { { testName: "nothing to clean up", wantErr: false, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ GetCentralsFunc: func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { centralItems := []public.CentralRequest{ { @@ -400,7 +400,7 @@ func TestCleanUp(t *testing.T) { testName: "clean up fails on internal server error", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ GetCentralsFunc: func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { centralList := public.CentralRequestList{} err := errors.Errorf("%d", http.StatusInternalServerError) @@ -412,7 +412,7 @@ func TestCleanUp(t *testing.T) { testName: "clean up central times out", wantErr: true, errType: &context.DeadlineExceeded, - mockFMClient: &fleetmanager.PublicClientMock{ + mockFMAPI: &fleetmanager.PublicAPIMock{ GetCentralsFunc: func(ctx context.Context, localVarOptionals *public.GetCentralsOpts) (public.CentralRequestList, *http.Response, error) { concurrency.WaitWithTimeout(ctx, 2*testConfig.ProbeCleanUpTimeout) return public.CentralRequestList{}, nil, ctx.Err() @@ -423,7 +423,7 @@ func TestCleanUp(t *testing.T) { for _, tc := range tt { t.Run(tc.testName, func(t *testing.T) { - probe := New(testConfig, tc.mockFMClient, nil) + probe := New(testConfig, tc.mockFMAPI, nil) ctx, cancel := context.WithTimeout(context.TODO(), testConfig.ProbeRunTimeout) defer cancel() @@ -436,7 +436,7 @@ func TestCleanUp(t *testing.T) { } } else { assert.NoError(t, err, "failed to delete central") - assert.Equal(t, tc.numDeleteCalled, len(tc.mockFMClient.DeleteCentralByIdCalls())) + assert.Equal(t, tc.numDeleteCalled, len(tc.mockFMAPI.DeleteCentralByIdCalls())) } }) }