diff --git a/generator/generator.go b/generator/generator.go index 4513635..ed05059 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -119,6 +119,12 @@ func extractSpecs(spec openAPISpec, orderedEndpointRoutes []string) (templateInp m := generateModels(spec) endpoints := generateEndpointsImplementationMethods(spec, orderedEndpointRoutes) + var endpointNames = make([]string, 0, len(endpoints)) + for k, _ := range endpoints { + endpointNames = append(endpointNames, k) + } + slices.Sort(endpointNames) + endpointsStr := make([]string, len(endpoints)) endpointsTestStr := make([]string, 0, len(endpoints)) models := models{} @@ -449,7 +455,8 @@ func extractSpecs(spec openAPISpec, orderedEndpointRoutes []string) (templateInp }, } - for i, s := range endpoints { + for i, name := range endpointNames { + s := endpoints[name] endpointsStr[i] = s.generateMethodImplementation() if !skipTest(s.Route) { endpointsTestStr = append(endpointsTestStr, s.generateMethodImplementationTest()) @@ -1326,6 +1333,7 @@ func (m model) generateCodeEnum() string { children[i] = c i++ } + slices.Sort(children) for _, child := range children { enumOption := strings.ToUpper(child[:1]) + child[1:] @@ -1374,7 +1382,7 @@ func implementationNameFromID(s string) string { func generateEndpointsImplementationMethods( o openAPISpec, orderedEndpoints []string, -) (endpoints []endpointImplementation) { +) (endpoints map[string]endpointImplementation) { const suffixResponseObject = "RespObj" const suffixRequestObject = "ReqObj" @@ -1387,6 +1395,7 @@ func generateEndpointsImplementationMethods( http.MethodDelete, } + endpoints = make(map[string]endpointImplementation) for _, route := range orderedEndpoints { p := o.Paths.Find(route) if p == nil { @@ -1454,7 +1463,7 @@ func generateEndpointsImplementationMethods( } } - endpoints = append(endpoints, e) + endpoints[e.Name] = e } } return diff --git a/sdk.go b/sdk.go index f976199..4e40e2d 100644 --- a/sdk.go +++ b/sdk.go @@ -104,18 +104,6 @@ func (c Client) requestHandler(url string, t string, reqPayload interface{}, res return nil } -// ListApiKeys Retrieves the API keys for your Neon account. -// The response does not include API key tokens. A token is only provided when creating an API key. -// API keys can also be managed in the Neon Console. -// For more information, see [Manage API keys](https://neon.tech/docs/manage/api-keys/). -func (c Client) ListApiKeys() ([]ApiKeysListResponseItem, error) { - var v []ApiKeysListResponseItem - if err := c.requestHandler(c.baseURL+"/api_keys", "GET", nil, &v); err != nil { - return nil, err - } - return v, nil -} - // CreateApiKey Creates an API key. // The `key_name` is a user-specified name for the key. // This method returns an `id` and `key`. The `key` is a randomly generated, 64-bit token required to access the Neon API. @@ -129,62 +117,6 @@ func (c Client) CreateApiKey(cfg ApiKeyCreateRequest) (ApiKeyCreateResponse, err return v, nil } -// RevokeApiKey Revokes the specified API key. -// An API key that is no longer needed can be revoked. -// This action cannot be reversed. -// You can obtain `key_id` values by listing the API keys for your Neon account. -// API keys can also be managed in the Neon Console. -// See [Manage API keys](https://neon.tech/docs/manage/api-keys/). -func (c Client) RevokeApiKey(keyID int64) (ApiKeyRevokeResponse, error) { - var v ApiKeyRevokeResponse - if err := c.requestHandler(c.baseURL+"/api_keys/"+strconv.FormatInt(keyID, 10), "DELETE", nil, &v); err != nil { - return ApiKeyRevokeResponse{}, err - } - return v, nil -} - -// GetProjectOperation Retrieves details for the specified operation. -// An operation is an action performed on a Neon project resource. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain a `operation_id` by listing operations for the project. -func (c Client) GetProjectOperation(projectID string, operationID string) (OperationResponse, error) { - var v OperationResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/operations/"+operationID, "GET", nil, &v); err != nil { - return OperationResponse{}, err - } - return v, nil -} - -// ListProjects Retrieves a list of projects for the Neon account. -// A project is the top-level object in the Neon object hierarchy. -// For more information, see [Manage projects](https://neon.tech/docs/manage/projects/). -func (c Client) ListProjects(cursor *string, limit *int, search *string, orgID *string) (ListProjectsRespObj, error) { - var ( - queryElements []string - query string - ) - if cursor != nil { - queryElements = append(queryElements, "cursor="+*cursor) - } - if limit != nil { - queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) - } - if search != nil { - queryElements = append(queryElements, "search="+*search) - } - if orgID != nil { - queryElements = append(queryElements, "org_id="+*orgID) - } - if len(queryElements) > 0 { - query = "?" + strings.Join(queryElements, "&") - } - var v ListProjectsRespObj - if err := c.requestHandler(c.baseURL+"/projects"+query, "GET", nil, &v); err != nil { - return ListProjectsRespObj{}, err - } - return v, nil -} - // CreateProject Creates a Neon project. // A project is the top-level object in the Neon object hierarchy. // Plan limits define how many projects you can create. @@ -201,29 +133,62 @@ func (c Client) CreateProject(cfg ProjectCreateRequest) (CreatedProject, error) return v, nil } -// ListSharedProjects Retrieves a list of shared projects for the Neon account. -// A project is the top-level object in the Neon object hierarchy. -// For more information, see [Manage projects](https://neon.tech/docs/manage/projects/). -func (c Client) ListSharedProjects(cursor *string, limit *int, search *string) (ListSharedProjectsRespObj, error) { - var ( - queryElements []string - query string - ) - if cursor != nil { - queryElements = append(queryElements, "cursor="+*cursor) - } - if limit != nil { - queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) +// CreateProjectBranch Creates a branch in the specified project. +// You can obtain a `project_id` by listing the projects for your Neon account. +// This method does not require a request body, but you can specify one to create a compute endpoint for the branch or to select a non-default parent branch. +// The default behavior is to create a branch from the project's default branch with no compute endpoint, and the branch name is auto-generated. +// There is a maximum of one read-write endpoint per branch. +// A branch can have multiple read-only endpoints. +// For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). +func (c Client) CreateProjectBranch(projectID string, cfg *CreateProjectBranchReqObj) (CreatedBranch, error) { + var v CreatedBranch + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches", "POST", cfg, &v); err != nil { + return CreatedBranch{}, err } - if search != nil { - queryElements = append(queryElements, "search="+*search) + return v, nil +} + +// CreateProjectBranchDatabase Creates a database in the specified branch. +// A branch can have multiple databases. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain the `branch_id` by listing the project's branches. +// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). +func (c Client) CreateProjectBranchDatabase(projectID string, branchID string, cfg DatabaseCreateRequest) (DatabaseOperations, error) { + var v DatabaseOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases", "POST", cfg, &v); err != nil { + return DatabaseOperations{}, err } - if len(queryElements) > 0 { - query = "?" + strings.Join(queryElements, "&") + return v, nil +} + +// CreateProjectBranchRole Creates a Postgres role in the specified branch. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain the `branch_id` by listing the project's branches. +// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). +// Connections established to the active compute endpoint will be dropped. +// If the compute endpoint is idle, the endpoint becomes active for a short period of time and is suspended afterward. +func (c Client) CreateProjectBranchRole(projectID string, branchID string, cfg RoleCreateRequest) (RoleOperations, error) { + var v RoleOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles", "POST", cfg, &v); err != nil { + return RoleOperations{}, err } - var v ListSharedProjectsRespObj - if err := c.requestHandler(c.baseURL+"/projects/shared"+query, "GET", nil, &v); err != nil { - return ListSharedProjectsRespObj{}, err + return v, nil +} + +// CreateProjectEndpoint Creates a compute endpoint for the specified branch. +// An endpoint is a Neon compute instance. +// There is a maximum of one read-write compute endpoint per branch. +// If the specified branch already has a read-write compute endpoint, the operation fails. +// A branch can have multiple read-only compute endpoints. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain `branch_id` by listing the project's branches. +// A `branch_id` has a `br-` prefix. +// For supported regions and `region_id` values, see [Regions](https://neon.tech/docs/introduction/regions/). +// For more information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). +func (c Client) CreateProjectEndpoint(projectID string, cfg EndpointCreateRequest) (EndpointOperations, error) { + var v EndpointOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints", "POST", cfg, &v); err != nil { + return EndpointOperations{}, err } return v, nil } @@ -240,77 +205,61 @@ func (c Client) DeleteProject(projectID string) (ProjectResponse, error) { return v, nil } -// GetProject Retrieves information about the specified project. -// A project is the top-level object in the Neon object hierarchy. +// DeleteProjectBranch Deletes the specified branch from a project, and places +// all compute endpoints into an idle state, breaking existing client connections. // You can obtain a `project_id` by listing the projects for your Neon account. -func (c Client) GetProject(projectID string) (ProjectResponse, error) { - var v ProjectResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID, "GET", nil, &v); err != nil { - return ProjectResponse{}, err +// You can obtain a `branch_id` by listing the project's branches. +// For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). +// When a successful response status is received, the compute endpoints are still active, +// and the branch is not yet deleted from storage. +// The deletion occurs after all operations finish. +// You cannot delete a project's root or default branch, and you cannot delete a branch that has a child branch. +// A project must have at least one branch. +func (c Client) DeleteProjectBranch(projectID string, branchID string) (BranchOperations, error) { + var v BranchOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID, "DELETE", nil, &v); err != nil { + return BranchOperations{}, err } return v, nil } -// UpdateProject Updates the specified project. +// DeleteProjectBranchDatabase Deletes the specified database from the branch. // You can obtain a `project_id` by listing the projects for your Neon account. -// Neon permits updating the project name only. -func (c Client) UpdateProject(projectID string, cfg ProjectUpdateRequest) (UpdateProjectRespObj, error) { - var v UpdateProjectRespObj - if err := c.requestHandler(c.baseURL+"/projects/"+projectID, "PATCH", cfg, &v); err != nil { - return UpdateProjectRespObj{}, err +// You can obtain the `branch_id` and `database_name` by listing the branch's databases. +// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). +func (c Client) DeleteProjectBranchDatabase(projectID string, branchID string, databaseName string) (DatabaseOperations, error) { + var v DatabaseOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases/"+databaseName, "DELETE", nil, &v); err != nil { + return DatabaseOperations{}, err } return v, nil } -// ListProjectOperations Retrieves a list of operations for the specified Neon project. +// DeleteProjectBranchRole Deletes the specified Postgres role from the branch. // You can obtain a `project_id` by listing the projects for your Neon account. -// The number of operations returned can be large. -// To paginate the response, issue an initial request with a `limit` value. -// Then, add the `cursor` value that was returned in the response to the next request. -func (c Client) ListProjectOperations(projectID string, cursor *string, limit *int) (ListOperations, error) { - var ( - queryElements []string - query string - ) - if cursor != nil { - queryElements = append(queryElements, "cursor="+*cursor) - } - if limit != nil { - queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) - } - if len(queryElements) > 0 { - query = "?" + strings.Join(queryElements, "&") - } - var v ListOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/operations"+query, "GET", nil, &v); err != nil { - return ListOperations{}, err - } - return v, nil -} - -// ListProjectPermissions Retrieves details about users who have access to the project, including the permission `id`, the granted-to email address, and the date project access was granted. -func (c Client) ListProjectPermissions(projectID string) (ProjectPermissions, error) { - var v ProjectPermissions - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/permissions", "GET", nil, &v); err != nil { - return ProjectPermissions{}, err - } - return v, nil -} - -// GrantPermissionToProject Grants project access to the account associated with the specified email address -func (c Client) GrantPermissionToProject(projectID string, cfg GrantPermissionToProjectRequest) (ProjectPermission, error) { - var v ProjectPermission - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/permissions", "POST", cfg, &v); err != nil { - return ProjectPermission{}, err +// You can obtain the `branch_id` by listing the project's branches. +// You can obtain the `role_name` by listing the roles for a branch. +// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). +func (c Client) DeleteProjectBranchRole(projectID string, branchID string, roleName string) (RoleOperations, error) { + var v RoleOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles/"+roleName, "DELETE", nil, &v); err != nil { + return RoleOperations{}, err } return v, nil } -// RevokePermissionFromProject Revokes project access from the user associted with the specified permisison `id`. You can retrieve a user's permission `id` by listing project access. -func (c Client) RevokePermissionFromProject(projectID string, permissionID string) (ProjectPermission, error) { - var v ProjectPermission - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/permissions/"+permissionID, "DELETE", nil, &v); err != nil { - return ProjectPermission{}, err +// DeleteProjectEndpoint Delete the specified compute endpoint. +// A compute endpoint is a Neon compute instance. +// Deleting a compute endpoint drops existing network connections to the compute endpoint. +// The deletion is completed when last operation in the chain finishes successfully. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain an `endpoint_id` by listing your project's compute endpoints. +// An `endpoint_id` has an `ep-` prefix. +// For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). +func (c Client) DeleteProjectEndpoint(projectID string, endpointID string) (EndpointOperations, error) { + var v EndpointOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID, "DELETE", nil, &v); err != nil { + return EndpointOperations{}, err } return v, nil } @@ -350,50 +299,103 @@ func (c Client) GetConnectionURI(projectID string, branchID *string, endpointID return v, nil } -// ListProjectBranches Retrieves a list of branches for the specified project. -// You can obtain a `project_id` by listing the projects for your Neon account. -// Each Neon project has a root branch named `main`. -// A `branch_id` value has a `br-` prefix. -// A project may contain child branches that were branched from `main` or from another branch. -// A parent branch is identified by the `parent_id` value, which is the `id` of the parent branch. -// For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). -func (c Client) ListProjectBranches(projectID string) (ListProjectBranchesRespObj, error) { - var v ListProjectBranchesRespObj - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches", "GET", nil, &v); err != nil { - return ListProjectBranchesRespObj{}, err - } - return v, nil -} - -// CreateProjectBranch Creates a branch in the specified project. -// You can obtain a `project_id` by listing the projects for your Neon account. -// This method does not require a request body, but you can specify one to create a compute endpoint for the branch or to select a non-default parent branch. -// The default behavior is to create a branch from the project's default branch with no compute endpoint, and the branch name is auto-generated. -// There is a maximum of one read-write endpoint per branch. -// A branch can have multiple read-only endpoints. -// For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). -func (c Client) CreateProjectBranch(projectID string, cfg *CreateProjectBranchReqObj) (CreatedBranch, error) { - var v CreatedBranch - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches", "POST", cfg, &v); err != nil { - return CreatedBranch{}, err +// GetConsumptionHistoryPerAccount Retrieves consumption metrics for Scale and Business plan accounts. History begins at the time of upgrade. +// Available for Scale and Business plan users only. +func (c Client) GetConsumptionHistoryPerAccount(from time.Time, to time.Time, granularity ConsumptionHistoryGranularity, orgID *string, includeV1Metrics *bool) (ConsumptionHistoryPerAccountResponse, error) { + var ( + queryElements []string + query string + ) + queryElements = append(queryElements, "from="+from.Format(time.RFC3339)) + queryElements = append(queryElements, "to="+to.Format(time.RFC3339)) + queryElements = append(queryElements, "granularity="+string(granularity)) + if orgID != nil { + queryElements = append(queryElements, "org_id="+*orgID) + } + if includeV1Metrics != nil { + queryElements = append(queryElements, "include_v1_metrics="+func(includeV1Metrics bool) string { + if includeV1Metrics { + return "true" + } + return "false" + }(*includeV1Metrics)) + } + if len(queryElements) > 0 { + query = "?" + strings.Join(queryElements, "&") + } + var v ConsumptionHistoryPerAccountResponse + if err := c.requestHandler(c.baseURL+"/consumption_history/account"+query, "GET", nil, &v); err != nil { + return ConsumptionHistoryPerAccountResponse{}, err } return v, nil } -// DeleteProjectBranch Deletes the specified branch from a project, and places -// all compute endpoints into an idle state, breaking existing client connections. +// GetConsumptionHistoryPerProject Retrieves consumption metrics for Scale and Business plan projects. History begins at the time of upgrade. +// Available for Scale and Business plan users only. +// Issuing a call to this API does not wake a project's compute endpoint. +func (c Client) GetConsumptionHistoryPerProject(cursor *string, limit *int, projectIDs []string, from time.Time, to time.Time, granularity ConsumptionHistoryGranularity, orgID *string, includeV1Metrics *bool) (GetConsumptionHistoryPerProjectRespObj, error) { + var ( + queryElements []string + query string + ) + queryElements = append(queryElements, "from="+from.Format(time.RFC3339)) + queryElements = append(queryElements, "to="+to.Format(time.RFC3339)) + queryElements = append(queryElements, "granularity="+string(granularity)) + if cursor != nil { + queryElements = append(queryElements, "cursor="+*cursor) + } + if limit != nil { + queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) + } + if len(projectIDs) > 0 { + queryElements = append(queryElements, "project_ids="+strings.Join(projectIDs, ",")) + } + if orgID != nil { + queryElements = append(queryElements, "org_id="+*orgID) + } + if includeV1Metrics != nil { + queryElements = append(queryElements, "include_v1_metrics="+func(includeV1Metrics bool) string { + if includeV1Metrics { + return "true" + } + return "false" + }(*includeV1Metrics)) + } + if len(queryElements) > 0 { + query = "?" + strings.Join(queryElements, "&") + } + var v GetConsumptionHistoryPerProjectRespObj + if err := c.requestHandler(c.baseURL+"/consumption_history/projects"+query, "GET", nil, &v); err != nil { + return GetConsumptionHistoryPerProjectRespObj{}, err + } + return v, nil +} + +// GetCurrentUserInfo Retrieves information about the current Neon user account. +func (c Client) GetCurrentUserInfo() (CurrentUserInfoResponse, error) { + var v CurrentUserInfoResponse + if err := c.requestHandler(c.baseURL+"/users/me", "GET", nil, &v); err != nil { + return CurrentUserInfoResponse{}, err + } + return v, nil +} + +// GetCurrentUserOrganizations Retrieves information about the current Neon user's organizations +func (c Client) GetCurrentUserOrganizations() (OrganizationsResponse, error) { + var v OrganizationsResponse + if err := c.requestHandler(c.baseURL+"/users/me/organizations", "GET", nil, &v); err != nil { + return OrganizationsResponse{}, err + } + return v, nil +} + +// GetProject Retrieves information about the specified project. +// A project is the top-level object in the Neon object hierarchy. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain a `branch_id` by listing the project's branches. -// For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). -// When a successful response status is received, the compute endpoints are still active, -// and the branch is not yet deleted from storage. -// The deletion occurs after all operations finish. -// You cannot delete a project's root or default branch, and you cannot delete a branch that has a child branch. -// A project must have at least one branch. -func (c Client) DeleteProjectBranch(projectID string, branchID string) (BranchOperations, error) { - var v BranchOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID, "DELETE", nil, &v); err != nil { - return BranchOperations{}, err +func (c Client) GetProject(projectID string) (ProjectResponse, error) { + var v ProjectResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID, "GET", nil, &v); err != nil { + return ProjectResponse{}, err } return v, nil } @@ -414,23 +416,41 @@ func (c Client) GetProjectBranch(projectID string, branchID string) (GetProjectB return v, nil } -// UpdateProjectBranch Updates the specified branch. +// GetProjectBranchDatabase Retrieves information about the specified database. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain the `branch_id` and `database_name` by listing the branch's databases. +// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). +func (c Client) GetProjectBranchDatabase(projectID string, branchID string, databaseName string) (DatabaseResponse, error) { + var v DatabaseResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases/"+databaseName, "GET", nil, &v); err != nil { + return DatabaseResponse{}, err + } + return v, nil +} + +// GetProjectBranchRole Retrieves details about the specified role. // You can obtain a `project_id` by listing the projects for your Neon account. // You can obtain the `branch_id` by listing the project's branches. -// For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). -func (c Client) UpdateProjectBranch(projectID string, branchID string, cfg BranchUpdateRequest) (BranchOperations, error) { - var v BranchOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID, "PATCH", cfg, &v); err != nil { - return BranchOperations{}, err +// You can obtain the `role_name` by listing the roles for a branch. +// In Neon, the terms "role" and "user" are synonymous. +// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). +func (c Client) GetProjectBranchRole(projectID string, branchID string, roleName string) (RoleResponse, error) { + var v RoleResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles/"+roleName, "GET", nil, &v); err != nil { + return RoleResponse{}, err } return v, nil } -// RestoreProjectBranch Restores a branch to an earlier state in its own or another branch's history -func (c Client) RestoreProjectBranch(projectID string, branchID string, cfg BranchRestoreRequest) (BranchOperations, error) { - var v BranchOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/restore", "POST", cfg, &v); err != nil { - return BranchOperations{}, err +// GetProjectBranchRolePassword Retrieves the password for the specified Postgres role, if possible. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain the `branch_id` by listing the project's branches. +// You can obtain the `role_name` by listing the roles for a branch. +// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). +func (c Client) GetProjectBranchRolePassword(projectID string, branchID string, roleName string) (RolePasswordResponse, error) { + var v RolePasswordResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles/"+roleName+"/reveal_password", "GET", nil, &v); err != nil { + return RolePasswordResponse{}, err } return v, nil } @@ -458,42 +478,49 @@ func (c Client) GetProjectBranchSchema(projectID string, branchID string, dbName return v, nil } -// SetPrimaryProjectBranch DEPRECATED. Use `/set_as_default` endpoint. -// Sets the specified branch as the project's primary branch. -// The primary designation is automatically removed from the previous primary branch. +// GetProjectEndpoint Retrieves information about the specified compute endpoint. +// A compute endpoint is a Neon compute instance. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). -func (c Client) SetPrimaryProjectBranch(projectID string, branchID string) (BranchOperations, error) { - var v BranchOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/set_as_primary", "POST", nil, &v); err != nil { - return BranchOperations{}, err +// You can obtain an `endpoint_id` by listing your project's compute endpoints. +// An `endpoint_id` has an `ep-` prefix. +// For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). +func (c Client) GetProjectEndpoint(projectID string, endpointID string) (EndpointResponse, error) { + var v EndpointResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID, "GET", nil, &v); err != nil { + return EndpointResponse{}, err } return v, nil } -// SetDefaultProjectBranch Sets the specified branch as the project's default branch. -// The default designation is automatically removed from the previous default branch. +// GetProjectOperation Retrieves details for the specified operation. +// An operation is an action performed on a Neon project resource. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). -func (c Client) SetDefaultProjectBranch(projectID string, branchID string) (BranchOperations, error) { - var v BranchOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/set_as_default", "POST", nil, &v); err != nil { - return BranchOperations{}, err +// You can obtain a `operation_id` by listing operations for the project. +func (c Client) GetProjectOperation(projectID string, operationID string) (OperationResponse, error) { + var v OperationResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/operations/"+operationID, "GET", nil, &v); err != nil { + return OperationResponse{}, err } return v, nil } -// ListProjectBranchEndpoints Retrieves a list of compute endpoints for the specified branch. -// Neon permits only one read-write compute endpoint per branch. -// A branch can have multiple read-only compute endpoints. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -func (c Client) ListProjectBranchEndpoints(projectID string, branchID string) (EndpointsResponse, error) { - var v EndpointsResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/endpoints", "GET", nil, &v); err != nil { - return EndpointsResponse{}, err +// GrantPermissionToProject Grants project access to the account associated with the specified email address +func (c Client) GrantPermissionToProject(projectID string, cfg GrantPermissionToProjectRequest) (ProjectPermission, error) { + var v ProjectPermission + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/permissions", "POST", cfg, &v); err != nil { + return ProjectPermission{}, err + } + return v, nil +} + +// ListApiKeys Retrieves the API keys for your Neon account. +// The response does not include API key tokens. A token is only provided when creating an API key. +// API keys can also be managed in the Neon Console. +// For more information, see [Manage API keys](https://neon.tech/docs/manage/api-keys/). +func (c Client) ListApiKeys() ([]ApiKeysListResponseItem, error) { + var v []ApiKeysListResponseItem + if err := c.requestHandler(c.baseURL+"/api_keys", "GET", nil, &v); err != nil { + return nil, err } return v, nil } @@ -511,117 +538,179 @@ func (c Client) ListProjectBranchDatabases(projectID string, branchID string) (D return v, nil } -// CreateProjectBranchDatabase Creates a database in the specified branch. -// A branch can have multiple databases. +// ListProjectBranchEndpoints Retrieves a list of compute endpoints for the specified branch. +// Neon permits only one read-write compute endpoint per branch. +// A branch can have multiple read-only compute endpoints. // You can obtain a `project_id` by listing the projects for your Neon account. // You can obtain the `branch_id` by listing the project's branches. -// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). -func (c Client) CreateProjectBranchDatabase(projectID string, branchID string, cfg DatabaseCreateRequest) (DatabaseOperations, error) { - var v DatabaseOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases", "POST", cfg, &v); err != nil { - return DatabaseOperations{}, err +func (c Client) ListProjectBranchEndpoints(projectID string, branchID string) (EndpointsResponse, error) { + var v EndpointsResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/endpoints", "GET", nil, &v); err != nil { + return EndpointsResponse{}, err } return v, nil } -// GetProjectBranchDatabase Retrieves information about the specified database. +// ListProjectBranchRoles Retrieves a list of Postgres roles from the specified branch. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` and `database_name` by listing the branch's databases. -// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). -func (c Client) GetProjectBranchDatabase(projectID string, branchID string, databaseName string) (DatabaseResponse, error) { - var v DatabaseResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases/"+databaseName, "GET", nil, &v); err != nil { - return DatabaseResponse{}, err +// You can obtain the `branch_id` by listing the project's branches. +// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). +func (c Client) ListProjectBranchRoles(projectID string, branchID string) (RolesResponse, error) { + var v RolesResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles", "GET", nil, &v); err != nil { + return RolesResponse{}, err } return v, nil } -// UpdateProjectBranchDatabase Updates the specified database in the branch. +// ListProjectBranches Retrieves a list of branches for the specified project. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` and `database_name` by listing the branch's databases. -// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). -func (c Client) UpdateProjectBranchDatabase(projectID string, branchID string, databaseName string, cfg DatabaseUpdateRequest) (DatabaseOperations, error) { - var v DatabaseOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases/"+databaseName, "PATCH", cfg, &v); err != nil { - return DatabaseOperations{}, err +// Each Neon project has a root branch named `main`. +// A `branch_id` value has a `br-` prefix. +// A project may contain child branches that were branched from `main` or from another branch. +// A parent branch is identified by the `parent_id` value, which is the `id` of the parent branch. +// For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). +func (c Client) ListProjectBranches(projectID string) (ListProjectBranchesRespObj, error) { + var v ListProjectBranchesRespObj + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches", "GET", nil, &v); err != nil { + return ListProjectBranchesRespObj{}, err } return v, nil } -// DeleteProjectBranchDatabase Deletes the specified database from the branch. +// ListProjectEndpoints Retrieves a list of compute endpoints for the specified project. +// A compute endpoint is a Neon compute instance. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` and `database_name` by listing the branch's databases. -// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). -func (c Client) DeleteProjectBranchDatabase(projectID string, branchID string, databaseName string) (DatabaseOperations, error) { - var v DatabaseOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases/"+databaseName, "DELETE", nil, &v); err != nil { - return DatabaseOperations{}, err +// For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). +func (c Client) ListProjectEndpoints(projectID string) (EndpointsResponse, error) { + var v EndpointsResponse + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints", "GET", nil, &v); err != nil { + return EndpointsResponse{}, err } return v, nil } -// ListProjectBranchRoles Retrieves a list of Postgres roles from the specified branch. +// ListProjectOperations Retrieves a list of operations for the specified Neon project. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). -func (c Client) ListProjectBranchRoles(projectID string, branchID string) (RolesResponse, error) { - var v RolesResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles", "GET", nil, &v); err != nil { - return RolesResponse{}, err +// The number of operations returned can be large. +// To paginate the response, issue an initial request with a `limit` value. +// Then, add the `cursor` value that was returned in the response to the next request. +func (c Client) ListProjectOperations(projectID string, cursor *string, limit *int) (ListOperations, error) { + var ( + queryElements []string + query string + ) + if cursor != nil { + queryElements = append(queryElements, "cursor="+*cursor) + } + if limit != nil { + queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) + } + if len(queryElements) > 0 { + query = "?" + strings.Join(queryElements, "&") + } + var v ListOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/operations"+query, "GET", nil, &v); err != nil { + return ListOperations{}, err } return v, nil } -// CreateProjectBranchRole Creates a Postgres role in the specified branch. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). -// Connections established to the active compute endpoint will be dropped. -// If the compute endpoint is idle, the endpoint becomes active for a short period of time and is suspended afterward. -func (c Client) CreateProjectBranchRole(projectID string, branchID string, cfg RoleCreateRequest) (RoleOperations, error) { - var v RoleOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles", "POST", cfg, &v); err != nil { - return RoleOperations{}, err +// ListProjectPermissions Retrieves details about users who have access to the project, including the permission `id`, the granted-to email address, and the date project access was granted. +func (c Client) ListProjectPermissions(projectID string) (ProjectPermissions, error) { + var v ProjectPermissions + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/permissions", "GET", nil, &v); err != nil { + return ProjectPermissions{}, err } return v, nil } -// DeleteProjectBranchRole Deletes the specified Postgres role from the branch. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// You can obtain the `role_name` by listing the roles for a branch. -// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). -func (c Client) DeleteProjectBranchRole(projectID string, branchID string, roleName string) (RoleOperations, error) { - var v RoleOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles/"+roleName, "DELETE", nil, &v); err != nil { - return RoleOperations{}, err +// ListProjects Retrieves a list of projects for the Neon account. +// A project is the top-level object in the Neon object hierarchy. +// For more information, see [Manage projects](https://neon.tech/docs/manage/projects/). +func (c Client) ListProjects(cursor *string, limit *int, search *string, orgID *string) (ListProjectsRespObj, error) { + var ( + queryElements []string + query string + ) + if cursor != nil { + queryElements = append(queryElements, "cursor="+*cursor) + } + if limit != nil { + queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) + } + if search != nil { + queryElements = append(queryElements, "search="+*search) + } + if orgID != nil { + queryElements = append(queryElements, "org_id="+*orgID) + } + if len(queryElements) > 0 { + query = "?" + strings.Join(queryElements, "&") + } + var v ListProjectsRespObj + if err := c.requestHandler(c.baseURL+"/projects"+query, "GET", nil, &v); err != nil { + return ListProjectsRespObj{}, err } return v, nil } -// GetProjectBranchRole Retrieves details about the specified role. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// You can obtain the `role_name` by listing the roles for a branch. -// In Neon, the terms "role" and "user" are synonymous. -// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). -func (c Client) GetProjectBranchRole(projectID string, branchID string, roleName string) (RoleResponse, error) { - var v RoleResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles/"+roleName, "GET", nil, &v); err != nil { - return RoleResponse{}, err +// ListProjectsConsumption Retrieves consumption metrics for each project for the current billing period. +// For usage information, see [Retrieving metrics for all projects](https://neon.tech/docs/guides/partner-billing#retrieving-metrics-for-all-projects). +// Issuing a call to this API does not wake a project's compute endpoint. +func (c Client) ListProjectsConsumption(cursor *string, limit *int, from *time.Time, to *time.Time, orgID *string) (ListProjectsConsumptionRespObj, error) { + var ( + queryElements []string + query string + ) + if cursor != nil { + queryElements = append(queryElements, "cursor="+*cursor) + } + if limit != nil { + queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) + } + if from != nil { + queryElements = append(queryElements, "from="+from.Format(time.RFC3339)) + } + if to != nil { + queryElements = append(queryElements, "to="+to.Format(time.RFC3339)) + } + if orgID != nil { + queryElements = append(queryElements, "org_id="+*orgID) + } + if len(queryElements) > 0 { + query = "?" + strings.Join(queryElements, "&") + } + var v ListProjectsConsumptionRespObj + if err := c.requestHandler(c.baseURL+"/consumption/projects"+query, "GET", nil, &v); err != nil { + return ListProjectsConsumptionRespObj{}, err } return v, nil } -// GetProjectBranchRolePassword Retrieves the password for the specified Postgres role, if possible. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain the `branch_id` by listing the project's branches. -// You can obtain the `role_name` by listing the roles for a branch. -// For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). -func (c Client) GetProjectBranchRolePassword(projectID string, branchID string, roleName string) (RolePasswordResponse, error) { - var v RolePasswordResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/roles/"+roleName+"/reveal_password", "GET", nil, &v); err != nil { - return RolePasswordResponse{}, err +// ListSharedProjects Retrieves a list of shared projects for the Neon account. +// A project is the top-level object in the Neon object hierarchy. +// For more information, see [Manage projects](https://neon.tech/docs/manage/projects/). +func (c Client) ListSharedProjects(cursor *string, limit *int, search *string) (ListSharedProjectsRespObj, error) { + var ( + queryElements []string + query string + ) + if cursor != nil { + queryElements = append(queryElements, "cursor="+*cursor) + } + if limit != nil { + queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) + } + if search != nil { + queryElements = append(queryElements, "search="+*search) + } + if len(queryElements) > 0 { + query = "?" + strings.Join(queryElements, "&") + } + var v ListSharedProjectsRespObj + if err := c.requestHandler(c.baseURL+"/projects/shared"+query, "GET", nil, &v); err != nil { + return ListSharedProjectsRespObj{}, err } return v, nil } @@ -643,79 +732,74 @@ func (c Client) ResetProjectBranchRolePassword(projectID string, branchID string return v, nil } -// ListProjectEndpoints Retrieves a list of compute endpoints for the specified project. -// A compute endpoint is a Neon compute instance. +// RestartProjectEndpoint Restart the specified compute endpoint: suspend immediately followed by start operations. // You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain an `endpoint_id` by listing your project's compute endpoints. +// An `endpoint_id` has an `ep-` prefix. // For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). -func (c Client) ListProjectEndpoints(projectID string) (EndpointsResponse, error) { - var v EndpointsResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints", "GET", nil, &v); err != nil { - return EndpointsResponse{}, err +func (c Client) RestartProjectEndpoint(projectID string, endpointID string) (EndpointOperations, error) { + var v EndpointOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID+"/restart", "POST", nil, &v); err != nil { + return EndpointOperations{}, err } return v, nil } -// CreateProjectEndpoint Creates a compute endpoint for the specified branch. -// An endpoint is a Neon compute instance. -// There is a maximum of one read-write compute endpoint per branch. -// If the specified branch already has a read-write compute endpoint, the operation fails. -// A branch can have multiple read-only compute endpoints. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain `branch_id` by listing the project's branches. -// A `branch_id` has a `br-` prefix. -// For supported regions and `region_id` values, see [Regions](https://neon.tech/docs/introduction/regions/). -// For more information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). -func (c Client) CreateProjectEndpoint(projectID string, cfg EndpointCreateRequest) (EndpointOperations, error) { - var v EndpointOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints", "POST", cfg, &v); err != nil { - return EndpointOperations{}, err +// RestoreProjectBranch Restores a branch to an earlier state in its own or another branch's history +func (c Client) RestoreProjectBranch(projectID string, branchID string, cfg BranchRestoreRequest) (BranchOperations, error) { + var v BranchOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/restore", "POST", cfg, &v); err != nil { + return BranchOperations{}, err } return v, nil } -// DeleteProjectEndpoint Delete the specified compute endpoint. -// A compute endpoint is a Neon compute instance. -// Deleting a compute endpoint drops existing network connections to the compute endpoint. -// The deletion is completed when last operation in the chain finishes successfully. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain an `endpoint_id` by listing your project's compute endpoints. -// An `endpoint_id` has an `ep-` prefix. -// For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). -func (c Client) DeleteProjectEndpoint(projectID string, endpointID string) (EndpointOperations, error) { - var v EndpointOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID, "DELETE", nil, &v); err != nil { - return EndpointOperations{}, err +// RevokeApiKey Revokes the specified API key. +// An API key that is no longer needed can be revoked. +// This action cannot be reversed. +// You can obtain `key_id` values by listing the API keys for your Neon account. +// API keys can also be managed in the Neon Console. +// See [Manage API keys](https://neon.tech/docs/manage/api-keys/). +func (c Client) RevokeApiKey(keyID int64) (ApiKeyRevokeResponse, error) { + var v ApiKeyRevokeResponse + if err := c.requestHandler(c.baseURL+"/api_keys/"+strconv.FormatInt(keyID, 10), "DELETE", nil, &v); err != nil { + return ApiKeyRevokeResponse{}, err } return v, nil } -// GetProjectEndpoint Retrieves information about the specified compute endpoint. -// A compute endpoint is a Neon compute instance. +// RevokePermissionFromProject Revokes project access from the user associted with the specified permisison `id`. You can retrieve a user's permission `id` by listing project access. +func (c Client) RevokePermissionFromProject(projectID string, permissionID string) (ProjectPermission, error) { + var v ProjectPermission + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/permissions/"+permissionID, "DELETE", nil, &v); err != nil { + return ProjectPermission{}, err + } + return v, nil +} + +// SetDefaultProjectBranch Sets the specified branch as the project's default branch. +// The default designation is automatically removed from the previous default branch. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain an `endpoint_id` by listing your project's compute endpoints. -// An `endpoint_id` has an `ep-` prefix. -// For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). -func (c Client) GetProjectEndpoint(projectID string, endpointID string) (EndpointResponse, error) { - var v EndpointResponse - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID, "GET", nil, &v); err != nil { - return EndpointResponse{}, err +// You can obtain the `branch_id` by listing the project's branches. +// For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). +func (c Client) SetDefaultProjectBranch(projectID string, branchID string) (BranchOperations, error) { + var v BranchOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/set_as_default", "POST", nil, &v); err != nil { + return BranchOperations{}, err } return v, nil } -// UpdateProjectEndpoint Updates the specified compute endpoint. +// SetPrimaryProjectBranch DEPRECATED. Use `/set_as_default` endpoint. +// Sets the specified branch as the project's primary branch. +// The primary designation is automatically removed from the previous primary branch. // You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain an `endpoint_id` and `branch_id` by listing your project's compute endpoints. -// An `endpoint_id` has an `ep-` prefix. A `branch_id` has a `br-` prefix. -// For more information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). -// If the returned list of operations is not empty, the compute endpoint is not ready to use. -// The client must wait for the last operation to finish before using the compute endpoint. -// If the compute endpoint was idle before the update, it becomes active for a short period of time, -// and the control plane suspends it again after the update. -func (c Client) UpdateProjectEndpoint(projectID string, endpointID string, cfg EndpointUpdateRequest) (EndpointOperations, error) { - var v EndpointOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID, "PATCH", cfg, &v); err != nil { - return EndpointOperations{}, err +// You can obtain the `branch_id` by listing the project's branches. +// For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). +func (c Client) SetPrimaryProjectBranch(projectID string, branchID string) (BranchOperations, error) { + var v BranchOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/set_as_primary", "POST", nil, &v); err != nil { + return BranchOperations{}, err } return v, nil } @@ -747,148 +831,64 @@ func (c Client) SuspendProjectEndpoint(projectID string, endpointID string) (End return v, nil } -// RestartProjectEndpoint Restart the specified compute endpoint: suspend immediately followed by start operations. -// You can obtain a `project_id` by listing the projects for your Neon account. -// You can obtain an `endpoint_id` by listing your project's compute endpoints. -// An `endpoint_id` has an `ep-` prefix. -// For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). -func (c Client) RestartProjectEndpoint(projectID string, endpointID string) (EndpointOperations, error) { - var v EndpointOperations - if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID+"/restart", "POST", nil, &v); err != nil { - return EndpointOperations{}, err - } - return v, nil -} - -// GetConsumptionHistoryPerAccount Retrieves consumption metrics for Scale and Business plan accounts. History begins at the time of upgrade. -// Available for Scale and Business plan users only. -func (c Client) GetConsumptionHistoryPerAccount(from time.Time, to time.Time, granularity ConsumptionHistoryGranularity, orgID *string, includeV1Metrics *bool) (ConsumptionHistoryPerAccountResponse, error) { - var ( - queryElements []string - query string - ) - queryElements = append(queryElements, "from="+from.Format(time.RFC3339)) - queryElements = append(queryElements, "to="+to.Format(time.RFC3339)) - queryElements = append(queryElements, "granularity="+string(granularity)) - if orgID != nil { - queryElements = append(queryElements, "org_id="+*orgID) - } - if includeV1Metrics != nil { - queryElements = append(queryElements, "include_v1_metrics="+func(includeV1Metrics bool) string { - if includeV1Metrics { - return "true" - } - return "false" - }(*includeV1Metrics)) - } - if len(queryElements) > 0 { - query = "?" + strings.Join(queryElements, "&") - } - var v ConsumptionHistoryPerAccountResponse - if err := c.requestHandler(c.baseURL+"/consumption_history/account"+query, "GET", nil, &v); err != nil { - return ConsumptionHistoryPerAccountResponse{}, err - } - return v, nil -} - -// GetConsumptionHistoryPerProject Retrieves consumption metrics for Scale and Business plan projects. History begins at the time of upgrade. -// Available for Scale and Business plan users only. -// Issuing a call to this API does not wake a project's compute endpoint. -func (c Client) GetConsumptionHistoryPerProject(cursor *string, limit *int, projectIDs []string, from time.Time, to time.Time, granularity ConsumptionHistoryGranularity, orgID *string, includeV1Metrics *bool) (GetConsumptionHistoryPerProjectRespObj, error) { - var ( - queryElements []string - query string - ) - queryElements = append(queryElements, "from="+from.Format(time.RFC3339)) - queryElements = append(queryElements, "to="+to.Format(time.RFC3339)) - queryElements = append(queryElements, "granularity="+string(granularity)) - if cursor != nil { - queryElements = append(queryElements, "cursor="+*cursor) - } - if limit != nil { - queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) - } - if len(projectIDs) > 0 { - queryElements = append(queryElements, "project_ids="+strings.Join(projectIDs, ",")) - } - if orgID != nil { - queryElements = append(queryElements, "org_id="+*orgID) - } - if includeV1Metrics != nil { - queryElements = append(queryElements, "include_v1_metrics="+func(includeV1Metrics bool) string { - if includeV1Metrics { - return "true" - } - return "false" - }(*includeV1Metrics)) - } - if len(queryElements) > 0 { - query = "?" + strings.Join(queryElements, "&") - } - var v GetConsumptionHistoryPerProjectRespObj - if err := c.requestHandler(c.baseURL+"/consumption_history/projects"+query, "GET", nil, &v); err != nil { - return GetConsumptionHistoryPerProjectRespObj{}, err +// TransferProjectsFromUserToOrg Transfers selected projects, identified by their IDs, from your personal account to a specified organization. +// This API is only available for early access users. +func (c Client) TransferProjectsFromUserToOrg(cfg TransferProjectsToOrganizationRequest) (EmptyResponse, error) { + var v EmptyResponse + if err := c.requestHandler(c.baseURL+"/users/me/projects/transfer", "POST", cfg, &v); err != nil { + return EmptyResponse{}, err } return v, nil } -// ListProjectsConsumption Retrieves consumption metrics for each project for the current billing period. -// For usage information, see [Retrieving metrics for all projects](https://neon.tech/docs/guides/partner-billing#retrieving-metrics-for-all-projects). -// Issuing a call to this API does not wake a project's compute endpoint. -func (c Client) ListProjectsConsumption(cursor *string, limit *int, from *time.Time, to *time.Time, orgID *string) (ListProjectsConsumptionRespObj, error) { - var ( - queryElements []string - query string - ) - if cursor != nil { - queryElements = append(queryElements, "cursor="+*cursor) - } - if limit != nil { - queryElements = append(queryElements, "limit="+strconv.FormatInt(int64(*limit), 10)) - } - if from != nil { - queryElements = append(queryElements, "from="+from.Format(time.RFC3339)) - } - if to != nil { - queryElements = append(queryElements, "to="+to.Format(time.RFC3339)) - } - if orgID != nil { - queryElements = append(queryElements, "org_id="+*orgID) - } - if len(queryElements) > 0 { - query = "?" + strings.Join(queryElements, "&") - } - var v ListProjectsConsumptionRespObj - if err := c.requestHandler(c.baseURL+"/consumption/projects"+query, "GET", nil, &v); err != nil { - return ListProjectsConsumptionRespObj{}, err +// UpdateProject Updates the specified project. +// You can obtain a `project_id` by listing the projects for your Neon account. +// Neon permits updating the project name only. +func (c Client) UpdateProject(projectID string, cfg ProjectUpdateRequest) (UpdateProjectRespObj, error) { + var v UpdateProjectRespObj + if err := c.requestHandler(c.baseURL+"/projects/"+projectID, "PATCH", cfg, &v); err != nil { + return UpdateProjectRespObj{}, err } return v, nil } -// GetCurrentUserInfo Retrieves information about the current Neon user account. -func (c Client) GetCurrentUserInfo() (CurrentUserInfoResponse, error) { - var v CurrentUserInfoResponse - if err := c.requestHandler(c.baseURL+"/users/me", "GET", nil, &v); err != nil { - return CurrentUserInfoResponse{}, err +// UpdateProjectBranch Updates the specified branch. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain the `branch_id` by listing the project's branches. +// For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). +func (c Client) UpdateProjectBranch(projectID string, branchID string, cfg BranchUpdateRequest) (BranchOperations, error) { + var v BranchOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID, "PATCH", cfg, &v); err != nil { + return BranchOperations{}, err } return v, nil } -// GetCurrentUserOrganizations Retrieves information about the current Neon user's organizations -func (c Client) GetCurrentUserOrganizations() (OrganizationsResponse, error) { - var v OrganizationsResponse - if err := c.requestHandler(c.baseURL+"/users/me/organizations", "GET", nil, &v); err != nil { - return OrganizationsResponse{}, err +// UpdateProjectBranchDatabase Updates the specified database in the branch. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain the `branch_id` and `database_name` by listing the branch's databases. +// For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). +func (c Client) UpdateProjectBranchDatabase(projectID string, branchID string, databaseName string, cfg DatabaseUpdateRequest) (DatabaseOperations, error) { + var v DatabaseOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/branches/"+branchID+"/databases/"+databaseName, "PATCH", cfg, &v); err != nil { + return DatabaseOperations{}, err } return v, nil } -// TransferProjectsFromUserToOrg Transfers selected projects, identified by their IDs, from your personal account to a specified organization. -// This API is only available for early access users. -func (c Client) TransferProjectsFromUserToOrg(cfg TransferProjectsToOrganizationRequest) (EmptyResponse, error) { - var v EmptyResponse - if err := c.requestHandler(c.baseURL+"/users/me/projects/transfer", "POST", cfg, &v); err != nil { - return EmptyResponse{}, err +// UpdateProjectEndpoint Updates the specified compute endpoint. +// You can obtain a `project_id` by listing the projects for your Neon account. +// You can obtain an `endpoint_id` and `branch_id` by listing your project's compute endpoints. +// An `endpoint_id` has an `ep-` prefix. A `branch_id` has a `br-` prefix. +// For more information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). +// If the returned list of operations is not empty, the compute endpoint is not ready to use. +// The client must wait for the last operation to finish before using the compute endpoint. +// If the compute endpoint was idle before the update, it becomes active for a short period of time, +// and the control plane suspends it again after the update. +func (c Client) UpdateProjectEndpoint(projectID string, endpointID string, cfg EndpointUpdateRequest) (EndpointOperations, error) { + var v EndpointOperations + if err := c.requestHandler(c.baseURL+"/projects/"+projectID+"/endpoints/"+endpointID, "PATCH", cfg, &v); err != nil { + return EndpointOperations{}, err } return v, nil } @@ -1013,15 +1013,15 @@ type BillingAccount struct { type BillingPaymentMethod string const ( - BillingPaymentMethodVercelMp BillingPaymentMethod = "vercel_mp" - BillingPaymentMethodSponsorship BillingPaymentMethod = "sponsorship" - BillingPaymentMethodStripe BillingPaymentMethod = "stripe" - BillingPaymentMethodDirectPayment BillingPaymentMethod = "direct_payment" + BillingPaymentMethodUNKNOWN BillingPaymentMethod = "UNKNOWN" BillingPaymentMethodAwsMp BillingPaymentMethod = "aws_mp" + BillingPaymentMethodDirectPayment BillingPaymentMethod = "direct_payment" + BillingPaymentMethodNone BillingPaymentMethod = "none" + BillingPaymentMethodSponsorship BillingPaymentMethod = "sponsorship" BillingPaymentMethodStaff BillingPaymentMethod = "staff" + BillingPaymentMethodStripe BillingPaymentMethod = "stripe" BillingPaymentMethodTrial BillingPaymentMethod = "trial" - BillingPaymentMethodUNKNOWN BillingPaymentMethod = "UNKNOWN" - BillingPaymentMethodNone BillingPaymentMethod = "none" + BillingPaymentMethodVercelMp BillingPaymentMethod = "vercel_mp" ) // BillingSubscriptionType Type of subscription to Neon Cloud. @@ -1029,13 +1029,13 @@ const ( type BillingSubscriptionType string const ( + BillingSubscriptionTypeUNKNOWN BillingSubscriptionType = "UNKNOWN" + BillingSubscriptionTypeAwsMarketplace BillingSubscriptionType = "aws_marketplace" + BillingSubscriptionTypeBusiness BillingSubscriptionType = "business" + BillingSubscriptionTypeDirectSales BillingSubscriptionType = "direct_sales" BillingSubscriptionTypeFreeV2 BillingSubscriptionType = "free_v2" BillingSubscriptionTypeLaunch BillingSubscriptionType = "launch" BillingSubscriptionTypeScale BillingSubscriptionType = "scale" - BillingSubscriptionTypeBusiness BillingSubscriptionType = "business" - BillingSubscriptionTypeUNKNOWN BillingSubscriptionType = "UNKNOWN" - BillingSubscriptionTypeDirectSales BillingSubscriptionType = "direct_sales" - BillingSubscriptionTypeAwsMarketplace BillingSubscriptionType = "aws_marketplace" ) type Branch struct { @@ -1205,8 +1205,8 @@ type ConnectionURIsResponse struct { type ConsumptionHistoryGranularity string const ( - ConsumptionHistoryGranularityHourly ConsumptionHistoryGranularity = "hourly" ConsumptionHistoryGranularityDaily ConsumptionHistoryGranularity = "daily" + ConsumptionHistoryGranularityHourly ConsumptionHistoryGranularity = "hourly" ConsumptionHistoryGranularityMonthly ConsumptionHistoryGranularity = "monthly" ) @@ -1448,9 +1448,9 @@ type EndpointSettingsData struct { type EndpointState string const ( - EndpointStateInit EndpointState = "init" EndpointStateActive EndpointState = "active" EndpointStateIdle EndpointState = "idle" + EndpointStateInit EndpointState = "init" ) // EndpointType The compute endpoint type. Either `read_write` or `read_only`. @@ -1511,8 +1511,8 @@ const ( IdentityProviderIdGithub IdentityProviderId = "github" IdentityProviderIdGoogle IdentityProviderId = "google" IdentityProviderIdHasura IdentityProviderId = "hasura" - IdentityProviderIdMicrosoft IdentityProviderId = "microsoft" IdentityProviderIdKeycloak IdentityProviderId = "keycloak" + IdentityProviderIdMicrosoft IdentityProviderId = "microsoft" IdentityProviderIdTest IdentityProviderId = "test" ) @@ -1570,24 +1570,24 @@ type Operation struct { type OperationAction string const ( - OperationActionStartCompute OperationAction = "start_compute" - OperationActionTenantAttach OperationAction = "tenant_attach" - OperationActionTenantReattach OperationAction = "tenant_reattach" + OperationActionApplyConfig OperationAction = "apply_config" OperationActionApplyStorageConfig OperationAction = "apply_storage_config" OperationActionCheckAvailability OperationAction = "check_availability" - OperationActionReplaceSafekeeper OperationAction = "replace_safekeeper" - OperationActionSwitchPageserver OperationAction = "switch_pageserver" + OperationActionCreateBranch OperationAction = "create_branch" OperationActionCreateCompute OperationAction = "create_compute" OperationActionCreateTimeline OperationAction = "create_timeline" - OperationActionSuspendCompute OperationAction = "suspend_compute" - OperationActionCreateBranch OperationAction = "create_branch" - OperationActionDisableMaintenance OperationAction = "disable_maintenance" - OperationActionApplyConfig OperationAction = "apply_config" OperationActionDeleteTimeline OperationAction = "delete_timeline" - OperationActionTenantIgnore OperationAction = "tenant_ignore" - OperationActionTenantDetach OperationAction = "tenant_detach" - OperationActionPrepareSecondaryPageserver OperationAction = "prepare_secondary_pageserver" OperationActionDetachParentBranch OperationAction = "detach_parent_branch" + OperationActionDisableMaintenance OperationAction = "disable_maintenance" + OperationActionPrepareSecondaryPageserver OperationAction = "prepare_secondary_pageserver" + OperationActionReplaceSafekeeper OperationAction = "replace_safekeeper" + OperationActionStartCompute OperationAction = "start_compute" + OperationActionSuspendCompute OperationAction = "suspend_compute" + OperationActionSwitchPageserver OperationAction = "switch_pageserver" + OperationActionTenantAttach OperationAction = "tenant_attach" + OperationActionTenantDetach OperationAction = "tenant_detach" + OperationActionTenantIgnore OperationAction = "tenant_ignore" + OperationActionTenantReattach OperationAction = "tenant_reattach" ) type OperationResponse struct { @@ -1598,14 +1598,14 @@ type OperationResponse struct { type OperationStatus string const ( - OperationStatusRunning OperationStatus = "running" - OperationStatusFinished OperationStatus = "finished" - OperationStatusFailed OperationStatus = "failed" - OperationStatusError OperationStatus = "error" - OperationStatusCancelling OperationStatus = "cancelling" OperationStatusCancelled OperationStatus = "cancelled" - OperationStatusSkipped OperationStatus = "skipped" + OperationStatusCancelling OperationStatus = "cancelling" + OperationStatusError OperationStatus = "error" + OperationStatusFailed OperationStatus = "failed" + OperationStatusFinished OperationStatus = "finished" + OperationStatusRunning OperationStatus = "running" OperationStatusScheduling OperationStatus = "scheduling" + OperationStatusSkipped OperationStatus = "skipped" ) type OperationsResponse struct { @@ -1954,8 +1954,8 @@ type ProjectsResponse struct { type Provisioner string const ( - ProvisionerK8sPod Provisioner = "k8s-pod" ProvisionerK8sNeonvm Provisioner = "k8s-neonvm" + ProvisionerK8sPod Provisioner = "k8s-pod" ) type Role struct { diff --git a/sdk_test.go b/sdk_test.go index 079ded5..e01de70 100644 --- a/sdk_test.go +++ b/sdk_test.go @@ -450,53 +450,6 @@ func TestError_httpResp(t *testing.T) { } } -func Test_client_ListApiKeys(t *testing.T) { - deserializeResp := func(s string) []ApiKeysListResponseItem { - var v []ApiKeysListResponseItem - if err := json.Unmarshal([]byte(s), &v); err != nil { - panic(err) - } - return v - } - tests := []struct { - name string - apiKey string - want []ApiKeysListResponseItem - wantErr bool - }{ - { - name: "happy path", - apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/api_keys"]["GET"].Content), - wantErr: false, - }, - { - name: "unhappy path", - apiKey: "invalidApiKey", - want: nil, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run( - tt.name, func(t *testing.T) { - c, err := NewClient(Config{tt.apiKey, NewMockHTTPClient()}) - if err != nil { - panic(err) - } - got, err := c.ListApiKeys() - if (err != nil) != tt.wantErr { - t.Errorf("ListApiKeys() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListApiKeys() got = %v, want %v", got, tt.want) - } - }, - ) - } -} - func Test_client_CreateApiKey(t *testing.T) { deserializeResp := func(s string) ApiKeyCreateResponse { var v ApiKeyCreateResponse @@ -554,40 +507,40 @@ func Test_client_CreateApiKey(t *testing.T) { } } -func Test_client_RevokeApiKey(t *testing.T) { - deserializeResp := func(s string) ApiKeyRevokeResponse { - var v ApiKeyRevokeResponse +func Test_client_CreateProject(t *testing.T) { + deserializeResp := func(s string) CreatedProject { + var v CreatedProject if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - keyID int64 + cfg ProjectCreateRequest } tests := []struct { name string args args apiKey string - want ApiKeyRevokeResponse + want CreatedProject wantErr bool }{ { name: "happy path", args: args{ - keyID: 1, + cfg: ProjectCreateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/api_keys/{key_id}"]["DELETE"].Content), + want: deserializeResp(endpointResponseExamples["/projects"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - keyID: 1, + cfg: ProjectCreateRequest{}, }, apiKey: "invalidApiKey", - want: ApiKeyRevokeResponse{}, + want: CreatedProject{}, wantErr: true, }, } @@ -598,56 +551,56 @@ func Test_client_RevokeApiKey(t *testing.T) { if err != nil { panic(err) } - got, err := c.RevokeApiKey(tt.args.keyID) + got, err := c.CreateProject(tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("RevokeApiKey() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CreateProject() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("RevokeApiKey() got = %v, want %v", got, tt.want) + t.Errorf("CreateProject() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetProjectOperation(t *testing.T) { - deserializeResp := func(s string) OperationResponse { - var v OperationResponse +func Test_client_CreateProjectBranch(t *testing.T) { + deserializeResp := func(s string) CreatedBranch { + var v CreatedBranch if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - operationID string + projectID string + cfg *CreateProjectBranchReqObj } tests := []struct { name string args args apiKey string - want OperationResponse + want CreatedBranch wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - operationID: "foo", + projectID: "foo", + cfg: nil, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/operations/{operation_id}"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - operationID: "foo", + projectID: "foo", + cfg: nil, }, apiKey: "invalidApiKey", - want: OperationResponse{}, + want: CreatedBranch{}, wantErr: true, }, } @@ -658,62 +611,59 @@ func Test_client_GetProjectOperation(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectOperation(tt.args.projectID, tt.args.operationID) + got, err := c.CreateProjectBranch(tt.args.projectID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("GetProjectOperation() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CreateProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectOperation() got = %v, want %v", got, tt.want) + t.Errorf("CreateProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListProjects(t *testing.T) { - deserializeResp := func(s string) ListProjectsRespObj { - var v ListProjectsRespObj +func Test_client_CreateProjectBranchDatabase(t *testing.T) { + deserializeResp := func(s string) DatabaseOperations { + var v DatabaseOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - cursor *string - limit *int - search *string - orgID *string + projectID string + branchID string + cfg DatabaseCreateRequest } tests := []struct { name string args args apiKey string - want ListProjectsRespObj + want DatabaseOperations wantErr bool }{ { name: "happy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - search: createPointer("foo"), - orgID: createPointer("foo"), + projectID: "foo", + branchID: "foo", + cfg: DatabaseCreateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - search: createPointer("foo"), - orgID: createPointer("foo"), + projectID: "foo", + branchID: "foo", + cfg: DatabaseCreateRequest{}, }, apiKey: "invalidApiKey", - want: ListProjectsRespObj{}, + want: DatabaseOperations{}, wantErr: true, }, } @@ -724,53 +674,59 @@ func Test_client_ListProjects(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjects(tt.args.cursor, tt.args.limit, tt.args.search, tt.args.orgID) + got, err := c.CreateProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("ListProjects() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CreateProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjects() got = %v, want %v", got, tt.want) + t.Errorf("CreateProjectBranchDatabase() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_CreateProject(t *testing.T) { - deserializeResp := func(s string) CreatedProject { - var v CreatedProject +func Test_client_CreateProjectBranchRole(t *testing.T) { + deserializeResp := func(s string) RoleOperations { + var v RoleOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - cfg ProjectCreateRequest + projectID string + branchID string + cfg RoleCreateRequest } tests := []struct { name string args args apiKey string - want CreatedProject + want RoleOperations wantErr bool }{ { name: "happy path", args: args{ - cfg: ProjectCreateRequest{}, + projectID: "foo", + branchID: "foo", + cfg: RoleCreateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - cfg: ProjectCreateRequest{}, + projectID: "foo", + branchID: "foo", + cfg: RoleCreateRequest{}, }, apiKey: "invalidApiKey", - want: CreatedProject{}, + want: RoleOperations{}, wantErr: true, }, } @@ -781,59 +737,56 @@ func Test_client_CreateProject(t *testing.T) { if err != nil { panic(err) } - got, err := c.CreateProject(tt.args.cfg) + got, err := c.CreateProjectBranchRole(tt.args.projectID, tt.args.branchID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("CreateProject() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CreateProjectBranchRole() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateProject() got = %v, want %v", got, tt.want) + t.Errorf("CreateProjectBranchRole() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListSharedProjects(t *testing.T) { - deserializeResp := func(s string) ListSharedProjectsRespObj { - var v ListSharedProjectsRespObj +func Test_client_CreateProjectEndpoint(t *testing.T) { + deserializeResp := func(s string) EndpointOperations { + var v EndpointOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - cursor *string - limit *int - search *string + projectID string + cfg EndpointCreateRequest } tests := []struct { name string args args apiKey string - want ListSharedProjectsRespObj + want EndpointOperations wantErr bool }{ { name: "happy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - search: createPointer("foo"), + projectID: "foo", + cfg: EndpointCreateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/shared"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - search: createPointer("foo"), + projectID: "foo", + cfg: EndpointCreateRequest{}, }, apiKey: "invalidApiKey", - want: ListSharedProjectsRespObj{}, + want: EndpointOperations{}, wantErr: true, }, } @@ -844,13 +797,13 @@ func Test_client_ListSharedProjects(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListSharedProjects(tt.args.cursor, tt.args.limit, tt.args.search) + got, err := c.CreateProjectEndpoint(tt.args.projectID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("ListSharedProjects() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CreateProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListSharedProjects() got = %v, want %v", got, tt.want) + t.Errorf("CreateProjectEndpoint() got = %v, want %v", got, tt.want) } }, ) @@ -914,9 +867,9 @@ func Test_client_DeleteProject(t *testing.T) { } } -func Test_client_GetProject(t *testing.T) { - deserializeResp := func(s string) ProjectResponse { - var v ProjectResponse +func Test_client_DeleteProjectBranch(t *testing.T) { + deserializeResp := func(s string) BranchOperations { + var v BranchOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -924,30 +877,33 @@ func Test_client_GetProject(t *testing.T) { } type args struct { projectID string + branchID string } tests := []struct { name string args args apiKey string - want ProjectResponse + want BranchOperations wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", + branchID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}"]["DELETE"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", + branchID: "foo", }, apiKey: "invalidApiKey", - want: ProjectResponse{}, + want: BranchOperations{}, wantErr: true, }, } @@ -958,56 +914,59 @@ func Test_client_GetProject(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProject(tt.args.projectID) + got, err := c.DeleteProjectBranch(tt.args.projectID, tt.args.branchID) if (err != nil) != tt.wantErr { - t.Errorf("GetProject() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("DeleteProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProject() got = %v, want %v", got, tt.want) + t.Errorf("DeleteProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_UpdateProject(t *testing.T) { - deserializeResp := func(s string) UpdateProjectRespObj { - var v UpdateProjectRespObj +func Test_client_DeleteProjectBranchDatabase(t *testing.T) { + deserializeResp := func(s string) DatabaseOperations { + var v DatabaseOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - cfg ProjectUpdateRequest + projectID string + branchID string + databaseName string } tests := []struct { name string args args apiKey string - want UpdateProjectRespObj + want DatabaseOperations wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - cfg: ProjectUpdateRequest{}, + projectID: "foo", + branchID: "foo", + databaseName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}"]["PATCH"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases/{database_name}"]["DELETE"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - cfg: ProjectUpdateRequest{}, + projectID: "foo", + branchID: "foo", + databaseName: "foo", }, apiKey: "invalidApiKey", - want: UpdateProjectRespObj{}, + want: DatabaseOperations{}, wantErr: true, }, } @@ -1018,22 +977,22 @@ func Test_client_UpdateProject(t *testing.T) { if err != nil { panic(err) } - got, err := c.UpdateProject(tt.args.projectID, tt.args.cfg) + got, err := c.DeleteProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.databaseName) if (err != nil) != tt.wantErr { - t.Errorf("UpdateProject() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("DeleteProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateProject() got = %v, want %v", got, tt.want) + t.Errorf("DeleteProjectBranchDatabase() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListProjectOperations(t *testing.T) { - deserializeResp := func(s string) ListOperations { - var v ListOperations +func Test_client_DeleteProjectBranchRole(t *testing.T) { + deserializeResp := func(s string) RoleOperations { + var v RoleOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -1041,36 +1000,36 @@ func Test_client_ListProjectOperations(t *testing.T) { } type args struct { projectID string - cursor *string - limit *int + branchID string + roleName string } tests := []struct { name string args args apiKey string - want ListOperations + want RoleOperations wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", - cursor: createPointer("foo"), - limit: createPointer(1), + branchID: "foo", + roleName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/operations"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}"]["DELETE"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", - cursor: createPointer("foo"), - limit: createPointer(1), + branchID: "foo", + roleName: "foo", }, apiKey: "invalidApiKey", - want: ListOperations{}, + want: RoleOperations{}, wantErr: true, }, } @@ -1081,13 +1040,73 @@ func Test_client_ListProjectOperations(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjectOperations(tt.args.projectID, tt.args.cursor, tt.args.limit) + got, err := c.DeleteProjectBranchRole(tt.args.projectID, tt.args.branchID, tt.args.roleName) if (err != nil) != tt.wantErr { - t.Errorf("ListProjectOperations() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("DeleteProjectBranchRole() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjectOperations() got = %v, want %v", got, tt.want) + t.Errorf("DeleteProjectBranchRole() got = %v, want %v", got, tt.want) + } + }, + ) + } +} + +func Test_client_DeleteProjectEndpoint(t *testing.T) { + deserializeResp := func(s string) EndpointOperations { + var v EndpointOperations + if err := json.Unmarshal([]byte(s), &v); err != nil { + panic(err) + } + return v + } + type args struct { + projectID string + endpointID string + } + tests := []struct { + name string + args args + apiKey string + want EndpointOperations + wantErr bool + }{ + { + name: "happy path", + args: args{ + projectID: "foo", + endpointID: "foo", + }, + apiKey: "foo", + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}"]["DELETE"].Content), + wantErr: false, + }, + { + name: "unhappy path", + args: args{ + projectID: "foo", + endpointID: "foo", + }, + apiKey: "invalidApiKey", + want: EndpointOperations{}, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + c, err := NewClient(Config{tt.apiKey, NewMockHTTPClient()}) + if err != nil { + panic(err) + } + got, err := c.DeleteProjectEndpoint(tt.args.projectID, tt.args.endpointID) + if (err != nil) != tt.wantErr { + t.Errorf("DeleteProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("DeleteProjectEndpoint() got = %v, want %v", got, tt.want) } }, ) @@ -1166,40 +1185,52 @@ func Test_client_GetConnectionURI(t *testing.T) { } } -func Test_client_ListProjectBranches(t *testing.T) { - deserializeResp := func(s string) ListProjectBranchesRespObj { - var v ListProjectBranchesRespObj +func Test_client_GetConsumptionHistoryPerAccount(t *testing.T) { + deserializeResp := func(s string) ConsumptionHistoryPerAccountResponse { + var v ConsumptionHistoryPerAccountResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string + from time.Time + to time.Time + granularity ConsumptionHistoryGranularity + orgID *string + includeV1Metrics *bool } tests := []struct { name string args args apiKey string - want ListProjectBranchesRespObj + want ConsumptionHistoryPerAccountResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", + from: time.Time{}, + to: time.Time{}, + granularity: "foo", + orgID: createPointer("foo"), + includeV1Metrics: createPointer(true), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/consumption_history/account"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", + from: time.Time{}, + to: time.Time{}, + granularity: "foo", + orgID: createPointer("foo"), + includeV1Metrics: createPointer(true), }, apiKey: "invalidApiKey", - want: ListProjectBranchesRespObj{}, + want: ConsumptionHistoryPerAccountResponse{}, wantErr: true, }, } @@ -1210,56 +1241,74 @@ func Test_client_ListProjectBranches(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjectBranches(tt.args.projectID) + got, err := c.GetConsumptionHistoryPerAccount(tt.args.from, tt.args.to, tt.args.granularity, tt.args.orgID, tt.args.includeV1Metrics) if (err != nil) != tt.wantErr { - t.Errorf("ListProjectBranches() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetConsumptionHistoryPerAccount() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjectBranches() got = %v, want %v", got, tt.want) + t.Errorf("GetConsumptionHistoryPerAccount() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_CreateProjectBranch(t *testing.T) { - deserializeResp := func(s string) CreatedBranch { - var v CreatedBranch +func Test_client_GetConsumptionHistoryPerProject(t *testing.T) { + deserializeResp := func(s string) GetConsumptionHistoryPerProjectRespObj { + var v GetConsumptionHistoryPerProjectRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - cfg *CreateProjectBranchReqObj + cursor *string + limit *int + projectIDs []string + from time.Time + to time.Time + granularity ConsumptionHistoryGranularity + orgID *string + includeV1Metrics *bool } tests := []struct { name string args args apiKey string - want CreatedBranch + want GetConsumptionHistoryPerProjectRespObj wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - cfg: nil, + cursor: createPointer("foo"), + limit: createPointer(1), + projectIDs: []string{"foo"}, + from: time.Time{}, + to: time.Time{}, + granularity: "foo", + orgID: createPointer("foo"), + includeV1Metrics: createPointer(true), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/consumption_history/projects"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - cfg: nil, + cursor: createPointer("foo"), + limit: createPointer(1), + projectIDs: []string{"foo"}, + from: time.Time{}, + to: time.Time{}, + granularity: "foo", + orgID: createPointer("foo"), + includeV1Metrics: createPointer(true), }, apiKey: "invalidApiKey", - want: CreatedBranch{}, + want: GetConsumptionHistoryPerProjectRespObj{}, wantErr: true, }, } @@ -1270,56 +1319,43 @@ func Test_client_CreateProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.CreateProjectBranch(tt.args.projectID, tt.args.cfg) + got, err := c.GetConsumptionHistoryPerProject(tt.args.cursor, tt.args.limit, tt.args.projectIDs, tt.args.from, tt.args.to, tt.args.granularity, tt.args.orgID, tt.args.includeV1Metrics) if (err != nil) != tt.wantErr { - t.Errorf("CreateProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetConsumptionHistoryPerProject() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetConsumptionHistoryPerProject() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_DeleteProjectBranch(t *testing.T) { - deserializeResp := func(s string) BranchOperations { - var v BranchOperations +func Test_client_GetCurrentUserInfo(t *testing.T) { + deserializeResp := func(s string) CurrentUserInfoResponse { + var v CurrentUserInfoResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } - type args struct { - projectID string - branchID string - } tests := []struct { name string - args args apiKey string - want BranchOperations + want CurrentUserInfoResponse wantErr bool }{ { - name: "happy path", - args: args{ - projectID: "foo", - branchID: "foo", - }, + name: "happy path", apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}"]["DELETE"].Content), + want: deserializeResp(endpointResponseExamples["/users/me"]["GET"].Content), wantErr: false, }, { - name: "unhappy path", - args: args{ - projectID: "foo", - branchID: "foo", - }, + name: "unhappy path", apiKey: "invalidApiKey", - want: BranchOperations{}, + want: CurrentUserInfoResponse{}, wantErr: true, }, } @@ -1330,56 +1366,43 @@ func Test_client_DeleteProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.DeleteProjectBranch(tt.args.projectID, tt.args.branchID) + got, err := c.GetCurrentUserInfo() if (err != nil) != tt.wantErr { - t.Errorf("DeleteProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetCurrentUserInfo() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("DeleteProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetCurrentUserInfo() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetProjectBranch(t *testing.T) { - deserializeResp := func(s string) GetProjectBranchRespObj { - var v GetProjectBranchRespObj +func Test_client_GetCurrentUserOrganizations(t *testing.T) { + deserializeResp := func(s string) OrganizationsResponse { + var v OrganizationsResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } - type args struct { - projectID string - branchID string - } tests := []struct { name string - args args apiKey string - want GetProjectBranchRespObj + want OrganizationsResponse wantErr bool }{ { - name: "happy path", - args: args{ - projectID: "foo", - branchID: "foo", - }, + name: "happy path", apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/users/me/organizations"]["GET"].Content), wantErr: false, }, { - name: "unhappy path", - args: args{ - projectID: "foo", - branchID: "foo", - }, + name: "unhappy path", apiKey: "invalidApiKey", - want: GetProjectBranchRespObj{}, + want: OrganizationsResponse{}, wantErr: true, }, } @@ -1390,22 +1413,22 @@ func Test_client_GetProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectBranch(tt.args.projectID, tt.args.branchID) + got, err := c.GetCurrentUserOrganizations() if (err != nil) != tt.wantErr { - t.Errorf("GetProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetCurrentUserOrganizations() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetCurrentUserOrganizations() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_UpdateProjectBranch(t *testing.T) { - deserializeResp := func(s string) BranchOperations { - var v BranchOperations +func Test_client_GetProject(t *testing.T) { + deserializeResp := func(s string) ProjectResponse { + var v ProjectResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -1413,36 +1436,30 @@ func Test_client_UpdateProjectBranch(t *testing.T) { } type args struct { projectID string - branchID string - cfg BranchUpdateRequest } tests := []struct { name string args args apiKey string - want BranchOperations + want ProjectResponse wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", - branchID: "foo", - cfg: BranchUpdateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}"]["PATCH"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", - branchID: "foo", - cfg: BranchUpdateRequest{}, }, apiKey: "invalidApiKey", - want: BranchOperations{}, + want: ProjectResponse{}, wantErr: true, }, } @@ -1453,22 +1470,22 @@ func Test_client_UpdateProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.UpdateProjectBranch(tt.args.projectID, tt.args.branchID, tt.args.cfg) + got, err := c.GetProject(tt.args.projectID) if (err != nil) != tt.wantErr { - t.Errorf("UpdateProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProject() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetProject() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_RestoreProjectBranch(t *testing.T) { - deserializeResp := func(s string) BranchOperations { - var v BranchOperations +func Test_client_GetProjectBranch(t *testing.T) { + deserializeResp := func(s string) GetProjectBranchRespObj { + var v GetProjectBranchRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -1477,13 +1494,12 @@ func Test_client_RestoreProjectBranch(t *testing.T) { type args struct { projectID string branchID string - cfg BranchRestoreRequest } tests := []struct { name string args args apiKey string - want BranchOperations + want GetProjectBranchRespObj wantErr bool }{ { @@ -1491,10 +1507,9 @@ func Test_client_RestoreProjectBranch(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", - cfg: BranchRestoreRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/restore"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}"]["GET"].Content), wantErr: false, }, { @@ -1502,10 +1517,9 @@ func Test_client_RestoreProjectBranch(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", - cfg: BranchRestoreRequest{}, }, apiKey: "invalidApiKey", - want: BranchOperations{}, + want: GetProjectBranchRespObj{}, wantErr: true, }, } @@ -1516,65 +1530,59 @@ func Test_client_RestoreProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.RestoreProjectBranch(tt.args.projectID, tt.args.branchID, tt.args.cfg) + got, err := c.GetProjectBranch(tt.args.projectID, tt.args.branchID) if (err != nil) != tt.wantErr { - t.Errorf("RestoreProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("RestoreProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetProjectBranchSchema(t *testing.T) { - deserializeResp := func(s string) BranchSchemaResponse { - var v BranchSchemaResponse +func Test_client_GetProjectBranchDatabase(t *testing.T) { + deserializeResp := func(s string) DatabaseResponse { + var v DatabaseResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string - dbName string - lsn *string - timestamp *time.Time + projectID string + branchID string + databaseName string } tests := []struct { name string args args apiKey string - want BranchSchemaResponse + want DatabaseResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", - dbName: "foo", - lsn: createPointer("foo"), - timestamp: createPointer(time.Time{}), + projectID: "foo", + branchID: "foo", + databaseName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/schema"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases/{database_name}"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", - dbName: "foo", - lsn: createPointer("foo"), - timestamp: createPointer(time.Time{}), + projectID: "foo", + branchID: "foo", + databaseName: "foo", }, apiKey: "invalidApiKey", - want: BranchSchemaResponse{}, + want: DatabaseResponse{}, wantErr: true, }, } @@ -1585,22 +1593,22 @@ func Test_client_GetProjectBranchSchema(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectBranchSchema(tt.args.projectID, tt.args.branchID, tt.args.dbName, tt.args.lsn, tt.args.timestamp) + got, err := c.GetProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.databaseName) if (err != nil) != tt.wantErr { - t.Errorf("GetProjectBranchSchema() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectBranchSchema() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectBranchDatabase() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_SetPrimaryProjectBranch(t *testing.T) { - deserializeResp := func(s string) BranchOperations { - var v BranchOperations +func Test_client_GetProjectBranchRole(t *testing.T) { + deserializeResp := func(s string) RoleResponse { + var v RoleResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -1609,12 +1617,13 @@ func Test_client_SetPrimaryProjectBranch(t *testing.T) { type args struct { projectID string branchID string + roleName string } tests := []struct { name string args args apiKey string - want BranchOperations + want RoleResponse wantErr bool }{ { @@ -1622,9 +1631,10 @@ func Test_client_SetPrimaryProjectBranch(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", + roleName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/set_as_primary"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}"]["GET"].Content), wantErr: false, }, { @@ -1632,9 +1642,10 @@ func Test_client_SetPrimaryProjectBranch(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", + roleName: "foo", }, apiKey: "invalidApiKey", - want: BranchOperations{}, + want: RoleResponse{}, wantErr: true, }, } @@ -1645,22 +1656,22 @@ func Test_client_SetPrimaryProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.SetPrimaryProjectBranch(tt.args.projectID, tt.args.branchID) + got, err := c.GetProjectBranchRole(tt.args.projectID, tt.args.branchID, tt.args.roleName) if (err != nil) != tt.wantErr { - t.Errorf("SetPrimaryProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectBranchRole() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("SetPrimaryProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectBranchRole() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_SetDefaultProjectBranch(t *testing.T) { - deserializeResp := func(s string) BranchOperations { - var v BranchOperations +func Test_client_GetProjectBranchRolePassword(t *testing.T) { + deserializeResp := func(s string) RolePasswordResponse { + var v RolePasswordResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -1669,12 +1680,13 @@ func Test_client_SetDefaultProjectBranch(t *testing.T) { type args struct { projectID string branchID string + roleName string } tests := []struct { name string args args apiKey string - want BranchOperations + want RolePasswordResponse wantErr bool }{ { @@ -1682,9 +1694,10 @@ func Test_client_SetDefaultProjectBranch(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", + roleName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/set_as_default"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reveal_password"]["GET"].Content), wantErr: false, }, { @@ -1692,9 +1705,10 @@ func Test_client_SetDefaultProjectBranch(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", + roleName: "foo", }, apiKey: "invalidApiKey", - want: BranchOperations{}, + want: RolePasswordResponse{}, wantErr: true, }, } @@ -1705,22 +1719,22 @@ func Test_client_SetDefaultProjectBranch(t *testing.T) { if err != nil { panic(err) } - got, err := c.SetDefaultProjectBranch(tt.args.projectID, tt.args.branchID) + got, err := c.GetProjectBranchRolePassword(tt.args.projectID, tt.args.branchID, tt.args.roleName) if (err != nil) != tt.wantErr { - t.Errorf("SetDefaultProjectBranch() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectBranchRolePassword() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("SetDefaultProjectBranch() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectBranchRolePassword() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListProjectBranchEndpoints(t *testing.T) { - deserializeResp := func(s string) EndpointsResponse { - var v EndpointsResponse +func Test_client_GetProjectBranchSchema(t *testing.T) { + deserializeResp := func(s string) BranchSchemaResponse { + var v BranchSchemaResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -1729,12 +1743,15 @@ func Test_client_ListProjectBranchEndpoints(t *testing.T) { type args struct { projectID string branchID string + dbName string + lsn *string + timestamp *time.Time } tests := []struct { name string args args apiKey string - want EndpointsResponse + want BranchSchemaResponse wantErr bool }{ { @@ -1742,9 +1759,12 @@ func Test_client_ListProjectBranchEndpoints(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", + dbName: "foo", + lsn: createPointer("foo"), + timestamp: createPointer(time.Time{}), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/endpoints"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/schema"]["GET"].Content), wantErr: false, }, { @@ -1752,9 +1772,12 @@ func Test_client_ListProjectBranchEndpoints(t *testing.T) { args: args{ projectID: "foo", branchID: "foo", + dbName: "foo", + lsn: createPointer("foo"), + timestamp: createPointer(time.Time{}), }, apiKey: "invalidApiKey", - want: EndpointsResponse{}, + want: BranchSchemaResponse{}, wantErr: true, }, } @@ -1765,56 +1788,56 @@ func Test_client_ListProjectBranchEndpoints(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjectBranchEndpoints(tt.args.projectID, tt.args.branchID) + got, err := c.GetProjectBranchSchema(tt.args.projectID, tt.args.branchID, tt.args.dbName, tt.args.lsn, tt.args.timestamp) if (err != nil) != tt.wantErr { - t.Errorf("ListProjectBranchEndpoints() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectBranchSchema() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjectBranchEndpoints() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectBranchSchema() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListProjectBranchDatabases(t *testing.T) { - deserializeResp := func(s string) DatabasesResponse { - var v DatabasesResponse +func Test_client_GetProjectEndpoint(t *testing.T) { + deserializeResp := func(s string) EndpointResponse { + var v EndpointResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string + projectID string + endpointID string } tests := []struct { name string args args apiKey string - want DatabasesResponse + want EndpointResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", + projectID: "foo", + endpointID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", + projectID: "foo", + endpointID: "foo", }, apiKey: "invalidApiKey", - want: DatabasesResponse{}, + want: EndpointResponse{}, wantErr: true, }, } @@ -1825,59 +1848,56 @@ func Test_client_ListProjectBranchDatabases(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjectBranchDatabases(tt.args.projectID, tt.args.branchID) + got, err := c.GetProjectEndpoint(tt.args.projectID, tt.args.endpointID) if (err != nil) != tt.wantErr { - t.Errorf("ListProjectBranchDatabases() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjectBranchDatabases() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectEndpoint() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_CreateProjectBranchDatabase(t *testing.T) { - deserializeResp := func(s string) DatabaseOperations { - var v DatabaseOperations +func Test_client_GetProjectOperation(t *testing.T) { + deserializeResp := func(s string) OperationResponse { + var v OperationResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string - cfg DatabaseCreateRequest + projectID string + operationID string } tests := []struct { name string args args apiKey string - want DatabaseOperations + want OperationResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", - cfg: DatabaseCreateRequest{}, + projectID: "foo", + operationID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/operations/{operation_id}"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", - cfg: DatabaseCreateRequest{}, + projectID: "foo", + operationID: "foo", }, apiKey: "invalidApiKey", - want: DatabaseOperations{}, + want: OperationResponse{}, wantErr: true, }, } @@ -1888,59 +1908,43 @@ func Test_client_CreateProjectBranchDatabase(t *testing.T) { if err != nil { panic(err) } - got, err := c.CreateProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.cfg) + got, err := c.GetProjectOperation(tt.args.projectID, tt.args.operationID) if (err != nil) != tt.wantErr { - t.Errorf("CreateProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetProjectOperation() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateProjectBranchDatabase() got = %v, want %v", got, tt.want) + t.Errorf("GetProjectOperation() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetProjectBranchDatabase(t *testing.T) { - deserializeResp := func(s string) DatabaseResponse { - var v DatabaseResponse +func Test_client_ListApiKeys(t *testing.T) { + deserializeResp := func(s string) []ApiKeysListResponseItem { + var v []ApiKeysListResponseItem if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } - type args struct { - projectID string - branchID string - databaseName string - } tests := []struct { name string - args args apiKey string - want DatabaseResponse + want []ApiKeysListResponseItem wantErr bool }{ { - name: "happy path", - args: args{ - projectID: "foo", - branchID: "foo", - databaseName: "foo", - }, + name: "happy path", apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases/{database_name}"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/api_keys"]["GET"].Content), wantErr: false, }, { - name: "unhappy path", - args: args{ - projectID: "foo", - branchID: "foo", - databaseName: "foo", - }, + name: "unhappy path", apiKey: "invalidApiKey", - want: DatabaseResponse{}, + want: nil, wantErr: true, }, } @@ -1951,62 +1955,56 @@ func Test_client_GetProjectBranchDatabase(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.databaseName) + got, err := c.ListApiKeys() if (err != nil) != tt.wantErr { - t.Errorf("GetProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListApiKeys() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectBranchDatabase() got = %v, want %v", got, tt.want) + t.Errorf("ListApiKeys() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_UpdateProjectBranchDatabase(t *testing.T) { - deserializeResp := func(s string) DatabaseOperations { - var v DatabaseOperations +func Test_client_ListProjectBranchDatabases(t *testing.T) { + deserializeResp := func(s string) DatabasesResponse { + var v DatabasesResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string - databaseName string - cfg DatabaseUpdateRequest + projectID string + branchID string } tests := []struct { name string args args apiKey string - want DatabaseOperations + want DatabasesResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", - databaseName: "foo", - cfg: DatabaseUpdateRequest{}, + projectID: "foo", + branchID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases/{database_name}"]["PATCH"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", - databaseName: "foo", - cfg: DatabaseUpdateRequest{}, + projectID: "foo", + branchID: "foo", }, apiKey: "invalidApiKey", - want: DatabaseOperations{}, + want: DatabasesResponse{}, wantErr: true, }, } @@ -2017,59 +2015,56 @@ func Test_client_UpdateProjectBranchDatabase(t *testing.T) { if err != nil { panic(err) } - got, err := c.UpdateProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.databaseName, tt.args.cfg) + got, err := c.ListProjectBranchDatabases(tt.args.projectID, tt.args.branchID) if (err != nil) != tt.wantErr { - t.Errorf("UpdateProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjectBranchDatabases() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateProjectBranchDatabase() got = %v, want %v", got, tt.want) + t.Errorf("ListProjectBranchDatabases() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_DeleteProjectBranchDatabase(t *testing.T) { - deserializeResp := func(s string) DatabaseOperations { - var v DatabaseOperations +func Test_client_ListProjectBranchEndpoints(t *testing.T) { + deserializeResp := func(s string) EndpointsResponse { + var v EndpointsResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string - databaseName string + projectID string + branchID string } tests := []struct { name string args args apiKey string - want DatabaseOperations + want EndpointsResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", - databaseName: "foo", + projectID: "foo", + branchID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases/{database_name}"]["DELETE"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/endpoints"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", - databaseName: "foo", + projectID: "foo", + branchID: "foo", }, apiKey: "invalidApiKey", - want: DatabaseOperations{}, + want: EndpointsResponse{}, wantErr: true, }, } @@ -2080,13 +2075,13 @@ func Test_client_DeleteProjectBranchDatabase(t *testing.T) { if err != nil { panic(err) } - got, err := c.DeleteProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.databaseName) + got, err := c.ListProjectBranchEndpoints(tt.args.projectID, tt.args.branchID) if (err != nil) != tt.wantErr { - t.Errorf("DeleteProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjectBranchEndpoints() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("DeleteProjectBranchDatabase() got = %v, want %v", got, tt.want) + t.Errorf("ListProjectBranchEndpoints() got = %v, want %v", got, tt.want) } }, ) @@ -2153,9 +2148,9 @@ func Test_client_ListProjectBranchRoles(t *testing.T) { } } -func Test_client_CreateProjectBranchRole(t *testing.T) { - deserializeResp := func(s string) RoleOperations { - var v RoleOperations +func Test_client_ListProjectBranches(t *testing.T) { + deserializeResp := func(s string) ListProjectBranchesRespObj { + var v ListProjectBranchesRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -2163,36 +2158,30 @@ func Test_client_CreateProjectBranchRole(t *testing.T) { } type args struct { projectID string - branchID string - cfg RoleCreateRequest } tests := []struct { name string args args apiKey string - want RoleOperations + want ListProjectBranchesRespObj wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", - branchID: "foo", - cfg: RoleCreateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", - branchID: "foo", - cfg: RoleCreateRequest{}, }, apiKey: "invalidApiKey", - want: RoleOperations{}, + want: ListProjectBranchesRespObj{}, wantErr: true, }, } @@ -2203,22 +2192,22 @@ func Test_client_CreateProjectBranchRole(t *testing.T) { if err != nil { panic(err) } - got, err := c.CreateProjectBranchRole(tt.args.projectID, tt.args.branchID, tt.args.cfg) + got, err := c.ListProjectBranches(tt.args.projectID) if (err != nil) != tt.wantErr { - t.Errorf("CreateProjectBranchRole() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjectBranches() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateProjectBranchRole() got = %v, want %v", got, tt.want) + t.Errorf("ListProjectBranches() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_DeleteProjectBranchRole(t *testing.T) { - deserializeResp := func(s string) RoleOperations { - var v RoleOperations +func Test_client_ListProjectEndpoints(t *testing.T) { + deserializeResp := func(s string) EndpointsResponse { + var v EndpointsResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -2226,36 +2215,30 @@ func Test_client_DeleteProjectBranchRole(t *testing.T) { } type args struct { projectID string - branchID string - roleName string } tests := []struct { name string args args apiKey string - want RoleOperations + want EndpointsResponse wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", - branchID: "foo", - roleName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}"]["DELETE"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", - branchID: "foo", - roleName: "foo", }, apiKey: "invalidApiKey", - want: RoleOperations{}, + want: EndpointsResponse{}, wantErr: true, }, } @@ -2266,22 +2249,22 @@ func Test_client_DeleteProjectBranchRole(t *testing.T) { if err != nil { panic(err) } - got, err := c.DeleteProjectBranchRole(tt.args.projectID, tt.args.branchID, tt.args.roleName) + got, err := c.ListProjectEndpoints(tt.args.projectID) if (err != nil) != tt.wantErr { - t.Errorf("DeleteProjectBranchRole() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjectEndpoints() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("DeleteProjectBranchRole() got = %v, want %v", got, tt.want) + t.Errorf("ListProjectEndpoints() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetProjectBranchRole(t *testing.T) { - deserializeResp := func(s string) RoleResponse { - var v RoleResponse +func Test_client_ListProjectOperations(t *testing.T) { + deserializeResp := func(s string) ListOperations { + var v ListOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -2289,36 +2272,36 @@ func Test_client_GetProjectBranchRole(t *testing.T) { } type args struct { projectID string - branchID string - roleName string + cursor *string + limit *int } tests := []struct { name string args args apiKey string - want RoleResponse + want ListOperations wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", - branchID: "foo", - roleName: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/operations"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", - branchID: "foo", - roleName: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), }, apiKey: "invalidApiKey", - want: RoleResponse{}, + want: ListOperations{}, wantErr: true, }, } @@ -2329,59 +2312,62 @@ func Test_client_GetProjectBranchRole(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectBranchRole(tt.args.projectID, tt.args.branchID, tt.args.roleName) + got, err := c.ListProjectOperations(tt.args.projectID, tt.args.cursor, tt.args.limit) if (err != nil) != tt.wantErr { - t.Errorf("GetProjectBranchRole() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjectOperations() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectBranchRole() got = %v, want %v", got, tt.want) + t.Errorf("ListProjectOperations() got = %v, want %v", got, tt.want) } }, ) } -} - -func Test_client_GetProjectBranchRolePassword(t *testing.T) { - deserializeResp := func(s string) RolePasswordResponse { - var v RolePasswordResponse +} + +func Test_client_ListProjects(t *testing.T) { + deserializeResp := func(s string) ListProjectsRespObj { + var v ListProjectsRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string - roleName string + cursor *string + limit *int + search *string + orgID *string } tests := []struct { name string args args apiKey string - want RolePasswordResponse + want ListProjectsRespObj wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", - roleName: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), + search: createPointer("foo"), + orgID: createPointer("foo"), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reveal_password"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", - roleName: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), + search: createPointer("foo"), + orgID: createPointer("foo"), }, apiKey: "invalidApiKey", - want: RolePasswordResponse{}, + want: ListProjectsRespObj{}, wantErr: true, }, } @@ -2392,59 +2378,65 @@ func Test_client_GetProjectBranchRolePassword(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectBranchRolePassword(tt.args.projectID, tt.args.branchID, tt.args.roleName) + got, err := c.ListProjects(tt.args.cursor, tt.args.limit, tt.args.search, tt.args.orgID) if (err != nil) != tt.wantErr { - t.Errorf("GetProjectBranchRolePassword() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjects() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectBranchRolePassword() got = %v, want %v", got, tt.want) + t.Errorf("ListProjects() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ResetProjectBranchRolePassword(t *testing.T) { - deserializeResp := func(s string) RoleOperations { - var v RoleOperations +func Test_client_ListProjectsConsumption(t *testing.T) { + deserializeResp := func(s string) ListProjectsConsumptionRespObj { + var v ListProjectsConsumptionRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - branchID string - roleName string + cursor *string + limit *int + from *time.Time + to *time.Time + orgID *string } tests := []struct { name string args args apiKey string - want RoleOperations + want ListProjectsConsumptionRespObj wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - branchID: "foo", - roleName: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), + from: createPointer(time.Time{}), + to: createPointer(time.Time{}), + orgID: createPointer("foo"), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reset_password"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/consumption/projects"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - branchID: "foo", - roleName: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), + from: createPointer(time.Time{}), + to: createPointer(time.Time{}), + orgID: createPointer("foo"), }, apiKey: "invalidApiKey", - want: RoleOperations{}, + want: ListProjectsConsumptionRespObj{}, wantErr: true, }, } @@ -2455,53 +2447,59 @@ func Test_client_ResetProjectBranchRolePassword(t *testing.T) { if err != nil { panic(err) } - got, err := c.ResetProjectBranchRolePassword(tt.args.projectID, tt.args.branchID, tt.args.roleName) + got, err := c.ListProjectsConsumption(tt.args.cursor, tt.args.limit, tt.args.from, tt.args.to, tt.args.orgID) if (err != nil) != tt.wantErr { - t.Errorf("ResetProjectBranchRolePassword() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListProjectsConsumption() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ResetProjectBranchRolePassword() got = %v, want %v", got, tt.want) + t.Errorf("ListProjectsConsumption() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListProjectEndpoints(t *testing.T) { - deserializeResp := func(s string) EndpointsResponse { - var v EndpointsResponse +func Test_client_ListSharedProjects(t *testing.T) { + deserializeResp := func(s string) ListSharedProjectsRespObj { + var v ListSharedProjectsRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string + cursor *string + limit *int + search *string } tests := []struct { name string args args apiKey string - want EndpointsResponse + want ListSharedProjectsRespObj wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), + search: createPointer("foo"), }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/shared"]["GET"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", + cursor: createPointer("foo"), + limit: createPointer(1), + search: createPointer("foo"), }, apiKey: "invalidApiKey", - want: EndpointsResponse{}, + want: ListSharedProjectsRespObj{}, wantErr: true, }, } @@ -2512,22 +2510,22 @@ func Test_client_ListProjectEndpoints(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjectEndpoints(tt.args.projectID) + got, err := c.ListSharedProjects(tt.args.cursor, tt.args.limit, tt.args.search) if (err != nil) != tt.wantErr { - t.Errorf("ListProjectEndpoints() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListSharedProjects() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjectEndpoints() got = %v, want %v", got, tt.want) + t.Errorf("ListSharedProjects() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_CreateProjectEndpoint(t *testing.T) { - deserializeResp := func(s string) EndpointOperations { - var v EndpointOperations +func Test_client_ResetProjectBranchRolePassword(t *testing.T) { + deserializeResp := func(s string) RoleOperations { + var v RoleOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } @@ -2535,33 +2533,36 @@ func Test_client_CreateProjectEndpoint(t *testing.T) { } type args struct { projectID string - cfg EndpointCreateRequest + branchID string + roleName string } tests := []struct { name string args args apiKey string - want EndpointOperations + want RoleOperations wantErr bool }{ { name: "happy path", args: args{ projectID: "foo", - cfg: EndpointCreateRequest{}, + branchID: "foo", + roleName: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reset_password"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ projectID: "foo", - cfg: EndpointCreateRequest{}, + branchID: "foo", + roleName: "foo", }, apiKey: "invalidApiKey", - want: EndpointOperations{}, + want: RoleOperations{}, wantErr: true, }, } @@ -2572,20 +2573,20 @@ func Test_client_CreateProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.CreateProjectEndpoint(tt.args.projectID, tt.args.cfg) + got, err := c.ResetProjectBranchRolePassword(tt.args.projectID, tt.args.branchID, tt.args.roleName) if (err != nil) != tt.wantErr { - t.Errorf("CreateProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ResetProjectBranchRolePassword() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("CreateProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("ResetProjectBranchRolePassword() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_DeleteProjectEndpoint(t *testing.T) { +func Test_client_RestartProjectEndpoint(t *testing.T) { deserializeResp := func(s string) EndpointOperations { var v EndpointOperations if err := json.Unmarshal([]byte(s), &v); err != nil { @@ -2611,7 +2612,7 @@ func Test_client_DeleteProjectEndpoint(t *testing.T) { endpointID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}"]["DELETE"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}/restart"]["POST"].Content), wantErr: false, }, { @@ -2632,56 +2633,59 @@ func Test_client_DeleteProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.DeleteProjectEndpoint(tt.args.projectID, tt.args.endpointID) + got, err := c.RestartProjectEndpoint(tt.args.projectID, tt.args.endpointID) if (err != nil) != tt.wantErr { - t.Errorf("DeleteProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("RestartProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("DeleteProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("RestartProjectEndpoint() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetProjectEndpoint(t *testing.T) { - deserializeResp := func(s string) EndpointResponse { - var v EndpointResponse +func Test_client_RestoreProjectBranch(t *testing.T) { + deserializeResp := func(s string) BranchOperations { + var v BranchOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - endpointID string + projectID string + branchID string + cfg BranchRestoreRequest } tests := []struct { name string args args apiKey string - want EndpointResponse + want BranchOperations wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - endpointID: "foo", + projectID: "foo", + branchID: "foo", + cfg: BranchRestoreRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/restore"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - endpointID: "foo", + projectID: "foo", + branchID: "foo", + cfg: BranchRestoreRequest{}, }, apiKey: "invalidApiKey", - want: EndpointResponse{}, + want: BranchOperations{}, wantErr: true, }, } @@ -2692,59 +2696,53 @@ func Test_client_GetProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetProjectEndpoint(tt.args.projectID, tt.args.endpointID) + got, err := c.RestoreProjectBranch(tt.args.projectID, tt.args.branchID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("GetProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("RestoreProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("RestoreProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_UpdateProjectEndpoint(t *testing.T) { - deserializeResp := func(s string) EndpointOperations { - var v EndpointOperations +func Test_client_RevokeApiKey(t *testing.T) { + deserializeResp := func(s string) ApiKeyRevokeResponse { + var v ApiKeyRevokeResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - endpointID string - cfg EndpointUpdateRequest + keyID int64 } tests := []struct { name string args args apiKey string - want EndpointOperations + want ApiKeyRevokeResponse wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - endpointID: "foo", - cfg: EndpointUpdateRequest{}, + keyID: 1, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}"]["PATCH"].Content), + want: deserializeResp(endpointResponseExamples["/api_keys/{key_id}"]["DELETE"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - endpointID: "foo", - cfg: EndpointUpdateRequest{}, + keyID: 1, }, apiKey: "invalidApiKey", - want: EndpointOperations{}, + want: ApiKeyRevokeResponse{}, wantErr: true, }, } @@ -2755,56 +2753,56 @@ func Test_client_UpdateProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.UpdateProjectEndpoint(tt.args.projectID, tt.args.endpointID, tt.args.cfg) + got, err := c.RevokeApiKey(tt.args.keyID) if (err != nil) != tt.wantErr { - t.Errorf("UpdateProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("RevokeApiKey() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("UpdateProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("RevokeApiKey() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_StartProjectEndpoint(t *testing.T) { - deserializeResp := func(s string) EndpointOperations { - var v EndpointOperations +func Test_client_SetDefaultProjectBranch(t *testing.T) { + deserializeResp := func(s string) BranchOperations { + var v BranchOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - endpointID string + projectID string + branchID string } tests := []struct { name string args args apiKey string - want EndpointOperations + want BranchOperations wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - endpointID: "foo", + projectID: "foo", + branchID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}/start"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/set_as_default"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - endpointID: "foo", + projectID: "foo", + branchID: "foo", }, apiKey: "invalidApiKey", - want: EndpointOperations{}, + want: BranchOperations{}, wantErr: true, }, } @@ -2815,56 +2813,56 @@ func Test_client_StartProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.StartProjectEndpoint(tt.args.projectID, tt.args.endpointID) + got, err := c.SetDefaultProjectBranch(tt.args.projectID, tt.args.branchID) if (err != nil) != tt.wantErr { - t.Errorf("StartProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("SetDefaultProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("StartProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("SetDefaultProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_SuspendProjectEndpoint(t *testing.T) { - deserializeResp := func(s string) EndpointOperations { - var v EndpointOperations +func Test_client_SetPrimaryProjectBranch(t *testing.T) { + deserializeResp := func(s string) BranchOperations { + var v BranchOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - projectID string - endpointID string + projectID string + branchID string } tests := []struct { name string args args apiKey string - want EndpointOperations + want BranchOperations wantErr bool }{ { name: "happy path", args: args{ - projectID: "foo", - endpointID: "foo", + projectID: "foo", + branchID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}/suspend"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/set_as_primary"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - projectID: "foo", - endpointID: "foo", + projectID: "foo", + branchID: "foo", }, apiKey: "invalidApiKey", - want: EndpointOperations{}, + want: BranchOperations{}, wantErr: true, }, } @@ -2875,20 +2873,20 @@ func Test_client_SuspendProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.SuspendProjectEndpoint(tt.args.projectID, tt.args.endpointID) + got, err := c.SetPrimaryProjectBranch(tt.args.projectID, tt.args.branchID) if (err != nil) != tt.wantErr { - t.Errorf("SuspendProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("SetPrimaryProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("SuspendProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("SetPrimaryProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_RestartProjectEndpoint(t *testing.T) { +func Test_client_StartProjectEndpoint(t *testing.T) { deserializeResp := func(s string) EndpointOperations { var v EndpointOperations if err := json.Unmarshal([]byte(s), &v); err != nil { @@ -2914,7 +2912,7 @@ func Test_client_RestartProjectEndpoint(t *testing.T) { endpointID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}/restart"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}/start"]["POST"].Content), wantErr: false, }, { @@ -2935,65 +2933,56 @@ func Test_client_RestartProjectEndpoint(t *testing.T) { if err != nil { panic(err) } - got, err := c.RestartProjectEndpoint(tt.args.projectID, tt.args.endpointID) + got, err := c.StartProjectEndpoint(tt.args.projectID, tt.args.endpointID) if (err != nil) != tt.wantErr { - t.Errorf("RestartProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("StartProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("RestartProjectEndpoint() got = %v, want %v", got, tt.want) + t.Errorf("StartProjectEndpoint() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetConsumptionHistoryPerAccount(t *testing.T) { - deserializeResp := func(s string) ConsumptionHistoryPerAccountResponse { - var v ConsumptionHistoryPerAccountResponse +func Test_client_SuspendProjectEndpoint(t *testing.T) { + deserializeResp := func(s string) EndpointOperations { + var v EndpointOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - from time.Time - to time.Time - granularity ConsumptionHistoryGranularity - orgID *string - includeV1Metrics *bool + projectID string + endpointID string } tests := []struct { name string args args apiKey string - want ConsumptionHistoryPerAccountResponse + want EndpointOperations wantErr bool }{ { name: "happy path", args: args{ - from: time.Time{}, - to: time.Time{}, - granularity: "foo", - orgID: createPointer("foo"), - includeV1Metrics: createPointer(true), + projectID: "foo", + endpointID: "foo", }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/consumption_history/account"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}/suspend"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - from: time.Time{}, - to: time.Time{}, - granularity: "foo", - orgID: createPointer("foo"), - includeV1Metrics: createPointer(true), + projectID: "foo", + endpointID: "foo", }, apiKey: "invalidApiKey", - want: ConsumptionHistoryPerAccountResponse{}, + want: EndpointOperations{}, wantErr: true, }, } @@ -3004,74 +2993,53 @@ func Test_client_GetConsumptionHistoryPerAccount(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetConsumptionHistoryPerAccount(tt.args.from, tt.args.to, tt.args.granularity, tt.args.orgID, tt.args.includeV1Metrics) + got, err := c.SuspendProjectEndpoint(tt.args.projectID, tt.args.endpointID) if (err != nil) != tt.wantErr { - t.Errorf("GetConsumptionHistoryPerAccount() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("SuspendProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetConsumptionHistoryPerAccount() got = %v, want %v", got, tt.want) + t.Errorf("SuspendProjectEndpoint() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetConsumptionHistoryPerProject(t *testing.T) { - deserializeResp := func(s string) GetConsumptionHistoryPerProjectRespObj { - var v GetConsumptionHistoryPerProjectRespObj +func Test_client_TransferProjectsFromUserToOrg(t *testing.T) { + deserializeResp := func(s string) EmptyResponse { + var v EmptyResponse if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - cursor *string - limit *int - projectIDs []string - from time.Time - to time.Time - granularity ConsumptionHistoryGranularity - orgID *string - includeV1Metrics *bool + cfg TransferProjectsToOrganizationRequest } tests := []struct { name string args args apiKey string - want GetConsumptionHistoryPerProjectRespObj + want EmptyResponse wantErr bool }{ { name: "happy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - projectIDs: []string{"foo"}, - from: time.Time{}, - to: time.Time{}, - granularity: "foo", - orgID: createPointer("foo"), - includeV1Metrics: createPointer(true), + cfg: TransferProjectsToOrganizationRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/consumption_history/projects"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/users/me/projects/transfer"]["POST"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - projectIDs: []string{"foo"}, - from: time.Time{}, - to: time.Time{}, - granularity: "foo", - orgID: createPointer("foo"), - includeV1Metrics: createPointer(true), + cfg: TransferProjectsToOrganizationRequest{}, }, apiKey: "invalidApiKey", - want: GetConsumptionHistoryPerProjectRespObj{}, + want: EmptyResponse{}, wantErr: true, }, } @@ -3082,65 +3050,56 @@ func Test_client_GetConsumptionHistoryPerProject(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetConsumptionHistoryPerProject(tt.args.cursor, tt.args.limit, tt.args.projectIDs, tt.args.from, tt.args.to, tt.args.granularity, tt.args.orgID, tt.args.includeV1Metrics) + got, err := c.TransferProjectsFromUserToOrg(tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("GetConsumptionHistoryPerProject() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("TransferProjectsFromUserToOrg() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetConsumptionHistoryPerProject() got = %v, want %v", got, tt.want) + t.Errorf("TransferProjectsFromUserToOrg() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_ListProjectsConsumption(t *testing.T) { - deserializeResp := func(s string) ListProjectsConsumptionRespObj { - var v ListProjectsConsumptionRespObj +func Test_client_UpdateProject(t *testing.T) { + deserializeResp := func(s string) UpdateProjectRespObj { + var v UpdateProjectRespObj if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - cursor *string - limit *int - from *time.Time - to *time.Time - orgID *string + projectID string + cfg ProjectUpdateRequest } tests := []struct { name string args args apiKey string - want ListProjectsConsumptionRespObj + want UpdateProjectRespObj wantErr bool }{ { name: "happy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - from: createPointer(time.Time{}), - to: createPointer(time.Time{}), - orgID: createPointer("foo"), + projectID: "foo", + cfg: ProjectUpdateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/consumption/projects"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}"]["PATCH"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - cursor: createPointer("foo"), - limit: createPointer(1), - from: createPointer(time.Time{}), - to: createPointer(time.Time{}), - orgID: createPointer("foo"), + projectID: "foo", + cfg: ProjectUpdateRequest{}, }, apiKey: "invalidApiKey", - want: ListProjectsConsumptionRespObj{}, + want: UpdateProjectRespObj{}, wantErr: true, }, } @@ -3151,43 +3110,59 @@ func Test_client_ListProjectsConsumption(t *testing.T) { if err != nil { panic(err) } - got, err := c.ListProjectsConsumption(tt.args.cursor, tt.args.limit, tt.args.from, tt.args.to, tt.args.orgID) + got, err := c.UpdateProject(tt.args.projectID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("ListProjectsConsumption() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("UpdateProject() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListProjectsConsumption() got = %v, want %v", got, tt.want) + t.Errorf("UpdateProject() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetCurrentUserInfo(t *testing.T) { - deserializeResp := func(s string) CurrentUserInfoResponse { - var v CurrentUserInfoResponse +func Test_client_UpdateProjectBranch(t *testing.T) { + deserializeResp := func(s string) BranchOperations { + var v BranchOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } + type args struct { + projectID string + branchID string + cfg BranchUpdateRequest + } tests := []struct { name string + args args apiKey string - want CurrentUserInfoResponse + want BranchOperations wantErr bool }{ { - name: "happy path", + name: "happy path", + args: args{ + projectID: "foo", + branchID: "foo", + cfg: BranchUpdateRequest{}, + }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/users/me"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}"]["PATCH"].Content), wantErr: false, }, { - name: "unhappy path", + name: "unhappy path", + args: args{ + projectID: "foo", + branchID: "foo", + cfg: BranchUpdateRequest{}, + }, apiKey: "invalidApiKey", - want: CurrentUserInfoResponse{}, + want: BranchOperations{}, wantErr: true, }, } @@ -3198,43 +3173,62 @@ func Test_client_GetCurrentUserInfo(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetCurrentUserInfo() + got, err := c.UpdateProjectBranch(tt.args.projectID, tt.args.branchID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("GetCurrentUserInfo() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("UpdateProjectBranch() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCurrentUserInfo() got = %v, want %v", got, tt.want) + t.Errorf("UpdateProjectBranch() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_GetCurrentUserOrganizations(t *testing.T) { - deserializeResp := func(s string) OrganizationsResponse { - var v OrganizationsResponse +func Test_client_UpdateProjectBranchDatabase(t *testing.T) { + deserializeResp := func(s string) DatabaseOperations { + var v DatabaseOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } + type args struct { + projectID string + branchID string + databaseName string + cfg DatabaseUpdateRequest + } tests := []struct { name string + args args apiKey string - want OrganizationsResponse + want DatabaseOperations wantErr bool }{ { - name: "happy path", + name: "happy path", + args: args{ + projectID: "foo", + branchID: "foo", + databaseName: "foo", + cfg: DatabaseUpdateRequest{}, + }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/users/me/organizations"]["GET"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/branches/{branch_id}/databases/{database_name}"]["PATCH"].Content), wantErr: false, }, { - name: "unhappy path", + name: "unhappy path", + args: args{ + projectID: "foo", + branchID: "foo", + databaseName: "foo", + cfg: DatabaseUpdateRequest{}, + }, apiKey: "invalidApiKey", - want: OrganizationsResponse{}, + want: DatabaseOperations{}, wantErr: true, }, } @@ -3245,53 +3239,59 @@ func Test_client_GetCurrentUserOrganizations(t *testing.T) { if err != nil { panic(err) } - got, err := c.GetCurrentUserOrganizations() + got, err := c.UpdateProjectBranchDatabase(tt.args.projectID, tt.args.branchID, tt.args.databaseName, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("GetCurrentUserOrganizations() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("UpdateProjectBranchDatabase() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCurrentUserOrganizations() got = %v, want %v", got, tt.want) + t.Errorf("UpdateProjectBranchDatabase() got = %v, want %v", got, tt.want) } }, ) } } -func Test_client_TransferProjectsFromUserToOrg(t *testing.T) { - deserializeResp := func(s string) EmptyResponse { - var v EmptyResponse +func Test_client_UpdateProjectEndpoint(t *testing.T) { + deserializeResp := func(s string) EndpointOperations { + var v EndpointOperations if err := json.Unmarshal([]byte(s), &v); err != nil { panic(err) } return v } type args struct { - cfg TransferProjectsToOrganizationRequest + projectID string + endpointID string + cfg EndpointUpdateRequest } tests := []struct { name string args args apiKey string - want EmptyResponse + want EndpointOperations wantErr bool }{ { name: "happy path", args: args{ - cfg: TransferProjectsToOrganizationRequest{}, + projectID: "foo", + endpointID: "foo", + cfg: EndpointUpdateRequest{}, }, apiKey: "foo", - want: deserializeResp(endpointResponseExamples["/users/me/projects/transfer"]["POST"].Content), + want: deserializeResp(endpointResponseExamples["/projects/{project_id}/endpoints/{endpoint_id}"]["PATCH"].Content), wantErr: false, }, { name: "unhappy path", args: args{ - cfg: TransferProjectsToOrganizationRequest{}, + projectID: "foo", + endpointID: "foo", + cfg: EndpointUpdateRequest{}, }, apiKey: "invalidApiKey", - want: EmptyResponse{}, + want: EndpointOperations{}, wantErr: true, }, } @@ -3302,13 +3302,13 @@ func Test_client_TransferProjectsFromUserToOrg(t *testing.T) { if err != nil { panic(err) } - got, err := c.TransferProjectsFromUserToOrg(tt.args.cfg) + got, err := c.UpdateProjectEndpoint(tt.args.projectID, tt.args.endpointID, tt.args.cfg) if (err != nil) != tt.wantErr { - t.Errorf("TransferProjectsFromUserToOrg() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("UpdateProjectEndpoint() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("TransferProjectsFromUserToOrg() got = %v, want %v", got, tt.want) + t.Errorf("UpdateProjectEndpoint() got = %v, want %v", got, tt.want) } }, )