2025-01-08 12:41:08 +00:00
|
|
|
package acceptance_test
|
|
|
|
|
|
|
|
import (
|
2025-01-23 18:56:58 +00:00
|
|
|
"context"
|
2025-01-08 12:41:08 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2025-01-23 18:56:58 +00:00
|
|
|
"github.com/databricks/cli/internal/testserver"
|
2025-01-14 18:23:34 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/catalog"
|
2025-01-08 12:41:08 +00:00
|
|
|
"github.com/databricks/databricks-sdk-go/service/compute"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/iam"
|
|
|
|
"github.com/databricks/databricks-sdk-go/service/workspace"
|
|
|
|
)
|
|
|
|
|
2025-01-23 18:56:58 +00:00
|
|
|
func StartServer(t *testing.T) *testserver.Server {
|
|
|
|
server := testserver.New(context.Background(), t)
|
2025-01-08 12:41:08 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
server.Close()
|
|
|
|
})
|
|
|
|
return server
|
|
|
|
}
|
|
|
|
|
2025-01-23 18:56:58 +00:00
|
|
|
func AddHandlers(server *testserver.Server) {
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.0/policies/clusters/list", func(r *http.Request) (any, error) {
|
2025-01-08 12:41:08 +00:00
|
|
|
return compute.ListPoliciesResponse{
|
|
|
|
Policies: []compute.Policy{
|
|
|
|
{
|
|
|
|
PolicyId: "5678",
|
|
|
|
Name: "wrong-cluster-policy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PolicyId: "9876",
|
|
|
|
Name: "some-test-cluster-policy",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.0/instance-pools/list", func(r *http.Request) (any, error) {
|
2025-01-08 12:41:08 +00:00
|
|
|
return compute.ListInstancePools{
|
|
|
|
InstancePools: []compute.InstancePoolAndStats{
|
|
|
|
{
|
|
|
|
InstancePoolName: "some-test-instance-pool",
|
|
|
|
InstancePoolId: "1234",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.1/clusters/list", func(r *http.Request) (any, error) {
|
2025-01-08 12:41:08 +00:00
|
|
|
return compute.ListClustersResponse{
|
|
|
|
Clusters: []compute.ClusterDetails{
|
|
|
|
{
|
|
|
|
ClusterName: "some-test-cluster",
|
|
|
|
ClusterId: "4321",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ClusterName: "some-other-cluster",
|
|
|
|
ClusterId: "9876",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.0/preview/scim/v2/Me", func(r *http.Request) (any, error) {
|
2025-01-08 12:41:08 +00:00
|
|
|
return iam.User{
|
|
|
|
UserName: "tester@databricks.com",
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.0/workspace/get-status", func(r *http.Request) (any, error) {
|
2025-01-08 12:41:08 +00:00
|
|
|
return workspace.ObjectInfo{
|
|
|
|
ObjectId: 1001,
|
|
|
|
ObjectType: "DIRECTORY",
|
|
|
|
Path: "",
|
|
|
|
ResourceId: "1001",
|
|
|
|
}, nil
|
|
|
|
})
|
2025-01-14 18:23:34 +00:00
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.1/unity-catalog/current-metastore-assignment", func(r *http.Request) (any, error) {
|
2025-01-14 18:23:34 +00:00
|
|
|
return catalog.MetastoreAssignment{
|
|
|
|
DefaultCatalogName: "main",
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
2025-01-24 11:03:11 +00:00
|
|
|
server.Handle("/api/2.0/permissions/directories/1001", func(r *http.Request) (any, error) {
|
2025-01-14 18:23:34 +00:00
|
|
|
return workspace.WorkspaceObjectPermissions{
|
|
|
|
ObjectId: "1001",
|
|
|
|
ObjectType: "DIRECTORY",
|
|
|
|
AccessControlList: []workspace.WorkspaceObjectAccessControlResponse{
|
|
|
|
{
|
|
|
|
UserName: "tester@databricks.com",
|
|
|
|
AllPermissions: []workspace.WorkspaceObjectPermission{
|
|
|
|
{
|
|
|
|
PermissionLevel: "CAN_MANAGE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
})
|
2025-01-08 12:41:08 +00:00
|
|
|
}
|