From d8687524ba470ddbf7cb6359c3d6f453553e2714 Mon Sep 17 00:00:00 2001 From: Jakub Solecki Date: Thu, 22 Aug 2024 09:26:44 +0200 Subject: [PATCH] generate missing sdk mocks --- castai/sdk/api.gen.go | 34 +++++--- castai/sdk/client.gen.go | 161 ++++++++++++++++++++++++++++++++++++++ castai/sdk/mock/client.go | 70 +++++++++++++++++ 3 files changed, 252 insertions(+), 13 deletions(-) diff --git a/castai/sdk/api.gen.go b/castai/sdk/api.gen.go index b33eab8f..dea4b36c 100644 --- a/castai/sdk/api.gen.go +++ b/castai/sdk/api.gen.go @@ -3293,8 +3293,9 @@ type WorkloadoptimizationV1PodMetrics struct { // WorkloadoptimizationV1RecommendationAppliedEvent defines model for workloadoptimization.v1.RecommendationAppliedEvent. type WorkloadoptimizationV1RecommendationAppliedEvent struct { - Current WorkloadoptimizationV1RecommendationAppliedEventChange `json:"current"` - Previous WorkloadoptimizationV1RecommendationAppliedEventChange `json:"previous"` + ApplyType WorkloadoptimizationV1ApplyType `json:"applyType"` + Current WorkloadoptimizationV1RecommendationAppliedEventChange `json:"current"` + Previous WorkloadoptimizationV1RecommendationAppliedEventChange `json:"previous"` } // WorkloadoptimizationV1RecommendationAppliedEventChange defines model for workloadoptimization.v1.RecommendationAppliedEvent.Change. @@ -3644,17 +3645,18 @@ type WorkloadoptimizationV1WorkloadRecommendation struct { // WorkloadoptimizationV1WorkloadScalingPolicy defines model for workloadoptimization.v1.WorkloadScalingPolicy. type WorkloadoptimizationV1WorkloadScalingPolicy struct { - ApplyType WorkloadoptimizationV1ApplyType `json:"applyType"` - ClusterId string `json:"clusterId"` - ConfidenceThreshold float64 `json:"confidenceThreshold"` - CreatedAt time.Time `json:"createdAt"` - Id string `json:"id"` - IsDefault bool `json:"isDefault"` - IsReadonly bool `json:"isReadonly"` - Name string `json:"name"` - OrganizationId string `json:"organizationId"` - RecommendationPolicies WorkloadoptimizationV1RecommendationPolicies `json:"recommendationPolicies"` - UpdatedAt time.Time `json:"updatedAt"` + ApplyType WorkloadoptimizationV1ApplyType `json:"applyType"` + ClusterId string `json:"clusterId"` + ConfidenceThreshold float64 `json:"confidenceThreshold"` + CreatedAt time.Time `json:"createdAt"` + HasWorkloadsConfiguredByAnnotations bool `json:"hasWorkloadsConfiguredByAnnotations"` + Id string `json:"id"` + IsDefault bool `json:"isDefault"` + IsReadonly bool `json:"isReadonly"` + Name string `json:"name"` + OrganizationId string `json:"organizationId"` + RecommendationPolicies WorkloadoptimizationV1RecommendationPolicies `json:"recommendationPolicies"` + UpdatedAt time.Time `json:"updatedAt"` } // AuthTokenAPIListAuthTokensParams defines parameters for AuthTokenAPIListAuthTokens. @@ -3843,6 +3845,9 @@ type UsersAPIAddUserToOrganizationJSONBody = CastaiUsersV1beta1NewMembership // UsersAPIUpdateOrganizationUserJSONBody defines parameters for UsersAPIUpdateOrganizationUser. type UsersAPIUpdateOrganizationUserJSONBody = UsersAPIUpdateOrganizationUserRequest +// UsersAPIListUserGroupsJSONBody defines parameters for UsersAPIListUserGroups. +type UsersAPIListUserGroupsJSONBody = map[string]interface{} + // ScheduledRebalancingAPICreateRebalancingScheduleJSONBody defines parameters for ScheduledRebalancingAPICreateRebalancingSchedule. type ScheduledRebalancingAPICreateRebalancingScheduleJSONBody = ScheduledrebalancingV1RebalancingSchedule @@ -4060,6 +4065,9 @@ type UsersAPIAddUserToOrganizationJSONRequestBody = UsersAPIAddUserToOrganizatio // UsersAPIUpdateOrganizationUserJSONRequestBody defines body for UsersAPIUpdateOrganizationUser for application/json ContentType. type UsersAPIUpdateOrganizationUserJSONRequestBody = UsersAPIUpdateOrganizationUserJSONBody +// UsersAPIListUserGroupsJSONRequestBody defines body for UsersAPIListUserGroups for application/json ContentType. +type UsersAPIListUserGroupsJSONRequestBody = UsersAPIListUserGroupsJSONBody + // ScheduledRebalancingAPICreateRebalancingScheduleJSONRequestBody defines body for ScheduledRebalancingAPICreateRebalancingSchedule for application/json ContentType. type ScheduledRebalancingAPICreateRebalancingScheduleJSONRequestBody = ScheduledRebalancingAPICreateRebalancingScheduleJSONBody diff --git a/castai/sdk/client.gen.go b/castai/sdk/client.gen.go index e0d3aa22..f9e18b5d 100644 --- a/castai/sdk/client.gen.go +++ b/castai/sdk/client.gen.go @@ -377,6 +377,11 @@ type ClientInterface interface { UsersAPIUpdateOrganizationUser(ctx context.Context, organizationId string, userId string, body UsersAPIUpdateOrganizationUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // UsersAPIListUserGroups request with any body + UsersAPIListUserGroupsWithBody(ctx context.Context, organizationId string, userId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // ScheduledRebalancingAPIListRebalancingSchedules request ScheduledRebalancingAPIListRebalancingSchedules(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1787,6 +1792,30 @@ func (c *Client) UsersAPIUpdateOrganizationUser(ctx context.Context, organizatio return c.Client.Do(req) } +func (c *Client) UsersAPIListUserGroupsWithBody(ctx context.Context, organizationId string, userId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUsersAPIListUserGroupsRequestWithBody(c.Server, organizationId, userId, 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) UsersAPIListUserGroups(ctx context.Context, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUsersAPIListUserGroupsRequest(c.Server, organizationId, userId, 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) ScheduledRebalancingAPIListRebalancingSchedules(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewScheduledRebalancingAPIListRebalancingSchedulesRequest(c.Server) if err != nil { @@ -5959,6 +5988,60 @@ func NewUsersAPIUpdateOrganizationUserRequestWithBody(server string, organizatio return req, nil } +// NewUsersAPIListUserGroupsRequest calls the generic UsersAPIListUserGroups builder with application/json body +func NewUsersAPIListUserGroupsRequest(server string, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewUsersAPIListUserGroupsRequestWithBody(server, organizationId, userId, "application/json", bodyReader) +} + +// NewUsersAPIListUserGroupsRequestWithBody generates requests for UsersAPIListUserGroups with any type of body +func NewUsersAPIListUserGroupsRequestWithBody(server string, organizationId string, userId string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "organizationId", runtime.ParamLocationPath, organizationId) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "userId", runtime.ParamLocationPath, userId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/organizations/%s/users/%s/groups", 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 +} + // NewScheduledRebalancingAPIListRebalancingSchedulesRequest generates requests for ScheduledRebalancingAPIListRebalancingSchedules func NewScheduledRebalancingAPIListRebalancingSchedulesRequest(server string) (*http.Request, error) { var err error @@ -8180,6 +8263,11 @@ type ClientWithResponsesInterface interface { UsersAPIUpdateOrganizationUserWithResponse(ctx context.Context, organizationId string, userId string, body UsersAPIUpdateOrganizationUserJSONRequestBody) (*UsersAPIUpdateOrganizationUserResponse, error) + // UsersAPIListUserGroups request with any body + UsersAPIListUserGroupsWithBodyWithResponse(ctx context.Context, organizationId string, userId string, contentType string, body io.Reader) (*UsersAPIListUserGroupsResponse, error) + + UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody) (*UsersAPIListUserGroupsResponse, error) + // ScheduledRebalancingAPIListRebalancingSchedules request ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx context.Context) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) @@ -10648,6 +10736,36 @@ func (r UsersAPIUpdateOrganizationUserResponse) GetBody() []byte { // TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 +type UsersAPIListUserGroupsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *[]CastaiUsersV1beta1GroupRef +} + +// Status returns HTTPResponse.Status +func (r UsersAPIListUserGroupsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UsersAPIListUserGroupsResponse) 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 UsersAPIListUserGroupsResponse) GetBody() []byte { + return r.Body +} + +// TODO: to have common interface. https://github.com/deepmap/oapi-codegen/issues/240 + type ScheduledRebalancingAPIListRebalancingSchedulesResponse struct { Body []byte HTTPResponse *http.Response @@ -12791,6 +12909,23 @@ func (c *ClientWithResponses) UsersAPIUpdateOrganizationUserWithResponse(ctx con return ParseUsersAPIUpdateOrganizationUserResponse(rsp) } +// UsersAPIListUserGroupsWithBodyWithResponse request with arbitrary body returning *UsersAPIListUserGroupsResponse +func (c *ClientWithResponses) UsersAPIListUserGroupsWithBodyWithResponse(ctx context.Context, organizationId string, userId string, contentType string, body io.Reader) (*UsersAPIListUserGroupsResponse, error) { + rsp, err := c.UsersAPIListUserGroupsWithBody(ctx, organizationId, userId, contentType, body) + if err != nil { + return nil, err + } + return ParseUsersAPIListUserGroupsResponse(rsp) +} + +func (c *ClientWithResponses) UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId string, userId string, body UsersAPIListUserGroupsJSONRequestBody) (*UsersAPIListUserGroupsResponse, error) { + rsp, err := c.UsersAPIListUserGroups(ctx, organizationId, userId, body) + if err != nil { + return nil, err + } + return ParseUsersAPIListUserGroupsResponse(rsp) +} + // ScheduledRebalancingAPIListRebalancingSchedulesWithResponse request returning *ScheduledRebalancingAPIListRebalancingSchedulesResponse func (c *ClientWithResponses) ScheduledRebalancingAPIListRebalancingSchedulesWithResponse(ctx context.Context) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) { rsp, err := c.ScheduledRebalancingAPIListRebalancingSchedules(ctx) @@ -15256,6 +15391,32 @@ func ParseUsersAPIUpdateOrganizationUserResponse(rsp *http.Response) (*UsersAPIU return response, nil } +// ParseUsersAPIListUserGroupsResponse parses an HTTP response from a UsersAPIListUserGroupsWithResponse call +func ParseUsersAPIListUserGroupsResponse(rsp *http.Response) (*UsersAPIListUserGroupsResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer rsp.Body.Close() + if err != nil { + return nil, err + } + + response := &UsersAPIListUserGroupsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest []CastaiUsersV1beta1GroupRef + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParseScheduledRebalancingAPIListRebalancingSchedulesResponse parses an HTTP response from a ScheduledRebalancingAPIListRebalancingSchedulesWithResponse call func ParseScheduledRebalancingAPIListRebalancingSchedulesResponse(rsp *http.Response) (*ScheduledRebalancingAPIListRebalancingSchedulesResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/castai/sdk/mock/client.go b/castai/sdk/mock/client.go index e005d951..df83df72 100644 --- a/castai/sdk/mock/client.go +++ b/castai/sdk/mock/client.go @@ -2735,6 +2735,46 @@ func (mr *MockClientInterfaceMockRecorder) UsersAPIListOrganizations(ctx, params return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizations", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListOrganizations), varargs...) } +// UsersAPIListUserGroups mocks base method. +func (m *MockClientInterface) UsersAPIListUserGroups(ctx context.Context, organizationId, userId string, body sdk.UsersAPIListUserGroupsJSONRequestBody, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, organizationId, userId, body} + for _, a := range reqEditors { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "UsersAPIListUserGroups", varargs...) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UsersAPIListUserGroups indicates an expected call of UsersAPIListUserGroups. +func (mr *MockClientInterfaceMockRecorder) UsersAPIListUserGroups(ctx, organizationId, userId, body interface{}, reqEditors ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, organizationId, userId, body}, reqEditors...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroups", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListUserGroups), varargs...) +} + +// UsersAPIListUserGroupsWithBody mocks base method. +func (m *MockClientInterface) UsersAPIListUserGroupsWithBody(ctx context.Context, organizationId, userId, contentType string, body io.Reader, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, organizationId, userId, contentType, body} + for _, a := range reqEditors { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "UsersAPIListUserGroupsWithBody", varargs...) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UsersAPIListUserGroupsWithBody indicates an expected call of UsersAPIListUserGroupsWithBody. +func (mr *MockClientInterfaceMockRecorder) UsersAPIListUserGroupsWithBody(ctx, organizationId, userId, contentType, body interface{}, reqEditors ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, organizationId, userId, contentType, body}, reqEditors...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroupsWithBody", reflect.TypeOf((*MockClientInterface)(nil).UsersAPIListUserGroupsWithBody), varargs...) +} + // UsersAPIRemoveOrganizationUsers mocks base method. func (m *MockClientInterface) UsersAPIRemoveOrganizationUsers(ctx context.Context, organizationId string, params *sdk.UsersAPIRemoveOrganizationUsersParams, reqEditors ...sdk.RequestEditorFn) (*http.Response, error) { m.ctrl.T.Helper() @@ -5273,6 +5313,36 @@ func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListOrganization return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListOrganizationsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListOrganizationsWithResponse), ctx, params) } +// UsersAPIListUserGroupsWithBodyWithResponse mocks base method. +func (m *MockClientWithResponsesInterface) UsersAPIListUserGroupsWithBodyWithResponse(ctx context.Context, organizationId, userId, contentType string, body io.Reader) (*sdk.UsersAPIListUserGroupsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UsersAPIListUserGroupsWithBodyWithResponse", ctx, organizationId, userId, contentType, body) + ret0, _ := ret[0].(*sdk.UsersAPIListUserGroupsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UsersAPIListUserGroupsWithBodyWithResponse indicates an expected call of UsersAPIListUserGroupsWithBodyWithResponse. +func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListUserGroupsWithBodyWithResponse(ctx, organizationId, userId, contentType, body interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroupsWithBodyWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListUserGroupsWithBodyWithResponse), ctx, organizationId, userId, contentType, body) +} + +// UsersAPIListUserGroupsWithResponse mocks base method. +func (m *MockClientWithResponsesInterface) UsersAPIListUserGroupsWithResponse(ctx context.Context, organizationId, userId string, body sdk.UsersAPIListUserGroupsJSONRequestBody) (*sdk.UsersAPIListUserGroupsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UsersAPIListUserGroupsWithResponse", ctx, organizationId, userId, body) + ret0, _ := ret[0].(*sdk.UsersAPIListUserGroupsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UsersAPIListUserGroupsWithResponse indicates an expected call of UsersAPIListUserGroupsWithResponse. +func (mr *MockClientWithResponsesInterfaceMockRecorder) UsersAPIListUserGroupsWithResponse(ctx, organizationId, userId, body interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UsersAPIListUserGroupsWithResponse", reflect.TypeOf((*MockClientWithResponsesInterface)(nil).UsersAPIListUserGroupsWithResponse), ctx, organizationId, userId, body) +} + // UsersAPIRemoveOrganizationUsersWithResponse mocks base method. func (m *MockClientWithResponsesInterface) UsersAPIRemoveOrganizationUsersWithResponse(ctx context.Context, organizationId string, params *sdk.UsersAPIRemoveOrganizationUsersParams) (*sdk.UsersAPIRemoveOrganizationUsersResponse, error) { m.ctrl.T.Helper()