databricks-cli/acceptance/server_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

183 lines
5.1 KiB
Go
Raw Normal View History

package acceptance_test
import (
"encoding/json"
"fmt"
"net/http"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/iam"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/cli/libs/testserver"
"github.com/databricks/databricks-sdk-go/service/workspace"
)
var testUser = iam.User{
Id: "1000012345",
UserName: "tester@databricks.com",
}
var testMetastore = catalog.MetastoreAssignment{
DefaultCatalogName: "hive_metastore",
MetastoreId: "120efa64-9b68-46ba-be38-f319458430d2",
WorkspaceId: 470123456789500,
}
func AddHandlers(server *testserver.Server) {
server.Handle("GET", "/api/2.0/policies/clusters/list", func(req testserver.Request) any {
return compute.ListPoliciesResponse{
Policies: []compute.Policy{
{
PolicyId: "5678",
Name: "wrong-cluster-policy",
},
{
PolicyId: "9876",
Name: "some-test-cluster-policy",
},
},
}
})
server.Handle("GET", "/api/2.0/instance-pools/list", func(req testserver.Request) any {
return compute.ListInstancePools{
InstancePools: []compute.InstancePoolAndStats{
{
InstancePoolName: "some-test-instance-pool",
InstancePoolId: "1234",
},
},
}
})
server.Handle("GET", "/api/2.1/clusters/list", func(req testserver.Request) any {
return compute.ListClustersResponse{
Clusters: []compute.ClusterDetails{
{
ClusterName: "some-test-cluster",
ClusterId: "4321",
},
{
ClusterName: "some-other-cluster",
ClusterId: "9876",
},
},
}
})
server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any {
return testserver.Response{
Headers: map[string][]string{"X-Databricks-Org-Id": {"900800700600"}},
Body: testUser,
}
})
server.Handle("GET", "/api/2.0/workspace/get-status", func(req testserver.Request) any {
path := req.URL.Query().Get("path")
return req.Workspace.WorkspaceGetStatus(path)
})
server.Handle("POST", "/api/2.0/workspace/mkdirs", func(req testserver.Request) any {
var request workspace.Mkdirs
if err := json.Unmarshal(req.Body, &request); err != nil {
return testserver.Response{
Body: fmt.Sprintf("internal error: %s", err),
StatusCode: http.StatusInternalServerError,
}
}
req.Workspace.WorkspaceMkdirs(request)
return ""
})
server.Handle("GET", "/api/2.0/workspace/export", func(req testserver.Request) any {
path := req.URL.Query().Get("path")
return req.Workspace.WorkspaceExport(path)
})
server.Handle("POST", "/api/2.0/workspace/delete", func(req testserver.Request) any {
path := req.URL.Query().Get("path")
recursive := req.URL.Query().Get("recursive") == "true"
req.Workspace.WorkspaceDelete(path, recursive)
return ""
})
server.Handle("POST", "/api/2.0/workspace-files/import-file/{path:.*}", func(req testserver.Request) any {
path := req.Vars["path"]
req.Workspace.WorkspaceFilesImportFile(path, req.Body)
return ""
})
server.Handle("GET", "/api/2.0/workspace-files/{path:.*}", func(req testserver.Request) any {
path := req.Vars["path"]
return req.Workspace.WorkspaceFilesExportFile(path)
})
server.Handle("GET", "/api/2.1/unity-catalog/current-metastore-assignment", func(req testserver.Request) any {
return testMetastore
})
server.Handle("GET", "/api/2.0/permissions/directories/{objectId}", func(req testserver.Request) any {
objectId := req.Vars["objectId"]
return workspace.WorkspaceObjectPermissions{
ObjectId: objectId,
ObjectType: "DIRECTORY",
AccessControlList: []workspace.WorkspaceObjectAccessControlResponse{
{
UserName: "tester@databricks.com",
AllPermissions: []workspace.WorkspaceObjectPermission{
{
PermissionLevel: "CAN_MANAGE",
},
},
},
},
}
})
server.Handle("POST", "/api/2.1/jobs/create", func(req testserver.Request) any {
var request jobs.CreateJob
if err := json.Unmarshal(req.Body, &request); err != nil {
return testserver.Response{
Body: fmt.Sprintf("internal error: %s", err),
StatusCode: 500,
}
}
return req.Workspace.JobsCreate(request)
})
server.Handle("GET", "/api/2.1/jobs/get", func(req testserver.Request) any {
jobId := req.URL.Query().Get("job_id")
return req.Workspace.JobsGet(jobId)
})
build(deps): bump github.com/databricks/databricks-sdk-go from 0.59.0 to 0.60.0 (#2504) Bumps [github.com/databricks/databricks-sdk-go](https://github.com/databricks/databricks-sdk-go) from 0.59.0 to 0.60.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/databricks/databricks-sdk-go/releases">github.com/databricks/databricks-sdk-go's releases</a>.</em></p> <blockquote> <h2>v0.60.0</h2> <h2>Release v0.60.0</h2> <h3>API Changes</h3> <p>Added <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/ml#ForecastingAPI">w.Forecasting</a> workspace-level service. Added ExecuteMessageAttachmentQuery and GetMessageAttachmentQueryResult methods for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#GenieAPI">w.Genie</a> workspace-level service. Added StatementId field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#GenieQueryAttachment">dashboards.GenieQueryAttachment</a>. Added BudgetPolicyId field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#CreateServingEndpoint">serving.CreateServingEndpoint</a>. Added BudgetPolicyId field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpoint">serving.ServingEndpoint</a>. Added BudgetPolicyId field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointDetailed">serving.ServingEndpointDetailed</a>. Added CouldNotGetModelDeploymentsException enum value for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#MessageErrorType">dashboards.MessageErrorType</a>.</p> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/databricks/databricks-sdk-go/blob/main/CHANGELOG.md">github.com/databricks/databricks-sdk-go's changelog</a>.</em></p> <blockquote> <h2>Release v0.60.0</h2> <h3>API Changes</h3> <ul> <li>Added <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/ml#ForecastingAPI">w.Forecasting</a> workspace-level service.</li> <li>Added <code>ExecuteMessageAttachmentQuery</code> and <code>GetMessageAttachmentQueryResult</code> methods for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#GenieAPI">w.Genie</a> workspace-level service.</li> <li>Added <code>StatementId</code> field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#GenieQueryAttachment">dashboards.GenieQueryAttachment</a>.</li> <li>Added <code>BudgetPolicyId</code> field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#CreateServingEndpoint">serving.CreateServingEndpoint</a>.</li> <li>Added <code>BudgetPolicyId</code> field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpoint">serving.ServingEndpoint</a>.</li> <li>Added <code>BudgetPolicyId</code> field for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServingEndpointDetailed">serving.ServingEndpointDetailed</a>.</li> <li>Added <code>CouldNotGetModelDeploymentsException</code> enum value for <a href="https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/dashboards#MessageErrorType">dashboards.MessageErrorType</a>.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/databricks/databricks-sdk-go/commit/424a24bf8128015a9fe127c1cd412d1a8fe90c0f"><code>424a24b</code></a> [Release] Release v0.60.0</li> <li><a href="https://github.com/databricks/databricks-sdk-go/commit/19e0348fb08bb784b06e8f18ab4b01286f24df38"><code>19e0348</code></a> Update OpenAPI spec and Update mockery version (<a href="https://redirect.github.com/databricks/databricks-sdk-go/issues/1168">#1168</a>)</li> <li><a href="https://github.com/databricks/databricks-sdk-go/commit/c33f4160577d613d0ace5ed09d1826422ec4c4a0"><code>c33f416</code></a> Remove unnecessary config files and GitHub workflows (<a href="https://redirect.github.com/databricks/databricks-sdk-go/issues/1165">#1165</a>)</li> <li><a href="https://github.com/databricks/databricks-sdk-go/commit/2f2d945bb2c36583e2569d54eb7538981fa2aaf5"><code>2f2d945</code></a> [Fix] Properly parse the <code>RetryInfo</code> error detail (<a href="https://redirect.github.com/databricks/databricks-sdk-go/issues/1162">#1162</a>)</li> <li>See full diff in <a href="https://github.com/databricks/databricks-sdk-go/compare/v0.59.0...v0.60.0">compare view</a></li> </ul> </details> <br /> <details> <summary>Most Recent Ignore Conditions Applied to This Pull Request</summary> | Dependency Name | Ignore Conditions | | --- | --- | | github.com/databricks/databricks-sdk-go | [>= 0.28.a, < 0.29] | </details> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/databricks/databricks-sdk-go&package-manager=go_modules&previous-version=0.59.0&new-version=0.60.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andrew Nester <andrew.nester@databricks.com>
2025-03-17 15:20:36 +00:00
server.Handle("GET", "/api/2.2/jobs/get", func(req testserver.Request) any {
jobId := req.URL.Query().Get("job_id")
return req.Workspace.JobsGet(jobId)
})
server.Handle("GET", "/api/2.1/jobs/list", func(req testserver.Request) any {
return req.Workspace.JobsList()
})
server.Handle("GET", "/oidc/.well-known/oauth-authorization-server", func(_ testserver.Request) any {
return map[string]string{
"authorization_endpoint": server.URL + "oidc/v1/authorize",
"token_endpoint": server.URL + "/oidc/v1/token",
}
})
server.Handle("POST", "/oidc/v1/token", func(_ testserver.Request) any {
return map[string]string{
"access_token": "oauth-token",
"expires_in": "3600",
"scope": "all-apis",
"token_type": "Bearer",
}
})
}