From 376516a0e7fb49141e7ccb33b00628ae24fa8206 Mon Sep 17 00:00:00 2001 From: oskarw Date: Thu, 5 Dec 2024 16:34:37 +0200 Subject: [PATCH] WIRE-838 - More tests --- castai/resource_organization_group.go | 47 +- castai/resource_organization_group_test.go | 614 ++++++++++++++++++--- castai/sdk/api.gen.go | 47 -- castai/sdk/client.gen.go | 161 ------ castai/sdk/mock/client.go | 70 --- 5 files changed, 596 insertions(+), 343 deletions(-) diff --git a/castai/resource_organization_group.go b/castai/resource_organization_group.go index 1030d5b9..6909861d 100644 --- a/castai/resource_organization_group.go +++ b/castai/resource_organization_group.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "strings" "time" @@ -105,6 +106,13 @@ func resourceOrganizationGroup() *schema.Resource { func resourceOrganizationGroupCreate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { organizationID := data.Get(FieldOrganizationGroupOrganizationID).(string) + if organizationID == "" { + var err error + organizationID, err = getDefaultOrganizationId(ctx, meta) + if err != nil { + return diag.FromErr(fmt.Errorf("getting default organization: %w", err)) + } + } client := meta.(*ProviderConfig).api @@ -128,6 +136,11 @@ func resourceOrganizationGroupCreate(ctx context.Context, data *schema.ResourceD } func resourceOrganizationGroupRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { + groupID := data.Id() + if groupID == "" { + return diag.Errorf("group ID is not set") + } + organizationID := data.Get(FieldOrganizationGroupOrganizationID).(string) if organizationID == "" { var err error @@ -136,7 +149,6 @@ func resourceOrganizationGroupRead(ctx context.Context, data *schema.ResourceDat return diag.FromErr(fmt.Errorf("getting default organization: %w", err)) } } - groupID := data.Id() client := meta.(*ProviderConfig).api @@ -153,8 +165,19 @@ func resourceOrganizationGroupRead(ctx context.Context, data *schema.ResourceDat } func resourceOrganizationGroupUpdate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - organizationID := data.Get(FieldOrganizationGroupOrganizationID).(string) groupID := data.Id() + if groupID == "" { + return diag.Errorf("group ID is not set") + } + + organizationID := data.Get(FieldOrganizationGroupOrganizationID).(string) + if organizationID == "" { + var err error + organizationID, err = getDefaultOrganizationId(ctx, meta) + if err != nil { + return diag.FromErr(fmt.Errorf("getting default organization: %w", err)) + } + } client := meta.(*ProviderConfig).api @@ -175,8 +198,19 @@ func resourceOrganizationGroupUpdate(ctx context.Context, data *schema.ResourceD } func resourceOrganizationGroupDelete(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics { - organizationID := data.Get(FieldOrganizationGroupOrganizationID).(string) groupID := data.Id() + if groupID == "" { + return diag.Errorf("group ID is not set") + } + + organizationID := data.Get(FieldOrganizationGroupOrganizationID).(string) + if organizationID == "" { + var err error + organizationID, err = getDefaultOrganizationId(ctx, meta) + if err != nil { + return diag.FromErr(fmt.Errorf("getting default organization: %w", err)) + } + } client := meta.(*ProviderConfig).api @@ -190,6 +224,13 @@ func resourceOrganizationGroupDelete(ctx context.Context, data *schema.ResourceD func getGroup(client *sdk.ClientWithResponses, ctx context.Context, organizationID, groupID string) (*sdk.CastaiRbacV1beta1Group, error) { groupsResp, err := client.RbacServiceAPIGetGroupWithResponse(ctx, organizationID, groupID) + if err != nil { + return nil, fmt.Errorf("fetching group: %w", err) + } + + if groupsResp.StatusCode() == http.StatusNotFound { + return nil, fmt.Errorf("group %s not found", groupID) + } if err := sdk.CheckOKResponse(groupsResp, err); err != nil { return nil, fmt.Errorf("retrieving group: %w", err) } diff --git a/castai/resource_organization_group_test.go b/castai/resource_organization_group_test.go index a5f601c4..9da043bc 100644 --- a/castai/resource_organization_group_test.go +++ b/castai/resource_organization_group_test.go @@ -3,13 +3,17 @@ package castai import ( "bytes" "context" + "encoding/json" + "errors" "io" "net/http" "testing" "github.com/golang/mock/gomock" + "github.com/google/uuid" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/samber/lo" "github.com/stretchr/testify/require" "github.com/castai/terraform-provider-castai/castai/sdk" @@ -19,87 +23,217 @@ import ( func TestOrganizationGroupReadContext(t *testing.T) { t.Parallel() - r := require.New(t) - mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + t.Run("when state is missing group ID then return error", func(t *testing.T) { + r := require.New(t) - ctx := context.Background() - provider := &ProviderConfig{ - api: &sdk.ClientWithResponses{ - ClientInterface: mockClient, - }, - } + ctx := context.Background() + provider := &ProviderConfig{} - organizationID := "b6bfc024-a267-400f-b8f1-db0850c369b2" - groupID := "e9a3f787-15d4-4850-ae7c-b4864809aa54" + stateValue := cty.ObjectVal(map[string]cty.Value{}) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) - body := io.NopCloser(bytes.NewReader([]byte(`{ - "id": "e9a3f787-15d4-4850-ae7c-b4864809aa54", - "organizationId": "b6bfc024-a267-400f-b8f1-db0850c369b2", + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.ReadContext(ctx, data, provider) + + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Equal("group ID is not set", result[0].Summary) + }) + + t.Run("when ServiceAccountAPI respond with 404 then return error", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + body := io.NopCloser(bytes.NewReader([]byte(""))) + + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(&http.Response{StatusCode: http.StatusNotFound, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.ReadContext(ctx, data, provider) + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Equal("getting group for read: group "+groupID+" not found", result[0].Summary) + }) + + t.Run("when ServiceAccountAPI respond with 500 then return error", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + body := io.NopCloser(bytes.NewReader([]byte("internal error"))) + + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(&http.Response{StatusCode: http.StatusInternalServerError, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.ReadContext(ctx, data, provider) + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Equal("getting group for read: retrieving group: expected status code 200, received: status=500 body=internal error", result[0].Summary) + }) + + t.Run("when calling ServiceAccountAPI throws error then return error", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(nil, errors.New("unexpected error")) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.ReadContext(ctx, data, provider) + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Equal("getting group for read: fetching group: unexpected error", result[0].Summary) + }) + + t.Run("when RbacServiceAPI respond with 200 then populate the state", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + firstUserID := uuid.NewString() + secondUserID := uuid.NewString() + + body := io.NopCloser(bytes.NewReader([]byte(`{ + "id": "` + groupID + `", + "organizationId": "` + organizationID + `", "name": "test group", "description": "test group description", "definition": { "members": [ { - "id": "5d832285-c263-4d27-9ba5-7d8cf5759782", + "id": "` + firstUserID + `", "email": "test-user-1@test.com" }, { - "id": "5d832285-c263-4d27-9ba5-7d8cf5759783", + "id": "` + secondUserID + `", "email": "test-user-2@test.com" } ] } }`))) - mockClient.EXPECT(). - RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). - Return(&http.Response{StatusCode: 200, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(&http.Response{StatusCode: http.StatusOK, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) - stateValue := cty.ObjectVal(map[string]cty.Value{ - "organization_id": cty.StringVal(organizationID), - }) - state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) - state.ID = groupID + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID - resource := resourceOrganizationGroup() - data := resource.Data(state) + resource := resourceOrganizationGroup() + data := resource.Data(state) - result := resource.ReadContext(ctx, data, provider) - r.Nil(result) - r.False(result.HasError()) - r.Equal(`ID = e9a3f787-15d4-4850-ae7c-b4864809aa54 + result := resource.ReadContext(ctx, data, provider) + r.Nil(result) + r.False(result.HasError()) + r.Equal(`ID = `+groupID+` description = test group description members.# = 1 members.0.member.# = 2 members.0.member.0.email = test-user-1@test.com -members.0.member.0.id = 5d832285-c263-4d27-9ba5-7d8cf5759782 +members.0.member.0.id = `+firstUserID+` members.0.member.0.kind = members.0.member.1.email = test-user-2@test.com -members.0.member.1.id = 5d832285-c263-4d27-9ba5-7d8cf5759783 +members.0.member.1.id = `+secondUserID+` members.0.member.1.kind = name = test group -organization_id = b6bfc024-a267-400f-b8f1-db0850c369b2 +organization_id = `+organizationID+` Tainted = false `, data.State().String()) -} + }) -func TestOrganizationGroupReadContext_WithoutOrganizationInDefinition(t *testing.T) { - t.Parallel() + t.Run("when organization is not defined, use default one for the token", func(t *testing.T) { + t.Parallel() - r := require.New(t) - mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) - ctx := context.Background() - provider := &ProviderConfig{ - api: &sdk.ClientWithResponses{ - ClientInterface: mockClient, - }, - } + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } - organizationID := "b6bfc024-a267-400f-b8f1-db0850c369b4" - groupID := "e9a3f787-15d4-4850-ae7c-b4864809aa55" + organizationID := "b6bfc024-a267-400f-b8f1-db0850c369b4" + groupID := "e9a3f787-15d4-4850-ae7c-b4864809aa55" - organizationsBody := io.NopCloser(bytes.NewReader([]byte(`{ + organizationsBody := io.NopCloser(bytes.NewReader([]byte(`{ "organizations": [ { "id": "b6bfc024-a267-400f-b8f1-db0850c369b4", @@ -110,11 +244,11 @@ func TestOrganizationGroupReadContext_WithoutOrganizationInDefinition(t *testing ] }`))) - mockClient.EXPECT(). - UsersAPIListOrganizations(gomock.Any(), gomock.Any()). - Return(&http.Response{StatusCode: 200, Body: organizationsBody, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + mockClient.EXPECT(). + UsersAPIListOrganizations(gomock.Any(), gomock.Any()). + Return(&http.Response{StatusCode: http.StatusOK, Body: organizationsBody, Header: map[string][]string{"Content-Type": {"json"}}}, nil) - body := io.NopCloser(bytes.NewReader([]byte(`{ + body := io.NopCloser(bytes.NewReader([]byte(`{ "id": "e9a3f787-15d4-4850-ae7c-b4864809aa55", "organizationId": "b6bfc024-a267-400f-b8f1-db0850c369b4", "name": "test group", @@ -133,21 +267,21 @@ func TestOrganizationGroupReadContext_WithoutOrganizationInDefinition(t *testing } }`))) - mockClient.EXPECT(). - RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). - Return(&http.Response{StatusCode: 200, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(&http.Response{StatusCode: http.StatusOK, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) - stateValue := cty.ObjectVal(map[string]cty.Value{}) - state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) - state.ID = groupID + stateValue := cty.ObjectVal(map[string]cty.Value{}) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID - resource := resourceOrganizationGroup() - data := resource.Data(state) + resource := resourceOrganizationGroup() + data := resource.Data(state) - result := resource.ReadContext(ctx, data, provider) - r.Nil(result) - r.False(result.HasError()) - r.Equal(`ID = e9a3f787-15d4-4850-ae7c-b4864809aa55 + result := resource.ReadContext(ctx, data, provider) + r.Nil(result) + r.False(result.HasError()) + r.Equal(`ID = e9a3f787-15d4-4850-ae7c-b4864809aa55 description = test group description members.# = 1 members.0.member.# = 2 @@ -161,4 +295,360 @@ name = test group organization_id = b6bfc024-a267-400f-b8f1-db0850c369b4 Tainted = false `, data.State().String()) + }) + +} + +func TestOrganizationGroupUpdateContext(t *testing.T) { + t.Parallel() + + t.Run("when state is missing group ID then return error", func(t *testing.T) { + r := require.New(t) + + ctx := context.Background() + provider := &ProviderConfig{} + + stateValue := cty.ObjectVal(map[string]cty.Value{}) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.UpdateContext(ctx, data, provider) + + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Equal("group ID is not set", result[0].Summary) + }) + + t.Run("when RbacServiceAPI UpdateGroup respond with 500 then throw error", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + mockClient.EXPECT(). + RbacServiceAPIUpdateGroup(gomock.Any(), organizationID, groupID, gomock.Any()). + DoAndReturn(func(ctx context.Context, reqOrgID string, reqGroupID string, req sdk.RbacServiceAPIUpdateGroupJSONRequestBody) (*http.Response, error) { + r.Equal(organizationID, reqOrgID) + r.Equal(groupID, reqGroupID) + + body := &bytes.Buffer{} + err := json.NewEncoder(body).Encode(&sdk.CastaiRbacV1beta1Group{}) + r.NoError(err) + return &http.Response{StatusCode: http.StatusInternalServerError, Body: io.NopCloser(body), Header: map[string][]string{"Content-Type": {"json"}}}, nil + }) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.UpdateContext(ctx, data, provider) + + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Contains(result[0].Summary, "update group: expected status code 200, received: status=500") + }) + + t.Run("when RbacServiceAPI UpdateGroup respond with 200 then no errors", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + firstUserID := uuid.NewString() + secondUserID := uuid.NewString() + + body := io.NopCloser(bytes.NewReader([]byte(`{ + "id": "` + groupID + `", + "organizationId": "` + organizationID + `", + "name": "test group", + "description": "test group description changed", + "definition": { + "members": [ + { + "id": "` + firstUserID + `", + "email": "test-user-1@test.com" + }, + { + "id": "` + secondUserID + `", + "email": "test-user-2@test.com" + } + ] + } + }`))) + + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(&http.Response{StatusCode: http.StatusOK, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + + mockClient.EXPECT(). + RbacServiceAPIUpdateGroup(gomock.Any(), organizationID, groupID, gomock.Any()). + DoAndReturn(func(ctx context.Context, reqOrgID string, reqGroupID string, req sdk.RbacServiceAPIUpdateGroupJSONRequestBody) (*http.Response, error) { + r.Equal(organizationID, reqOrgID) + r.Equal(groupID, reqGroupID) + + body := &bytes.Buffer{} + err := json.NewEncoder(body).Encode(&sdk.CastaiRbacV1beta1Group{}) + r.NoError(err) + return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(body), Header: map[string][]string{"Content-Type": {"json"}}}, nil + }) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.UpdateContext(ctx, data, provider) + + r.Nil(result) + r.False(result.HasError()) + }) +} + +func TestOrganizationGroupCreateContext(t *testing.T) { + t.Parallel() + + t.Run("when RbacServiceAPI CreateGroup respond with 500 then throw error", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + + mockClient.EXPECT(). + RbacServiceAPICreateGroup(gomock.Any(), organizationID, gomock.Any()). + DoAndReturn(func(ctx context.Context, reqOrgID string, req sdk.RbacServiceAPICreateGroupJSONRequestBody) (*http.Response, error) { + r.Equal(organizationID, reqOrgID) + + body := &bytes.Buffer{} + err := json.NewEncoder(body).Encode(&sdk.CastaiRbacV1beta1Group{}) + r.NoError(err) + return &http.Response{StatusCode: http.StatusInternalServerError, Body: io.NopCloser(body), Header: map[string][]string{"Content-Type": {"json"}}}, nil + }) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.CreateContext(ctx, data, provider) + + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Contains(result[0].Summary, "create group: expected status code 200, received: status=500") + }) + + t.Run("when RbacServiceAPI CreateGroup respond with 200 then assume group was created", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + firstUserID := uuid.NewString() + secondUserID := uuid.NewString() + + body := io.NopCloser(bytes.NewReader([]byte(`{ + "id": "` + groupID + `", + "organizationId": "` + organizationID + `", + "name": "test group", + "description": "test group description changed", + "definition": { + "members": [ + { + "id": "` + firstUserID + `", + "email": "test-user-1@test.com" + }, + { + "id": "` + secondUserID + `", + "email": "test-user-2@test.com" + } + ] + } + }`))) + + mockClient.EXPECT(). + RbacServiceAPIGetGroup(gomock.Any(), organizationID, groupID). + Return(&http.Response{StatusCode: http.StatusOK, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil) + + mockClient.EXPECT(). + RbacServiceAPICreateGroup(gomock.Any(), organizationID, gomock.Any()). + DoAndReturn(func(ctx context.Context, reqOrgID string, req sdk.RbacServiceAPICreateGroupJSONRequestBody) (*http.Response, error) { + r.Equal(organizationID, reqOrgID) + + body := bytes.NewBuffer([]byte("")) + err := json.NewEncoder(body).Encode(&sdk.CastaiRbacV1beta1Group{ + Id: lo.ToPtr(groupID), + }) + r.NoError(err) + return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(body), Header: map[string][]string{"Content-Type": {"json"}}}, nil + }) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.CreateContext(ctx, data, provider) + + r.Nil(result) + r.False(result.HasError()) + }) +} + +func TestOrganizationGroupDeleteContext(t *testing.T) { + t.Parallel() + + t.Run("when state is missing group ID then return error", func(t *testing.T) { + r := require.New(t) + + ctx := context.Background() + provider := &ProviderConfig{} + + stateValue := cty.ObjectVal(map[string]cty.Value{}) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.DeleteContext(ctx, data, provider) + + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Equal("group ID is not set", result[0].Summary) + }) + + t.Run("when RbacServiceAPI DeleteGroup respond with 500 then throw error", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + mockClient.EXPECT(). + RbacServiceAPIDeleteGroup(gomock.Any(), organizationID, groupID, gomock.Any()). + DoAndReturn(func(ctx context.Context, reqOrgID string, reqGroupID string) (*http.Response, error) { + r.Equal(organizationID, reqOrgID) + r.Equal(groupID, reqGroupID) + + body := &bytes.Buffer{} + err := json.NewEncoder(body).Encode(&sdk.CastaiRbacV1beta1Group{}) + r.NoError(err) + return &http.Response{StatusCode: http.StatusInternalServerError, Body: io.NopCloser(body), Header: map[string][]string{"Content-Type": {"json"}}}, nil + }) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.DeleteContext(ctx, data, provider) + + r.NotNil(result) + r.True(result.HasError()) + r.Len(result, 1) + r.Contains(result[0].Summary, "destroy group: expected status code 200, received: status=500") + }) + + t.Run("when RbacServiceAPI DeleteGroup respond with 200 then no errors", func(t *testing.T) { + r := require.New(t) + mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) + + ctx := context.Background() + provider := &ProviderConfig{ + api: &sdk.ClientWithResponses{ + ClientInterface: mockClient, + }, + } + + organizationID := uuid.NewString() + groupID := uuid.NewString() + + mockClient.EXPECT(). + RbacServiceAPIDeleteGroup(gomock.Any(), organizationID, groupID, gomock.Any()). + DoAndReturn(func(ctx context.Context, reqOrgID string, reqGroupID string) (*http.Response, error) { + r.Equal(organizationID, reqOrgID) + r.Equal(groupID, reqGroupID) + + body := &bytes.Buffer{} + err := json.NewEncoder(body).Encode(&sdk.CastaiRbacV1beta1Group{}) + r.NoError(err) + return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(body), Header: map[string][]string{"Content-Type": {"json"}}}, nil + }) + + stateValue := cty.ObjectVal(map[string]cty.Value{ + "organization_id": cty.StringVal(organizationID), + }) + state := terraform.NewInstanceStateShimmedFromValue(stateValue, 0) + state.ID = groupID + + resource := resourceOrganizationGroup() + data := resource.Data(state) + + result := resource.DeleteContext(ctx, data, provider) + + r.Nil(result) + r.False(result.HasError()) + }) } diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index 253a118a..07076e1f 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -4250,18 +4250,6 @@ type WorkloadoptimizationV1TimeSeriesMetric struct { Value float64 `json:"value"` } -// WorkloadoptimizationV1UpdateWorkload defines model for workloadoptimization.v1.UpdateWorkload. -type WorkloadoptimizationV1UpdateWorkload struct { - // Defines the scaling policy ID assigned to the workload. - ScalingPolicyId string `json:"scalingPolicyId"` - WorkloadConfig *WorkloadoptimizationV1WorkloadConfigUpdate `json:"workloadConfig,omitempty"` -} - -// WorkloadoptimizationV1UpdateWorkloadResponse defines model for workloadoptimization.v1.UpdateWorkloadResponse. -type WorkloadoptimizationV1UpdateWorkloadResponse struct { - Workload *WorkloadoptimizationV1Workload `json:"workload,omitempty"` -} - // WorkloadoptimizationV1UpdateWorkloadResponseV2 defines model for workloadoptimization.v1.UpdateWorkloadResponseV2. type WorkloadoptimizationV1UpdateWorkloadResponseV2 struct { Workload *WorkloadoptimizationV1Workload `json:"workload,omitempty"` @@ -4356,38 +4344,9 @@ type WorkloadoptimizationV1Workload struct { ScalingPolicyId string `json:"scalingPolicyId"` UpdatedAt time.Time `json:"updatedAt"` Version string `json:"version"` - WorkloadConfig WorkloadoptimizationV1WorkloadConfig `json:"workloadConfig"` WorkloadConfigV2 WorkloadoptimizationV1WorkloadConfigV2 `json:"workloadConfigV2"` } -// WorkloadoptimizationV1WorkloadConfig defines model for workloadoptimization.v1.WorkloadConfig. -type WorkloadoptimizationV1WorkloadConfig struct { - AntiAffinity WorkloadoptimizationV1AntiAffinitySettings `json:"antiAffinity"` - ContainerConstraints []WorkloadoptimizationV1ContainerConstraints `json:"containerConstraints"` - Cpu WorkloadoptimizationV1ResourceConfig `json:"cpu"` - - // Defines possible options for workload management. - // READ_ONLY - workload watched (metrics collected), but no actions may be performed by CAST AI. - // MANAGED - workload watched (metrics collected), CAST AI may perform actions on the workload. - ManagementOption WorkloadoptimizationV1ManagementOption `json:"managementOption"` - Memory WorkloadoptimizationV1ResourceConfig `json:"memory"` - MemoryEvent *WorkloadoptimizationV1MemoryEventSettings `json:"memoryEvent,omitempty"` -} - -// WorkloadoptimizationV1WorkloadConfigUpdate defines model for workloadoptimization.v1.WorkloadConfigUpdate. -type WorkloadoptimizationV1WorkloadConfigUpdate struct { - AntiAffinity *WorkloadoptimizationV1AntiAffinitySettings `json:"antiAffinity,omitempty"` - ContainerConfig *[]WorkloadoptimizationV1ContainerConfigUpdate `json:"containerConfig,omitempty"` - Cpu *WorkloadoptimizationV1WorkloadResourceConfigUpdate `json:"cpu,omitempty"` - - // Defines possible options for workload management. - // READ_ONLY - workload watched (metrics collected), but no actions may be performed by CAST AI. - // MANAGED - workload watched (metrics collected), CAST AI may perform actions on the workload. - ManagementOption *WorkloadoptimizationV1ManagementOption `json:"managementOption,omitempty"` - Memory *WorkloadoptimizationV1WorkloadResourceConfigUpdate `json:"memory,omitempty"` - MemoryEvent *WorkloadoptimizationV1MemoryEventSettings `json:"memoryEvent,omitempty"` -} - // WorkloadoptimizationV1WorkloadConfigUpdateV2 defines model for workloadoptimization.v1.WorkloadConfigUpdateV2. type WorkloadoptimizationV1WorkloadConfigUpdateV2 struct { HpaConfig *WorkloadoptimizationV1HPAConfigUpdate `json:"hpaConfig,omitempty"` @@ -4849,9 +4808,6 @@ type WorkloadOptimizationAPIGetWorkloadParams struct { ToTime *time.Time `form:"toTime,omitempty" json:"toTime,omitempty"` } -// WorkloadOptimizationAPIUpdateWorkloadJSONBody defines parameters for WorkloadOptimizationAPIUpdateWorkload. -type WorkloadOptimizationAPIUpdateWorkloadJSONBody = WorkloadoptimizationV1UpdateWorkload - // WorkloadOptimizationAPIGetInstallCmdParams defines parameters for WorkloadOptimizationAPIGetInstallCmd. type WorkloadOptimizationAPIGetInstallCmdParams struct { ClusterId string `form:"clusterId" json:"clusterId"` @@ -5007,9 +4963,6 @@ type WorkloadOptimizationAPIUpdateWorkloadScalingPolicyJSONRequestBody = Workloa // WorkloadOptimizationAPIAssignScalingPolicyWorkloadsJSONRequestBody defines body for WorkloadOptimizationAPIAssignScalingPolicyWorkloads for application/json ContentType. type WorkloadOptimizationAPIAssignScalingPolicyWorkloadsJSONRequestBody = WorkloadOptimizationAPIAssignScalingPolicyWorkloadsJSONBody -// WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody defines body for WorkloadOptimizationAPIUpdateWorkload for application/json ContentType. -type WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody = WorkloadOptimizationAPIUpdateWorkloadJSONBody - // WorkloadOptimizationAPIUpdateWorkloadV2JSONRequestBody defines body for WorkloadOptimizationAPIUpdateWorkloadV2 for application/json ContentType. type WorkloadOptimizationAPIUpdateWorkloadV2JSONRequestBody = WorkloadOptimizationAPIUpdateWorkloadV2JSONBody diff --git a/castai/sdk/client.gen.go b/castai/sdk/client.gen.go index 38ec8694..d0b70865 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -580,11 +580,6 @@ type ClientInterface interface { // WorkloadOptimizationAPIGetWorkload request WorkloadOptimizationAPIGetWorkload(ctx context.Context, clusterId string, workloadId string, params *WorkloadOptimizationAPIGetWorkloadParams, reqEditors ...RequestEditorFn) (*http.Response, error) - // WorkloadOptimizationAPIUpdateWorkload request with any body - WorkloadOptimizationAPIUpdateWorkloadWithBody(ctx context.Context, clusterId string, workloadId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - - WorkloadOptimizationAPIUpdateWorkload(ctx context.Context, clusterId string, workloadId string, body WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - // WorkloadOptimizationAPIGetInstallCmd request WorkloadOptimizationAPIGetInstallCmd(ctx context.Context, params *WorkloadOptimizationAPIGetInstallCmdParams, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -2748,30 +2743,6 @@ func (c *Client) WorkloadOptimizationAPIGetWorkload(ctx context.Context, cluster return c.Client.Do(req) } -func (c *Client) WorkloadOptimizationAPIUpdateWorkloadWithBody(ctx context.Context, clusterId string, workloadId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewWorkloadOptimizationAPIUpdateWorkloadRequestWithBody(c.Server, clusterId, workloadId, contentType, body) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - -func (c *Client) WorkloadOptimizationAPIUpdateWorkload(ctx context.Context, clusterId string, workloadId string, body WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewWorkloadOptimizationAPIUpdateWorkloadRequest(c.Server, clusterId, workloadId, body) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - func (c *Client) WorkloadOptimizationAPIGetInstallCmd(ctx context.Context, params *WorkloadOptimizationAPIGetInstallCmdParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewWorkloadOptimizationAPIGetInstallCmdRequest(c.Server, params) if err != nil { @@ -8991,60 +8962,6 @@ func NewWorkloadOptimizationAPIGetWorkloadRequest(server string, clusterId strin return req, nil } -// NewWorkloadOptimizationAPIUpdateWorkloadRequest calls the generic WorkloadOptimizationAPIUpdateWorkload builder with application/json body -func NewWorkloadOptimizationAPIUpdateWorkloadRequest(server string, clusterId string, workloadId string, body WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody) (*http.Request, error) { - var bodyReader io.Reader - buf, err := json.Marshal(body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - return NewWorkloadOptimizationAPIUpdateWorkloadRequestWithBody(server, clusterId, workloadId, "application/json", bodyReader) -} - -// NewWorkloadOptimizationAPIUpdateWorkloadRequestWithBody generates requests for WorkloadOptimizationAPIUpdateWorkload with any type of body -func NewWorkloadOptimizationAPIUpdateWorkloadRequestWithBody(server string, clusterId string, workloadId string, contentType string, body io.Reader) (*http.Request, error) { - var err error - - var pathParam0 string - - pathParam0, err = runtime.StyleParamWithLocation("simple", false, "clusterId", runtime.ParamLocationPath, clusterId) - if err != nil { - return nil, err - } - - var pathParam1 string - - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "workloadId", runtime.ParamLocationPath, workloadId) - if err != nil { - return nil, err - } - - serverURL, err := url.Parse(server) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("/v1/workload-autoscaling/clusters/%s/workloads/%s", pathParam0, pathParam1) - if operationPath[0] == '/' { - operationPath = "." + operationPath - } - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("PUT", queryURL.String(), body) - if err != nil { - return nil, err - } - - req.Header.Add("Content-Type", contentType) - - return req, nil -} - // NewWorkloadOptimizationAPIGetInstallCmdRequest generates requests for WorkloadOptimizationAPIGetInstallCmd func NewWorkloadOptimizationAPIGetInstallCmdRequest(server string, params *WorkloadOptimizationAPIGetInstallCmdParams) (*http.Request, error) { var err error @@ -9765,11 +9682,6 @@ type ClientWithResponsesInterface interface { // WorkloadOptimizationAPIGetWorkload request WorkloadOptimizationAPIGetWorkloadWithResponse(ctx context.Context, clusterId string, workloadId string, params *WorkloadOptimizationAPIGetWorkloadParams) (*WorkloadOptimizationAPIGetWorkloadResponse, error) - // WorkloadOptimizationAPIUpdateWorkload request with any body - WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse(ctx context.Context, clusterId string, workloadId string, contentType string, body io.Reader) (*WorkloadOptimizationAPIUpdateWorkloadResponse, error) - - WorkloadOptimizationAPIUpdateWorkloadWithResponse(ctx context.Context, clusterId string, workloadId string, body WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody) (*WorkloadOptimizationAPIUpdateWorkloadResponse, error) - // WorkloadOptimizationAPIGetInstallCmd request WorkloadOptimizationAPIGetInstallCmdWithResponse(ctx context.Context, params *WorkloadOptimizationAPIGetInstallCmdParams) (*WorkloadOptimizationAPIGetInstallCmdResponse, error) @@ -13750,36 +13662,6 @@ func (r WorkloadOptimizationAPIGetWorkloadResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 -type WorkloadOptimizationAPIUpdateWorkloadResponse struct { - Body []byte - HTTPResponse *http.Response - JSON200 *WorkloadoptimizationV1UpdateWorkloadResponse -} - -// Status returns HTTPResponse.Status -func (r WorkloadOptimizationAPIUpdateWorkloadResponse) Status() string { - if r.HTTPResponse != nil { - return r.HTTPResponse.Status - } - return http.StatusText(0) -} - -// StatusCode returns HTTPResponse.StatusCode -func (r WorkloadOptimizationAPIUpdateWorkloadResponse) StatusCode() int { - if r.HTTPResponse != nil { - return r.HTTPResponse.StatusCode - } - return 0 -} - -// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 -// Body returns body of byte array -func (r WorkloadOptimizationAPIUpdateWorkloadResponse) GetBody() []byte { - return r.Body -} - -// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 - type WorkloadOptimizationAPIGetInstallCmdResponse struct { Body []byte HTTPResponse *http.Response @@ -15463,23 +15345,6 @@ func (c *ClientWithResponses) WorkloadOptimizationAPIGetWorkloadWithResponse(ctx return ParseWorkloadOptimizationAPIGetWorkloadResponse(rsp) } -// WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse request with arbitrary body returning *WorkloadOptimizationAPIUpdateWorkloadResponse -func (c *ClientWithResponses) WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse(ctx context.Context, clusterId string, workloadId string, contentType string, body io.Reader) (*WorkloadOptimizationAPIUpdateWorkloadResponse, error) { - rsp, err := c.WorkloadOptimizationAPIUpdateWorkloadWithBody(ctx, clusterId, workloadId, contentType, body) - if err != nil { - return nil, err - } - return ParseWorkloadOptimizationAPIUpdateWorkloadResponse(rsp) -} - -func (c *ClientWithResponses) WorkloadOptimizationAPIUpdateWorkloadWithResponse(ctx context.Context, clusterId string, workloadId string, body WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody) (*WorkloadOptimizationAPIUpdateWorkloadResponse, error) { - rsp, err := c.WorkloadOptimizationAPIUpdateWorkload(ctx, clusterId, workloadId, body) - if err != nil { - return nil, err - } - return ParseWorkloadOptimizationAPIUpdateWorkloadResponse(rsp) -} - // WorkloadOptimizationAPIGetInstallCmdWithResponse request returning *WorkloadOptimizationAPIGetInstallCmdResponse func (c *ClientWithResponses) WorkloadOptimizationAPIGetInstallCmdWithResponse(ctx context.Context, params *WorkloadOptimizationAPIGetInstallCmdParams) (*WorkloadOptimizationAPIGetInstallCmdResponse, error) { rsp, err := c.WorkloadOptimizationAPIGetInstallCmd(ctx, params) @@ -18916,32 +18781,6 @@ func ParseWorkloadOptimizationAPIGetWorkloadResponse(rsp *http.Response) (*Workl return response, nil } -// ParseWorkloadOptimizationAPIUpdateWorkloadResponse parses an HTTP response from a WorkloadOptimizationAPIUpdateWorkloadWithResponse call -func ParseWorkloadOptimizationAPIUpdateWorkloadResponse(rsp *http.Response) (*WorkloadOptimizationAPIUpdateWorkloadResponse, error) { - bodyBytes, err := ioutil.ReadAll(rsp.Body) - defer rsp.Body.Close() - if err != nil { - return nil, err - } - - response := &WorkloadOptimizationAPIUpdateWorkloadResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest WorkloadoptimizationV1UpdateWorkloadResponse - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - } - - return response, nil -} - // ParseWorkloadOptimizationAPIGetInstallCmdResponse parses an HTTP response from a WorkloadOptimizationAPIGetInstallCmdWithResponse call func ParseWorkloadOptimizationAPIGetInstallCmdResponse(rsp *http.Response) (*WorkloadOptimizationAPIGetInstallCmdResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/castai/sdk/mock/client.go b/castai/sdk/mock/client.go index d15ec852..20f0e0d4 100644 --- a/castai/sdk/mock/client.go +++ b/castai/sdk/mock/client.go @@ -3675,26 +3675,6 @@ func (mr *MockClientInterfaceMockRecorder) WorkloadOptimizationAPIListWorkloads( return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIListWorkloads", reflect.TypeOf((*MockClientInterface)(nil).WorkloadOptimizationAPIListWorkloads), varargs...) } -// WorkloadOptimizationAPIUpdateWorkload mocks base method. -func (m *MockClientInterface) WorkloadOptimizationAPIUpdateWorkload(ctx context.Context, clusterId, workloadId string, body sdk.WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { - m.ctrl.T.Helper() - varargs := []interface{}{ctx, clusterId, workloadId, body} - for _, a := range reqEditors { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "WorkloadOptimizationAPIUpdateWorkload", varargs...) - ret0, _ := ret[0].(*http.Response) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WorkloadOptimizationAPIUpdateWorkload indicates an expected call of WorkloadOptimizationAPIUpdateWorkload. -func (mr *MockClientInterfaceMockRecorder) WorkloadOptimizationAPIUpdateWorkload(ctx, clusterId, workloadId, body interface{}, reqEditors ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, clusterId, workloadId, body}, reqEditors...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIUpdateWorkload", reflect.TypeOf((*MockClientInterface)(nil).WorkloadOptimizationAPIUpdateWorkload), varargs...) -} - // WorkloadOptimizationAPIUpdateWorkloadScalingPolicy mocks base method. func (m *MockClientInterface) WorkloadOptimizationAPIUpdateWorkloadScalingPolicy(ctx context.Context, clusterId, policyId string, body sdk.WorkloadOptimizationAPIUpdateWorkloadScalingPolicyJSONRequestBody, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() @@ -3775,26 +3755,6 @@ func (mr *MockClientInterfaceMockRecorder) WorkloadOptimizationAPIUpdateWorkload return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIUpdateWorkloadV2WithBody", reflect.TypeOf((*MockClientInterface)(nil).WorkloadOptimizationAPIUpdateWorkloadV2WithBody), varargs...) } -// WorkloadOptimizationAPIUpdateWorkloadWithBody mocks base method. -func (m *MockClientInterface) WorkloadOptimizationAPIUpdateWorkloadWithBody(ctx context.Context, clusterId, workloadId, contentType string, body io.Reader, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { - m.ctrl.T.Helper() - varargs := []interface{}{ctx, clusterId, workloadId, contentType, body} - for _, a := range reqEditors { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "WorkloadOptimizationAPIUpdateWorkloadWithBody", varargs...) - ret0, _ := ret[0].(*http.Response) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WorkloadOptimizationAPIUpdateWorkloadWithBody indicates an expected call of WorkloadOptimizationAPIUpdateWorkloadWithBody. -func (mr *MockClientInterfaceMockRecorder) WorkloadOptimizationAPIUpdateWorkloadWithBody(ctx, clusterId, workloadId, contentType, body interface{}, reqEditors ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx, clusterId, workloadId, contentType, body}, reqEditors...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIUpdateWorkloadWithBody", reflect.TypeOf((*MockClientInterface)(nil).WorkloadOptimizationAPIUpdateWorkloadWithBody), varargs...) -} - // MockClientWithResponsesInterface is a mock of ClientWithResponsesInterface interface. type MockClientWithResponsesInterface struct { ctrl *gomock.Controller @@ -6578,36 +6538,6 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) WorkloadOptimizationAPIU return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIUpdateWorkloadV2WithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).WorkloadOptimizationAPIUpdateWorkloadV2WithResponse), ctx, clusterId, workloadId, body) } -// WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse(ctx context.Context, clusterId, workloadId, contentType string, body io.Reader) (*sdk.WorkloadOptimizationAPIUpdateWorkloadResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse", ctx, clusterId, workloadId, contentType, body) - ret0, _ := ret[0].(*sdk.WorkloadOptimizationAPIUpdateWorkloadResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse indicates an expected call of WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse(ctx, clusterId, workloadId, contentType, body interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).WorkloadOptimizationAPIUpdateWorkloadWithBodyWithResponse), ctx, clusterId, workloadId, contentType, body) -} - -// WorkloadOptimizationAPIUpdateWorkloadWithResponse mocks base method. -func (m *MockClientWithResponsesInterface) WorkloadOptimizationAPIUpdateWorkloadWithResponse(ctx context.Context, clusterId, workloadId string, body sdk.WorkloadOptimizationAPIUpdateWorkloadJSONRequestBody) (*sdk.WorkloadOptimizationAPIUpdateWorkloadResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WorkloadOptimizationAPIUpdateWorkloadWithResponse", ctx, clusterId, workloadId, body) - ret0, _ := ret[0].(*sdk.WorkloadOptimizationAPIUpdateWorkloadResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WorkloadOptimizationAPIUpdateWorkloadWithResponse indicates an expected call of WorkloadOptimizationAPIUpdateWorkloadWithResponse. -func (mr *MockClientWithResponsesInterfaceMockRecorder) WorkloadOptimizationAPIUpdateWorkloadWithResponse(ctx, clusterId, workloadId, body interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkloadOptimizationAPIUpdateWorkloadWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).WorkloadOptimizationAPIUpdateWorkloadWithResponse), ctx, clusterId, workloadId, body) -} - // MockResponse is a mock of Response interface. type MockResponse struct { ctrl *gomock.Controller