Skip to content

Commit

Permalink
Drop 'WithContext' suffix now that it is the default
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Dec 16, 2024
1 parent fa6285d commit 35dc5c4
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cmd/labs/installed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestListsInstalledProjects(t *testing.T) {
ctx := context.Background()
ctx = env.WithUserHomeDir(ctx, "project/testdata/installed-in-home")
r := testcli.NewRunnerWithContext(t, ctx, "labs", "installed")
r := testcli.NewRunner(t, ctx, "labs", "installed")
r.RunAndExpectOutput(`
Name Description Version
blueprint Blueprint Project v0.3.15
Expand Down
2 changes: 1 addition & 1 deletion cmd/labs/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestListingWorks(t *testing.T) {
ctx := context.Background()
ctx = env.WithUserHomeDir(ctx, "project/testdata/installed-in-home")
c := testcli.NewRunnerWithContext(t, ctx, "labs", "list")
c := testcli.NewRunner(t, ctx, "labs", "list")
stdout, _, err := c.Run()
require.NoError(t, err)
require.Contains(t, stdout.String(), "ucx")
Expand Down
8 changes: 4 additions & 4 deletions cmd/labs/project/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func devEnvContext(t *testing.T) context.Context {

func TestRunningBlueprintEcho(t *testing.T) {
ctx := devEnvContext(t)
r := testcli.NewRunnerWithContext(t, ctx, "labs", "blueprint", "echo")
r := testcli.NewRunner(t, ctx, "labs", "blueprint", "echo")
var out echoOut
r.RunAndParseJSON(&out)
assert.Equal(t, "echo", out.Command)
Expand All @@ -41,14 +41,14 @@ func TestRunningBlueprintEcho(t *testing.T) {

func TestRunningBlueprintEchoProfileWrongOverride(t *testing.T) {
ctx := devEnvContext(t)
r := testcli.NewRunnerWithContext(t, ctx, "labs", "blueprint", "echo", "--profile", "workspace-profile")
r := testcli.NewRunner(t, ctx, "labs", "blueprint", "echo", "--profile", "workspace-profile")
_, _, err := r.Run()
assert.ErrorIs(t, err, databricks.ErrNotAccountClient)
}

func TestRunningCommand(t *testing.T) {
ctx := devEnvContext(t)
r := testcli.NewRunnerWithContext(t, ctx, "labs", "blueprint", "foo")
r := testcli.NewRunner(t, ctx, "labs", "blueprint", "foo")
r.WithStdin()
defer r.CloseStdin()

Expand All @@ -60,7 +60,7 @@ func TestRunningCommand(t *testing.T) {

func TestRenderingTable(t *testing.T) {
ctx := devEnvContext(t)
r := testcli.NewRunnerWithContext(t, ctx, "labs", "blueprint", "table")
r := testcli.NewRunner(t, ctx, "labs", "blueprint", "table")
r.RunAndExpectOutput(`
Key Value
First Second
Expand Down
6 changes: 3 additions & 3 deletions cmd/labs/project/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestInstallerWorksForReleases(t *testing.T) {
// │ │ │ └── site-packages
// │ │ │ ├── ...
// │ │ │ ├── distutils-precedence.pth
r := testcli.NewRunnerWithContext(t, ctx, "labs", "install", "blueprint", "--debug")
r := testcli.NewRunner(t, ctx, "labs", "install", "blueprint", "--debug")
r.RunAndExpectOutput("setting up important infrastructure")
}

Expand Down Expand Up @@ -356,7 +356,7 @@ account_id = abc
// └── databrickslabs-blueprint-releases.json

// `databricks labs install .` means "verify this installer i'm developing does work"
r := testcli.NewRunnerWithContext(t, ctx, "labs", "install", ".")
r := testcli.NewRunner(t, ctx, "labs", "install", ".")
r.WithStdin()
defer r.CloseStdin()

Expand Down Expand Up @@ -426,7 +426,7 @@ func TestUpgraderWorksForReleases(t *testing.T) {
ctx = env.Set(ctx, "DATABRICKS_CLUSTER_ID", "installer-cluster")
ctx = env.Set(ctx, "DATABRICKS_WAREHOUSE_ID", "installer-warehouse")

r := testcli.NewRunnerWithContext(t, ctx, "labs", "upgrade", "blueprint")
r := testcli.NewRunner(t, ctx, "labs", "upgrade", "blueprint")
r.RunAndExpectOutput("setting up important infrastructure")

// Check if the stub was called with the 'python -m pip install' command
Expand Down
10 changes: 5 additions & 5 deletions integration/bundle/bind_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestBindJobToExistingJob(t *testing.T) {
})

ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "deployment", "bind", "foo", fmt.Sprint(jobId), "--auto-approve")
c := testcli.NewRunner(t, ctx, "bundle", "deployment", "bind", "foo", fmt.Sprint(jobId), "--auto-approve")
_, _, err = c.Run()
require.NoError(t, err)

Expand All @@ -59,7 +59,7 @@ func TestBindJobToExistingJob(t *testing.T) {
require.Equal(t, job.Settings.Name, fmt.Sprintf("test-job-basic-%s", uniqueId))
require.Contains(t, job.Settings.Tasks[0].SparkPythonTask.PythonFile, "hello_world.py")

c = testcli.NewRunnerWithContext(t, ctx, "bundle", "deployment", "unbind", "foo")
c = testcli.NewRunner(t, ctx, "bundle", "deployment", "unbind", "foo")
_, _, err = c.Run()
require.NoError(t, err)

Expand Down Expand Up @@ -102,7 +102,7 @@ func TestAbortBind(t *testing.T) {
// Bind should fail because prompting is not possible.
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "deployment", "bind", "foo", fmt.Sprint(jobId))
c := testcli.NewRunner(t, ctx, "bundle", "deployment", "bind", "foo", fmt.Sprint(jobId))

// Expect error suggesting to use --auto-approve
_, _, err = c.Run()
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestGenerateAndBind(t *testing.T) {
})

ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "generate", "job",
c := testcli.NewRunner(t, ctx, "bundle", "generate", "job",
"--key", "test_job_key",
"--existing-job-id", fmt.Sprint(jobId),
"--config-dir", filepath.Join(bundleRoot, "resources"),
Expand All @@ -165,7 +165,7 @@ func TestGenerateAndBind(t *testing.T) {

require.Len(t, matches, 1)

c = testcli.NewRunnerWithContext(t, ctx, "bundle", "deployment", "bind", "test_job_key", fmt.Sprint(jobId), "--auto-approve")
c = testcli.NewRunner(t, ctx, "bundle", "deployment", "bind", "test_job_key", fmt.Sprint(jobId), "--auto-approve")
_, _, err = c.Run()
require.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions integration/bundle/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestBundleDeployUcSchemaFailsWithoutAutoApprove(t *testing.T) {
// Redeploy the bundle
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "deploy", "--force-lock")
c := testcli.NewRunner(t, ctx, "bundle", "deploy", "--force-lock")
stdout, stderr, err := c.Run()

assert.EqualError(t, err, root.ErrAlreadyPrinted.Error())
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestBundlePipelineDeleteWithoutAutoApprove(t *testing.T) {
// Redeploy the bundle. Expect it to fail because deleting the pipeline requires --auto-approve.
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "deploy", "--force-lock")
c := testcli.NewRunner(t, ctx, "bundle", "deploy", "--force-lock")
stdout, stderr, err := c.Run()

assert.EqualError(t, err, root.ErrAlreadyPrinted.Error())
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestBundlePipelineRecreateWithoutAutoApprove(t *testing.T) {
// Redeploy the bundle, pointing the DLT pipeline to a different UC catalog.
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "deploy", "--force-lock", "--var=\"catalog=whatever\"")
c := testcli.NewRunner(t, ctx, "bundle", "deploy", "--force-lock", "--var=\"catalog=whatever\"")
stdout, stderr, err := c.Run()

assert.EqualError(t, err, root.ErrAlreadyPrinted.Error())
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestDeployUcVolume(t *testing.T) {
// Recreation of the volume without --auto-approve should fail since prompting is not possible
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
stdout, stderr, err := testcli.NewRunnerWithContext(t, ctx, "bundle", "deploy", "--var=schema_name=${resources.schemas.schema2.name}").Run()
stdout, stderr, err := testcli.NewRunner(t, ctx, "bundle", "deploy", "--var=schema_name=${resources.schemas.schema2.name}").Run()
assert.Error(t, err)
assert.Contains(t, stderr.String(), `This action will result in the deletion or recreation of the following volumes.
For managed volumes, the files stored in the volume are also deleted from your
Expand All @@ -297,7 +297,7 @@ is removed from the catalog, but the underlying files are not deleted:
// Successfully recreate the volume with --auto-approve
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
ctx = env.Set(ctx, "TERM", "dumb")
_, _, err = testcli.NewRunnerWithContext(t, ctx, "bundle", "deploy", "--var=schema_name=${resources.schemas.schema2.name}", "--auto-approve").Run()
_, _, err = testcli.NewRunner(t, ctx, "bundle", "deploy", "--var=schema_name=${resources.schemas.schema2.name}", "--auto-approve").Run()
assert.NoError(t, err)

// Assert the volume is updated successfully
Expand Down
2 changes: 1 addition & 1 deletion integration/bundle/generate_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGenerateFromExistingJobAndDeploy(t *testing.T) {
})

ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "generate", "job",
c := testcli.NewRunner(t, ctx, "bundle", "generate", "job",
"--existing-job-id", fmt.Sprint(jobId),
"--config-dir", filepath.Join(bundleRoot, "resources"),
"--source-dir", filepath.Join(bundleRoot, "src"))
Expand Down
2 changes: 1 addition & 1 deletion integration/bundle/generate_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestGenerateFromExistingPipelineAndDeploy(t *testing.T) {
})

ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot)
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "generate", "pipeline",
c := testcli.NewRunner(t, ctx, "bundle", "generate", "pipeline",
"--existing-pipeline-id", fmt.Sprint(pipelineId),
"--config-dir", filepath.Join(bundleRoot, "resources"),
"--source-dir", filepath.Join(bundleRoot, "src"))
Expand Down
14 changes: 7 additions & 7 deletions integration/bundle/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func writeConfigFile(t testutil.TestingT, config map[string]any) (string, error)

func validateBundle(t testutil.TestingT, ctx context.Context, path string) ([]byte, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "validate", "--output", "json")
c := testcli.NewRunner(t, ctx, "bundle", "validate", "--output", "json")
stdout, _, err := c.Run()
return stdout.Bytes(), err
}
Expand All @@ -85,15 +85,15 @@ func unmarshalConfig(t testutil.TestingT, data []byte) *bundle.Bundle {

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

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 := testcli.NewRunnerWithContext(t, ctx, args...)
c := testcli.NewRunner(t, ctx, args...)
stdout, stderr, err := c.Run()
return stdout.String(), stderr.String(), err
}
Expand All @@ -102,7 +102,7 @@ func deployBundleWithFlags(t testutil.TestingT, ctx context.Context, path string
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
args := []string{"bundle", "deploy", "--force-lock"}
args = append(args, flags...)
c := testcli.NewRunnerWithContext(t, ctx, args...)
c := testcli.NewRunner(t, ctx, args...)
_, _, err := c.Run()
return err
}
Expand All @@ -111,7 +111,7 @@ func runResource(t testutil.TestingT, ctx context.Context, path, key string) (st
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
ctx = cmdio.NewContext(ctx, cmdio.Default())

c := testcli.NewRunnerWithContext(t, ctx, "bundle", "run", key)
c := testcli.NewRunner(t, ctx, "bundle", "run", key)
stdout, _, err := c.Run()
return stdout.String(), err
}
Expand All @@ -123,14 +123,14 @@ func runResourceWithParams(t testutil.TestingT, ctx context.Context, path, key s
args := make([]string, 0)
args = append(args, "bundle", "run", key)
args = append(args, params...)
c := testcli.NewRunnerWithContext(t, ctx, args...)
c := testcli.NewRunner(t, ctx, args...)
stdout, _, err := c.Run()
return stdout.String(), err
}

func destroyBundle(t testutil.TestingT, ctx context.Context, path string) error {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
c := testcli.NewRunnerWithContext(t, ctx, "bundle", "destroy", "--auto-approve")
c := testcli.NewRunner(t, ctx, "bundle", "destroy", "--auto-approve")
_, _, err := c.Run()
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration/cmd/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func setupSyncTest(t *testing.T, args ...string) (context.Context, *syncTest) {
"json",
}, args...)

c := testcli.NewRunnerWithContext(t, ctx, args...)
c := testcli.NewRunner(t, ctx, args...)
c.RunBackground()

return ctx, &syncTest{
Expand Down
6 changes: 3 additions & 3 deletions internal/testcli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (r *Runner) RunAndParseJSON(v any) {
require.NoError(r, err)
}

func NewRunnerWithContext(t testutil.TestingT, ctx context.Context, args ...string) *Runner {
func NewRunner(t testutil.TestingT, ctx context.Context, args ...string) *Runner {
return &Runner{
TestingT: t,

Expand All @@ -292,14 +292,14 @@ func NewRunnerWithContext(t testutil.TestingT, ctx context.Context, args ...stri

func RequireSuccessfulRun(t testutil.TestingT, ctx context.Context, args ...string) (bytes.Buffer, bytes.Buffer) {
t.Logf("run args: [%s]", strings.Join(args, ", "))
r := NewRunnerWithContext(t, ctx, args...)
r := NewRunner(t, ctx, args...)
stdout, stderr, err := r.Run()
require.NoError(t, err)
return stdout, stderr
}

func RequireErrorRun(t testutil.TestingT, ctx context.Context, args ...string) (bytes.Buffer, bytes.Buffer, error) {
r := NewRunnerWithContext(t, ctx, args...)
r := NewRunner(t, ctx, args...)
stdout, stderr, err := r.Run()
require.Error(t, err)
return stdout, stderr, err
Expand Down

0 comments on commit 35dc5c4

Please sign in to comment.