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
3 changes: 2 additions & 1 deletion bundle/config/validate/files_to_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package validate

import (
"context"
"path/filepath"
"testing"

"github.com/databricks/cli/bundle"
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestFilesToSync_EverythingIgnored(t *testing.T) {
b := setupBundleForFilesToSyncTest(t)

// Ignore all files.
testutil.WriteFile(t, "*\n.*\n", b.BundleRootPath, ".gitignore")
testutil.WriteFile(t, filepath.Join(b.BundleRootPath, ".gitignore"), "*\n.*\n")

ctx := context.Background()
rb := bundle.ReadOnly(b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func writeFakeDashboardState(t *testing.T, ctx context.Context, b *bundle.Bundle
require.NoError(t, err)

// Write fake state file.
testutil.WriteFile(t, `
testutil.WriteFile(t, filepath.Join(tfDir, TerraformStateFileName), `
{
"version": 4,
"terraform_version": "1.5.5",
Expand Down Expand Up @@ -187,5 +187,5 @@ func writeFakeDashboardState(t *testing.T, ctx context.Context, b *bundle.Bundle
}
]
}
`, filepath.Join(tfDir, TerraformStateFileName))
`)
}
9 changes: 5 additions & 4 deletions internal/acc/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/service/compute"
Expand All @@ -26,7 +27,7 @@ type WorkspaceT struct {
func WorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
loadDebugEnvIfRunFromIDE(t, "workspace")

t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

w, err := databricks.NewWorkspaceClient()
require.NoError(t, err)
Expand All @@ -46,7 +47,7 @@ func WorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
func UcWorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
loadDebugEnvIfRunFromIDE(t, "workspace")

t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

if os.Getenv("TEST_METASTORE_ID") == "" {
t.Skipf("Skipping on non-UC workspaces")
Expand All @@ -70,7 +71,7 @@ func UcWorkspaceTest(t *testing.T) (context.Context, *WorkspaceT) {
}

func (t *WorkspaceT) TestClusterID() string {
clusterID := GetEnvOrSkipTest(t.T, "TEST_BRICKS_CLUSTER_ID")
clusterID := testutil.GetEnvOrSkipTest(t.T, "TEST_BRICKS_CLUSTER_ID")
err := t.W.Clusters.EnsureClusterIsRunning(t.ctx, clusterID)
require.NoError(t, err)
return clusterID
Expand Down Expand Up @@ -103,7 +104,7 @@ func (t *WorkspaceT) TemporaryWorkspaceDir(name ...string) string {
me, err := t.W.CurrentUser.Me(ctx)
require.NoError(t, err)

basePath := fmt.Sprintf("/Users/%s/%s", me.UserName, RandomName(name...))
basePath := fmt.Sprintf("/Users/%s/%s", me.UserName, testutil.RandomName(name...))

t.Logf("Creating %s", basePath)
err = t.W.Workspace.MkdirsByPath(ctx, basePath)
Expand Down
3 changes: 2 additions & 1 deletion internal/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package internal
import (
"testing"

"github.com/databricks/cli/internal/testutil"
"github.com/stretchr/testify/assert"
)

func TestAccAlertsCreateErrWhenNoArguments(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

_, _, err := RequireErrorRun(t, "alerts-legacy", "create")
assert.Equal(t, "please provide command input in JSON format by specifying the --json flag", err.Error())
Expand Down
11 changes: 7 additions & 4 deletions internal/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import (
"encoding/json"
"fmt"
"path"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

_ "github.com/databricks/cli/cmd/api"
"github.com/databricks/cli/internal/testutil"
)

func TestAccApiGet(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

stdout, _ := RequireSuccessfulRun(t, "api", "get", "/api/2.0/preview/scim/v2/Me")

Expand All @@ -28,14 +30,15 @@ func TestAccApiGet(t *testing.T) {
}

func TestAccApiPost(t *testing.T) {
env := GetEnvOrSkipTest(t, "CLOUD_ENV")
env := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
t.Log(env)
if env == "gcp" {
t.Skip("DBFS REST API is disabled on gcp")
}

dbfsPath := path.Join("/tmp/databricks/integration", RandomName("api-post"))
requestPath := writeFile(t, "body.json", fmt.Sprintf(`{
dbfsPath := path.Join("/tmp/databricks/integration", testutil.RandomName("api-post"))
requestPath := filepath.Join(t.TempDir(), "body.json")
testutil.WriteFile(t, requestPath, fmt.Sprintf(`{
"path": "%s"
}`, dbfsPath))

Expand Down
5 changes: 3 additions & 2 deletions internal/auth_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"fmt"
"testing"

"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go"
"github.com/stretchr/testify/require"
)

func TestAuthDescribeSuccess(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

stdout, _ := RequireSuccessfulRun(t, "auth", "describe")
outStr := stdout.String()
Expand All @@ -31,7 +32,7 @@ func TestAuthDescribeSuccess(t *testing.T) {
}

func TestAuthDescribeFailure(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

stdout, _ := RequireSuccessfulRun(t, "auth", "describe", "--profile", "nonexistent")
outStr := stdout.String()
Expand Down
5 changes: 3 additions & 2 deletions internal/bundle/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/jobs"
Expand Down Expand Up @@ -234,7 +235,7 @@ func TestAccUploadArtifactFileToVolumeThatDoesNotExist(t *testing.T) {
ctx, wt := acc.UcWorkspaceTest(t)
w := wt.W

schemaName := internal.RandomName("schema-")
schemaName := testutil.RandomName("schema-")

_, err := w.Schemas.Create(ctx, catalog.CreateSchema{
CatalogName: "main",
Expand Down Expand Up @@ -271,7 +272,7 @@ func TestAccUploadArtifactToVolumeNotYetDeployed(t *testing.T) {
ctx, wt := acc.UcWorkspaceTest(t)
w := wt.W

schemaName := internal.RandomName("schema-")
schemaName := testutil.RandomName("schema-")

_, err := w.Schemas.Create(ctx, catalog.CreateSchema{
CatalogName: "main",
Expand Down
7 changes: 4 additions & 3 deletions internal/bundle/bind_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/google/uuid"
Expand All @@ -16,7 +17,7 @@ import (
)

func TestAccBindJobToExistingJob(t *testing.T) {
env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
env := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
t.Log(env)

ctx, wt := acc.WorkspaceTest(t)
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestAccBindJobToExistingJob(t *testing.T) {
}

func TestAccAbortBind(t *testing.T) {
env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
env := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
t.Log(env)

ctx, wt := acc.WorkspaceTest(t)
Expand Down Expand Up @@ -130,7 +131,7 @@ func TestAccAbortBind(t *testing.T) {
}

func TestAccGenerateAndBind(t *testing.T) {
env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
env := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
t.Log(env)

ctx, wt := acc.WorkspaceTest(t)
Expand Down
3 changes: 2 additions & 1 deletion internal/bundle/dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go/service/dashboards"
"github.com/databricks/databricks-sdk-go/service/workspace"
"github.com/google/uuid"
Expand All @@ -15,7 +16,7 @@ import (
func TestAccDashboards(t *testing.T) {
ctx, wt := acc.WorkspaceTest(t)

warehouseID := acc.GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID")
warehouseID := testutil.GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID")
uniqueID := uuid.New().String()
root, err := initTestTemplate(t, ctx, "dashboards", map[string]any{
"unique_id": uniqueID,
Expand Down
3 changes: 2 additions & 1 deletion internal/bundle/deployment_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"github.com/databricks/cli/bundle/deploy"
"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

func TestAccFilesAreSyncedCorrectlyWhenNoSnapshot(t *testing.T) {
env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
env := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
t.Log(env)

ctx, wt := acc.WorkspaceTest(t)
Expand Down
2 changes: 1 addition & 1 deletion internal/bundle/generate_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (gt *generateJobTest) createTestJob(ctx context.Context) int64 {
require.NoError(t, err)

resp, err := w.Jobs.Create(ctx, jobs.CreateJob{
Name: internal.RandomName("generated-job-"),
Name: testutil.RandomName("generated-job-"),
Tasks: []jobs.Task{
{
TaskKey: "test",
Expand Down
7 changes: 4 additions & 3 deletions internal/bundle/generate_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/databricks/cli/internal"
"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/filer"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/pipelines"
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestAccGenerateFromExistingPipelineAndDeploy(t *testing.T) {
generatedYaml := string(data)

// Replace pipeline name
generatedYaml = strings.ReplaceAll(generatedYaml, name, internal.RandomName("copy-generated-pipeline-"))
generatedYaml = strings.ReplaceAll(generatedYaml, name, testutil.RandomName("copy-generated-pipeline-"))
err = os.WriteFile(fileName, []byte(generatedYaml), 0o644)
require.NoError(t, err)

Expand Down Expand Up @@ -94,10 +95,10 @@ func (gt *generatePipelineTest) createTestPipeline(ctx context.Context) (string,
err = f.Write(ctx, "test.py", strings.NewReader("print('Hello!')"))
require.NoError(t, err)

env := internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
env := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
nodeTypeId := internal.GetNodeTypeId(env)

name := internal.RandomName("generated-pipeline-")
name := testutil.RandomName("generated-pipeline-")
resp, err := w.Pipelines.Create(ctx, pipelines.CreatePipeline{
Name: name,
Libraries: []pipelines.PipelineLibrary{
Expand Down
6 changes: 3 additions & 3 deletions internal/bundle/spark_jar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func runSparkJarTestCommon(t *testing.T, ctx context.Context, sparkVersion, artifactPath string) {
cloudEnv := internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
cloudEnv := testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
nodeTypeId := internal.GetNodeTypeId(cloudEnv)
tmpDir := t.TempDir()
instancePoolId := env.Get(ctx, "TEST_INSTANCE_POOL_ID")
Expand Down Expand Up @@ -54,7 +54,7 @@ func runSparkJarTestFromWorkspace(t *testing.T, sparkVersion string) {
}

func TestAccSparkJarTaskDeployAndRunOnVolumes(t *testing.T) {
internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
testutil.RequireJDK(t, context.Background(), "1.8.0")

// Failure on earlier DBR versions:
Expand All @@ -78,7 +78,7 @@ func TestAccSparkJarTaskDeployAndRunOnVolumes(t *testing.T) {
}

func TestAccSparkJarTaskDeployAndRunOnWorkspace(t *testing.T) {
internal.GetEnvOrSkipTest(t, "CLOUD_ENV")
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")
testutil.RequireJDK(t, context.Background(), "1.8.0")

// Failure on earlier DBR versions:
Expand Down
5 changes: 3 additions & 2 deletions internal/bundle/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bundle
import (
"context"
"encoding/json"
"path/filepath"
"testing"

"github.com/databricks/cli/internal/testutil"
Expand All @@ -16,7 +17,7 @@ func TestAccBundleValidate(t *testing.T) {
testutil.GetEnvOrSkipTest(t, "CLOUD_ENV")

tmpDir := t.TempDir()
testutil.WriteFile(t,
testutil.WriteFile(t, filepath.Join(tmpDir, "databricks.yml"),
`
bundle:
name: "foobar"
Expand All @@ -33,7 +34,7 @@ resources:
inner_loop:
name: inner loop

`, tmpDir, "databricks.yml")
`)

ctx := context.Background()
stdout, err := validateBundle(t, ctx, tmpDir)
Expand Down
5 changes: 3 additions & 2 deletions internal/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"testing"

"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/databricks-sdk-go/listing"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAccClustersList(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

stdout, stderr := RequireSuccessfulRun(t, "clusters", "list")
outStr := stdout.String()
Expand All @@ -28,7 +29,7 @@ func TestAccClustersList(t *testing.T) {
}

func TestAccClustersGet(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
t.Log(testutil.GetEnvOrSkipTest(t, "CLOUD_ENV"))

clusterId := findValidClusterID(t)
stdout, stderr := RequireSuccessfulRun(t, "clusters", "get", clusterId)
Expand Down
3 changes: 2 additions & 1 deletion internal/dashboard_assumptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/dyn/convert"
"github.com/databricks/cli/libs/dyn/merge"
Expand All @@ -25,7 +26,7 @@ func TestAccDashboardAssumptions_WorkspaceImport(t *testing.T) {

dashboardName := "New Dashboard"
dashboardPayload := []byte(`{"pages":[{"name":"2506f97a","displayName":"New Page"}]}`)
warehouseId := acc.GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID")
warehouseId := testutil.GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID")

dir := wt.TemporaryWorkspaceDir("dashboard-assumptions-")

Expand Down
Loading
Loading