Skip to content

Commit

Permalink
rename RequireOutput to AssertOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Dec 20, 2024
1 parent ca24b15 commit abcf45d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions integration/bundle/init_default_python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ func testDefaultPython(t *testing.T, pythonVersion string) {
err = os.WriteFile(filepath.Join(tmpDir, "config.json"), b, 0o644)
require.NoError(t, err)

testcli.RequireOutput(t, ctx, []string{"bundle", "init", "default-python", "--config-file", "config.json"}, "testdata/default_python/bundle_init.txt")
testcli.AssertOutput(t, ctx, []string{"bundle", "init", "default-python", "--config-file", "config.json"}, "testdata/default_python/bundle_init.txt")
testutil.Chdir(t, projectName)

testcli.RequireOutput(t, ctx, []string{"bundle", "validate"}, "testdata/default_python/bundle_validate.txt")

testcli.RequireOutput(t, ctx, []string{"bundle", "deploy"}, "testdata/default_python/bundle_deploy.txt")
t.Cleanup(func() {
// Delete the stack
testcli.RequireSuccessfulRun(t, ctx, "bundle", "destroy", "--auto-approve")
})

testcli.AssertOutput(t, ctx, []string{"bundle", "validate"}, "testdata/default_python/bundle_validate.txt")
testcli.AssertOutput(t, ctx, []string{"bundle", "deploy"}, "testdata/default_python/bundle_deploy.txt")

ignoredFields := []string{
"/bundle/terraform/exec_path",
"/resources/jobs/project_name_$UNIQUE_PRJ_job/email_notifications",
Expand All @@ -108,6 +108,5 @@ func testDefaultPython(t *testing.T, pythonVersion string) {
"/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/url",
"/workspace/current_user",
}

testcli.RequireOutputJQ(t, ctx, []string{"bundle", "summary", "--output", "json"}, "testdata/default_python/bundle_summary.txt", ignoredFields)
testcli.AssertOutputJQ(t, ctx, []string{"bundle", "summary", "--output", "json"}, "testdata/default_python/bundle_summary.txt", ignoredFields)
}
12 changes: 6 additions & 6 deletions internal/testcli/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/databricks/cli/libs/testdiff"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/iam"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)

var OverwriteMode = os.Getenv("TESTS_OUTPUT") == "OVERWRITE"
Expand All @@ -26,7 +26,7 @@ func ReadFile(t testutil.TestingT, ctx context.Context, filename string) string
if os.IsNotExist(err) {
return ""
}
require.NoError(t, err)
assert.NoError(t, err)
// On CI, on Windows \n in the file somehow end up as \r\n
return NormalizeNewlines(string(data))
}
Expand All @@ -35,18 +35,18 @@ func captureOutput(t testutil.TestingT, ctx context.Context, args []string) stri
t.Logf("run args: [%s]", strings.Join(args, ", "))
r := NewRunner(t, ctx, args...)
stdout, stderr, err := r.Run()
require.NoError(t, err)
assert.NoError(t, err)
out := stderr.String() + stdout.String()
return ReplaceOutput(t, ctx, out)
}

func WriteFile(t testutil.TestingT, filename, data string) {
t.Logf("Overwriting %s", filename)
err := os.WriteFile(filename, []byte(data), 0o644)
require.NoError(t, err)
assert.NoError(t, err)
}

func RequireOutput(t testutil.TestingT, ctx context.Context, args []string, expectedFilename string) {
func AssertOutput(t testutil.TestingT, ctx context.Context, args []string, expectedFilename string) {
_, filename, _, _ := runtime.Caller(1)
dir := filepath.Dir(filename)
expectedPath := filepath.Join(dir, expectedFilename)
Expand All @@ -64,7 +64,7 @@ func RequireOutput(t testutil.TestingT, ctx context.Context, args []string, expe
}
}

func RequireOutputJQ(t testutil.TestingT, ctx context.Context, args []string, expectedFilename string, ignorePaths []string) {
func AssertOutputJQ(t testutil.TestingT, ctx context.Context, args []string, expectedFilename string, ignorePaths []string) {
_, filename, _, _ := runtime.Caller(1)
dir := filepath.Dir(filename)
expectedPath := filepath.Join(dir, expectedFilename)
Expand Down

0 comments on commit abcf45d

Please sign in to comment.