mirror of https://github.com/databricks/cli.git
acc: Create acceptance/internal package (#2495)
## Changes Move acceptance/*_test.go to acceptance/internal (except for acceptance_test.go). ## Why Some of this code needs its own tests, having it in package supports the separation between "acceptance tests" and "acceptance test runner tests".
This commit is contained in:
parent
52338c0341
commit
e233919212
|
@ -24,6 +24,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"github.com/databricks/cli/acceptance/internal"
|
||||||
"github.com/databricks/cli/internal/testutil"
|
"github.com/databricks/cli/internal/testutil"
|
||||||
"github.com/databricks/cli/libs/env"
|
"github.com/databricks/cli/libs/env"
|
||||||
"github.com/databricks/cli/libs/testdiff"
|
"github.com/databricks/cli/libs/testdiff"
|
||||||
|
@ -112,7 +113,7 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int {
|
||||||
execPath := ""
|
execPath := ""
|
||||||
|
|
||||||
if InprocessMode {
|
if InprocessMode {
|
||||||
cmdServer := StartCmdServer(t)
|
cmdServer := internal.StartCmdServer(t)
|
||||||
t.Setenv("CMD_SERVER_URL", cmdServer.URL)
|
t.Setenv("CMD_SERVER_URL", cmdServer.URL)
|
||||||
execPath = filepath.Join(cwd, "bin", "callserver.py")
|
execPath = filepath.Join(cwd, "bin", "callserver.py")
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,7 +138,7 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int {
|
||||||
|
|
||||||
if cloudEnv == "" {
|
if cloudEnv == "" {
|
||||||
defaultServer := testserver.New(t)
|
defaultServer := testserver.New(t)
|
||||||
AddHandlers(defaultServer)
|
internal.AddHandlers(defaultServer)
|
||||||
t.Setenv("DATABRICKS_DEFAULT_HOST", defaultServer.URL)
|
t.Setenv("DATABRICKS_DEFAULT_HOST", defaultServer.URL)
|
||||||
|
|
||||||
homeDir := t.TempDir()
|
homeDir := t.TempDir()
|
||||||
|
@ -198,7 +199,7 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int {
|
||||||
t.Run(dir, func(t *testing.T) {
|
t.Run(dir, func(t *testing.T) {
|
||||||
selectedDirs += 1
|
selectedDirs += 1
|
||||||
|
|
||||||
config, configPath := LoadConfig(t, dir)
|
config, configPath := internal.LoadConfig(t, dir)
|
||||||
skipReason := getSkipReason(&config, configPath)
|
skipReason := getSkipReason(&config, configPath)
|
||||||
|
|
||||||
if skipReason != "" {
|
if skipReason != "" {
|
||||||
|
@ -241,7 +242,7 @@ func getTests(t *testing.T) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a reason to skip the test. Empty string means "don't skip".
|
// Return a reason to skip the test. Empty string means "don't skip".
|
||||||
func getSkipReason(config *TestConfig, configPath string) string {
|
func getSkipReason(config *internal.TestConfig, configPath string) string {
|
||||||
if Forcerun {
|
if Forcerun {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -285,7 +286,7 @@ func getSkipReason(config *TestConfig, configPath string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsContext, config TestConfig, configPath string) {
|
func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsContext, config internal.TestConfig, configPath string) {
|
||||||
tailOutput := Tail
|
tailOutput := Tail
|
||||||
cloudEnv := os.Getenv("CLOUD_ENV")
|
cloudEnv := os.Getenv("CLOUD_ENV")
|
||||||
isRunningOnCloud := cloudEnv != ""
|
isRunningOnCloud := cloudEnv != ""
|
||||||
|
@ -380,7 +381,7 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
|
||||||
}
|
}
|
||||||
|
|
||||||
// The earliest handlers take precedence, add default handlers last
|
// The earliest handlers take precedence, add default handlers last
|
||||||
AddHandlers(server)
|
internal.AddHandlers(server)
|
||||||
databricksLocalHost = server.URL
|
databricksLocalHost = server.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +400,7 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
|
||||||
|
|
||||||
// For the purposes of replacements, use testUser.
|
// For the purposes of replacements, use testUser.
|
||||||
// Note, users might have overriden /api/2.0/preview/scim/v2/Me but that should not affect the replacement:
|
// Note, users might have overriden /api/2.0/preview/scim/v2/Me but that should not affect the replacement:
|
||||||
user = testUser
|
user = internal.TestUser
|
||||||
} else {
|
} else {
|
||||||
// Use whatever authentication mechanism is configured by the test runner.
|
// Use whatever authentication mechanism is configured by the test runner.
|
||||||
workspaceClient, err = databricks.NewWorkspaceClient(&databricks.Config{})
|
workspaceClient, err = databricks.NewWorkspaceClient(&databricks.Config{})
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package acceptance_test
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package acceptance_test
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -1,4 +1,4 @@
|
||||||
package acceptance_test
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -15,12 +15,12 @@ import (
|
||||||
"github.com/databricks/databricks-sdk-go/service/workspace"
|
"github.com/databricks/databricks-sdk-go/service/workspace"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testUser = iam.User{
|
var TestUser = iam.User{
|
||||||
Id: "1000012345",
|
Id: "1000012345",
|
||||||
UserName: "tester@databricks.com",
|
UserName: "tester@databricks.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
var testMetastore = catalog.MetastoreAssignment{
|
var TestMetastore = catalog.MetastoreAssignment{
|
||||||
DefaultCatalogName: "hive_metastore",
|
DefaultCatalogName: "hive_metastore",
|
||||||
MetastoreId: "120efa64-9b68-46ba-be38-f319458430d2",
|
MetastoreId: "120efa64-9b68-46ba-be38-f319458430d2",
|
||||||
WorkspaceId: 470123456789500,
|
WorkspaceId: 470123456789500,
|
||||||
|
@ -71,7 +71,7 @@ func AddHandlers(server *testserver.Server) {
|
||||||
server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any {
|
server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any {
|
||||||
return testserver.Response{
|
return testserver.Response{
|
||||||
Headers: map[string][]string{"X-Databricks-Org-Id": {"900800700600"}},
|
Headers: map[string][]string{"X-Databricks-Org-Id": {"900800700600"}},
|
||||||
Body: testUser,
|
Body: TestUser,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ func AddHandlers(server *testserver.Server) {
|
||||||
})
|
})
|
||||||
|
|
||||||
server.Handle("GET", "/api/2.1/unity-catalog/current-metastore-assignment", func(req testserver.Request) any {
|
server.Handle("GET", "/api/2.1/unity-catalog/current-metastore-assignment", func(req testserver.Request) any {
|
||||||
return testMetastore
|
return TestMetastore
|
||||||
})
|
})
|
||||||
|
|
||||||
server.Handle("GET", "/api/2.0/permissions/directories/{objectId}", func(req testserver.Request) any {
|
server.Handle("GET", "/api/2.0/permissions/directories/{objectId}", func(req testserver.Request) any {
|
Loading…
Reference in New Issue