Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/acc/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"path"
"path/filepath"
"strings"
"testing"

"github.com/databricks/cli/internal/testutil"
)

// Detects if test is run from "debug test" feature in VS Code.
Expand All @@ -16,7 +17,7 @@ func isInDebug() bool {
}

// Loads debug environment from ~/.databricks/debug-env.json.
func loadDebugEnvIfRunFromIDE(t *testing.T, key string) {
func loadDebugEnvIfRunFromIDE(t testutil.TestingT, key string) {
if !isInDebug() {
return
}
Expand Down
13 changes: 6 additions & 7 deletions internal/acc/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"testing"

"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go"
Expand All @@ -15,7 +14,7 @@ import (
)

type WorkspaceT struct {
*testing.T
testutil.TestingT

W *databricks.WorkspaceClient

Expand All @@ -24,7 +23,7 @@ type WorkspaceT struct {
exec *compute.CommandExecutorV2
}

func WorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
func WorkspaceTest(t testutil.TestingT) (context.Context, *WorkspaceT) {
loadDebugEnvIfRunFromIDE(t, "workspace")

t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))
Expand All @@ -33,7 +32,7 @@ func WorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
require.NoError(t, err)

wt := &WorkspaceT{
T: t,
TestingT: t,

W: w,

Expand All @@ -44,7 +43,7 @@ func WorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
}

// Run the workspace test only on UC workspaces.
func UcWorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
func UcWorkspaceTest(t testutil.TestingT) (context.Context, *WorkspaceT) {
loadDebugEnvIfRunFromIDE(t, "workspace")

t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))
Expand All @@ -60,7 +59,7 @@ func UcWorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
require.NoError(t, err)

wt := &WorkspaceT{
T: t,
TestingT: t,

W: w,

Expand All @@ -71,7 +70,7 @@ func UcWorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
}

func (t *WorkspaceT) TestClusterID() string {
clusterID := testutil.GetEnvOrSkipTest(t.T, "TEST_BRICKS_CLUSTER_ID")
clusterID := testutil.GetEnvOrSkipTest(t, "TEST_BRICKS_CLUSTER_ID")
err := t.W.Clusters.EnsureClusterIsRunning(t.ctx, clusterID)
require.NoError(t, err)
return clusterID
Expand Down
2 changes: 1 addition & 1 deletion internal/bundle/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestAccDeployBundleWithCluster(t *testing.T) {
ctx, wt := acc.WorkspaceTest(t)

if testutil.IsAWSCloud(wt.T) {
if testutil.IsAWSCloud(wt) {
t.Skip("Skipping test for AWS cloud because it is not permitted to create clusters")
}

Expand Down
8 changes: 4 additions & 4 deletions internal/bundle/deploy_to_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func TestAccDeployBasicToSharedWorkspacePath(t *testing.T) {
require.NoError(t, err)

t.Cleanup(func() {
err = destroyBundle(wt.T, ctx, bundleRoot)
require.NoError(wt.T, err)
err = destroyBundle(wt, ctx, bundleRoot)
require.NoError(wt, err)
})

err = deployBundle(wt.T, ctx, bundleRoot)
require.NoError(wt.T, err)
err = deployBundle(wt, ctx, bundleRoot)
require.NoError(wt, err)
}
30 changes: 15 additions & 15 deletions internal/bundle/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"os/exec"
"path/filepath"
"strings"
"testing"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/filer"
Expand All @@ -26,12 +26,12 @@ import (

const defaultSparkVersion = "13.3.x-snapshot-scala2.12"

func initTestTemplate(t *testing.T, ctx context.Context, templateName string, config map[string]any) (string, error) {
func initTestTemplate(t testutil.TestingT, ctx context.Context, templateName string, config map[string]any) (string, error) {
bundleRoot := t.TempDir()
return initTestTemplateWithBundleRoot(t, ctx, templateName, config, bundleRoot)
}

func initTestTemplateWithBundleRoot(t *testing.T, ctx context.Context, templateName string, config map[string]any, bundleRoot string) (string, error) {
func initTestTemplateWithBundleRoot(t testutil.TestingT, ctx context.Context, templateName string, config map[string]any, bundleRoot string) (string, error) {
templateRoot := filepath.Join("bundles", templateName)

configFilePath, err := writeConfigFile(t, config)
Expand All @@ -49,7 +49,7 @@ func initTestTemplateWithBundleRoot(t *testing.T, ctx context.Context, templateN
return bundleRoot, err
}

func writeConfigFile(t *testing.T, config map[string]any) (string, error) {
func writeConfigFile(t testutil.TestingT, config map[string]any) (string, error) {
bytes, err := json.Marshal(config)
if err != nil {
return "", err
Expand All @@ -63,42 +63,42 @@ func writeConfigFile(t *testing.T, config map[string]any) (string, error) {
return filepath, err
}

func validateBundle(t *testing.T, ctx context.Context, path string) ([]byte, error) {
func validateBundle(t testutil.TestingT, ctx context.Context, path string) ([]byte, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
c := internal.NewCobraTestRunnerWithContext(t, ctx, "bundle", "validate", "--output", "json")
stdout, _, err := c.Run()
return stdout.Bytes(), err
}

func mustValidateBundle(t *testing.T, ctx context.Context, path string) []byte {
func mustValidateBundle(t testutil.TestingT, ctx context.Context, path string) []byte {
data, err := validateBundle(t, ctx, path)
require.NoError(t, err)
return data
}

func unmarshalConfig(t *testing.T, data []byte) *bundle.Bundle {
func unmarshalConfig(t testutil.TestingT, data []byte) *bundle.Bundle {
bundle := &bundle.Bundle{}
err := json.Unmarshal(data, &bundle.Config)
require.NoError(t, err)
return bundle
}

func deployBundle(t *testing.T, ctx context.Context, path string) error {
func deployBundle(t testutil.TestingT, ctx context.Context, path string) error {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
c := internal.NewCobraTestRunnerWithContext(t, ctx, "bundle", "deploy", "--force-lock", "--auto-approve")
_, _, err := c.Run()
return err
}

func deployBundleWithArgs(t *testing.T, ctx context.Context, path string, args ...string) (string, string, error) {
func deployBundleWithArgs(t testutil.TestingT, ctx context.Context, path string, args ...string) (string, string, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
args = append([]string{"bundle", "deploy"}, args...)
c := internal.NewCobraTestRunnerWithContext(t, ctx, args...)
stdout, stderr, err := c.Run()
return stdout.String(), stderr.String(), err
}

func deployBundleWithFlags(t *testing.T, ctx context.Context, path string, flags []string) error {
func deployBundleWithFlags(t testutil.TestingT, ctx context.Context, path string, flags []string) error {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
args := []string{"bundle", "deploy", "--force-lock"}
args = append(args, flags...)
Expand All @@ -107,7 +107,7 @@ func deployBundleWithFlags(t *testing.T, ctx context.Context, path string, flags
return err
}

func runResource(t *testing.T, ctx context.Context, path, key string) (string, error) {
func runResource(t testutil.TestingT, ctx context.Context, path, key string) (string, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
ctx = cmdio.NewContext(ctx, cmdio.Default())

Expand All @@ -116,7 +116,7 @@ func runResource(t *testing.T, ctx context.Context, path, key string) (string, e
return stdout.String(), err
}

func runResourceWithParams(t *testing.T, ctx context.Context, path, key string, params ...string) (string, error) {
func runResourceWithParams(t testutil.TestingT, ctx context.Context, path, key string, params ...string) (string, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
ctx = cmdio.NewContext(ctx, cmdio.Default())

Expand All @@ -128,22 +128,22 @@ func runResourceWithParams(t *testing.T, ctx context.Context, path, key string,
return stdout.String(), err
}

func destroyBundle(t *testing.T, ctx context.Context, path string) error {
func destroyBundle(t testutil.TestingT, ctx context.Context, path string) error {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
c := internal.NewCobraTestRunnerWithContext(t, ctx, "bundle", "destroy", "--auto-approve")
_, _, err := c.Run()
return err
}

func getBundleRemoteRootPath(w *databricks.WorkspaceClient, t *testing.T, uniqueId string) string {
func getBundleRemoteRootPath(w *databricks.WorkspaceClient, t testutil.TestingT, uniqueId string) string {
// Compute root path for the bundle deployment
me, err := w.CurrentUser.Me(context.Background())
require.NoError(t, err)
root := fmt.Sprintf("/Workspace/Users/%s/.bundle/%s", me.UserName, uniqueId)
return root
}

func blackBoxRun(t *testing.T, root string, args ...string) (stdout, stderr string) {
func blackBoxRun(t testutil.TestingT, root string, args ...string) (stdout, stderr string) {
gitRoot, err := folders.FindDirWithLeaf(".", ".git")
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion internal/bundle/python_wheel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAccPythonWheelTaskDeployAndRunWithWrapper(t *testing.T) {
func TestAccPythonWheelTaskDeployAndRunOnInteractiveCluster(t *testing.T) {
_, wt := acc.WorkspaceTest(t)

if testutil.IsAWSCloud(wt.T) {
if testutil.IsAWSCloud(wt) {
t.Skip("Skipping test for AWS cloud because it is not permitted to create clusters")
}

Expand Down
6 changes: 3 additions & 3 deletions internal/filer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestAccFilerRecursiveDelete(t *testing.T) {

for _, testCase := range []struct {
name string
f func(t *testing.T) (filer.Filer, string)
f func(t testutil.TestingT) (filer.Filer, string)
}{
{"local", setupLocalFiler},
{"workspace files", setupWsfsFiler},
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestAccFilerReadWrite(t *testing.T) {

for _, testCase := range []struct {
name string
f func(t *testing.T) (filer.Filer, string)
f func(t testutil.TestingT) (filer.Filer, string)
}{
{"local", setupLocalFiler},
{"workspace files", setupWsfsFiler},
Expand Down Expand Up @@ -342,7 +342,7 @@ func TestAccFilerReadDir(t *testing.T) {

for _, testCase := range []struct {
name string
f func(t *testing.T) (filer.Filer, string)
f func(t testutil.TestingT) (filer.Filer, string)
}{
{"local", setupLocalFiler},
{"workspace files", setupWsfsFiler},
Expand Down
4 changes: 2 additions & 2 deletions internal/fs_cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func assertTargetDir(t *testing.T, ctx context.Context, f filer.Filer) {

type cpTest struct {
name string
setupSource func(*testing.T) (filer.Filer, string)
setupTarget func(*testing.T) (filer.Filer, string)
setupSource func(testutil.TestingT) (filer.Filer, string)
setupTarget func(testutil.TestingT) (filer.Filer, string)
}

func copyTests() []cpTest {
Expand Down
2 changes: 1 addition & 1 deletion internal/fs_ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

type fsTest struct {
name string
setupFiler func(t *testing.T) (filer.Filer, string)
setupFiler func(t testutil.TestingT) (filer.Filer, string)
}

var fsTests = []fsTest{
Expand Down
Loading
Loading