Skip to content

Commit

Permalink
Include acceptance tests in integration tests (#2242)
Browse files Browse the repository at this point in the history
## Changes
- Include acceptance directory in integration tests. Acceptance tests
will not start local server if CLOUD_ENV is set, so they become
integration tests.
- Add dependency for vendor to integration, so that CLI can be build
there.
- Implement LocalOnly option in test.toml to opt out of running
acceptance tests as integration tests. Use it in certain tests that are
difficult or not necessary to fix when run as integration tests.
- Update terraform test to redact timings out.
- Clean up .workspace.current_user from outputs of the tests.

## Tests
Existing tests.
  • Loading branch information
denik authored Feb 3, 2025
1 parent fcedfe4 commit f267318
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ schema:
docs:
go run ./bundle/docsgen ./bundle/internal/schema ./bundle/docsgen

INTEGRATION = gotestsum --format github-actions --rerun-fails --jsonfile output.json --packages "./integration/..." -- -parallel 4 -timeout=2h
INTEGRATION = gotestsum --format github-actions --rerun-fails --jsonfile output.json --packages "./acceptance ./integration/..." -- -parallel 4 -timeout=2h

integration:
integration: vendor
$(INTEGRATION)

integration-short:
integration-short: vendor
$(INTEGRATION) -short

.PHONY: lint lintcheck fmt test cover showcover build snapshot vendor schema integration integration-short acc-cover acc-showcover docs
5 changes: 5 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
t.Skipf("Disabled via GOOS.%s setting in %s", runtime.GOOS, configPath)
}

cloudEnv := os.Getenv("CLOUD_ENV")
if config.LocalOnly && cloudEnv != "" {
t.Skipf("Disabled via LocalOnly setting in %s (CLOUD_ENV=%s)", configPath, cloudEnv)
}

var tmpDir string
var err error
if KeepTmp {
Expand Down
1 change: 1 addition & 0 deletions acceptance/bundle/scripts/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LocalOnly = true # Deployment currently fails when run locally; once that is fixed, remove this setting
2 changes: 2 additions & 0 deletions acceptance/bundle/templates/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# At the moment, there are many differences across different envs w.r.t to catalog use, node type and so on.
LocalOnly = true
2 changes: 2 additions & 0 deletions acceptance/bundle/variables/env_overrides/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Cloud run fails with Error: failed to resolve cluster-policy: wrong-cluster-policy, err: Policy named 'wrong-cluster-policy' does not exist
LocalOnly = true
14 changes: 2 additions & 12 deletions acceptance/bundle/variables/git-branch/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"git": {
"actual_branch": "main",
"branch": "",
"bundle_root_path": ".",
"bundle_root_path": "."
},
"name": "git",
"target": "prod",
Expand All @@ -28,11 +28,6 @@
},
"workspace": {
"artifact_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/artifacts",
"current_user": {
"id": "$USER.Id",
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/files",
"resource_path": "/Workspace/Users/$USERNAME/.bundle/git/prod/resources",
"root_path": "/Workspace/Users/$USERNAME/.bundle/git/prod",
Expand All @@ -56,7 +51,7 @@ Validation OK!
"git": {
"actual_branch": "main",
"branch": "dev-branch",
"bundle_root_path": ".",
"bundle_root_path": "."
},
"name": "git",
"target": "dev",
Expand All @@ -78,11 +73,6 @@ Validation OK!
},
"workspace": {
"artifact_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/artifacts",
"current_user": {
"id": "$USER.Id",
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/files",
"resource_path": "/Workspace/Users/$USERNAME/.bundle/git/dev/resources",
"root_path": "/Workspace/Users/$USERNAME/.bundle/git/dev",
Expand Down
6 changes: 3 additions & 3 deletions acceptance/bundle/variables/git-branch/script
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
git-repo-init
trace $CLI bundle validate -o json | grep -v '"commit"'
trace $CLI bundle validate -o json | jq 'del(.workspace.current_user, .bundle.git.commit)'
trace $CLI bundle validate
trace $CLI bundle validate -o json -t dev | grep -v '"commit"'
trace $CLI bundle validate -t dev | grep -v '"commit"'
trace $CLI bundle validate -o json -t dev | jq 'del(.workspace.current_user, .bundle.git.commit)'
trace $CLI bundle validate -t dev
rm -fr .git
7 changes: 1 addition & 6 deletions acceptance/bundle/variables/prepend-workspace-var/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@
},
"workspace": {
"artifact_path": "/Users/$USERNAME/path/to/root/artifacts",
"current_user": {
"id": "$USER.Id",
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "/Users/$USERNAME/path/to/root/files",
"profile": "profile_name",
"resource_path": "/Users/$USERNAME/path/to/root/resources",
"root_path": "/Users/$USERNAME/path/to/root",
"state_path": "/Users/$USERNAME/path/to/root/state"
}
}
}
2 changes: 1 addition & 1 deletion acceptance/bundle/variables/prepend-workspace-var/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
echo /Workspace should be prepended on all paths, but it is not the case: #2181
$CLI bundle validate -o json
$CLI bundle validate -o json | jq 'del(.workspace.current_user)'
5 changes: 0 additions & 5 deletions acceptance/bundle/variables/resolve-builtin/output.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"artifact_path": "TestResolveVariableReferences/bar/artifacts",
"current_user": {
"id": "$USER.Id",
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "TestResolveVariableReferences/bar/baz",
"resource_path": "TestResolveVariableReferences/bar/resources",
"root_path": "TestResolveVariableReferences/bar",
Expand Down
2 changes: 1 addition & 1 deletion acceptance/bundle/variables/resolve-builtin/script
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$CLI bundle validate -o json | jq .workspace
$CLI bundle validate -o json | jq .workspace | jq 'del(.current_user)'
2 changes: 2 additions & 0 deletions acceptance/bundle/variables/resolve-builtin/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Cloud run fails with Error: Path (TestResolveVariableReferences/bar/baz) doesn't start with '/'
LocalOnly = true
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"artifact_path": "TestResolveVariableReferencesToBundleVariables/bar/artifacts",
"current_user": {
"id": "$USER.Id",
"short_name": "$USERNAME",
"userName": "$USERNAME"
},
"file_path": "TestResolveVariableReferencesToBundleVariables/bar/files",
"resource_path": "TestResolveVariableReferencesToBundleVariables/bar/resources",
"root_path": "TestResolveVariableReferencesToBundleVariables/bar",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$CLI bundle validate -o json | jq .workspace
$CLI bundle validate -o json | jq .workspace | jq 'del(.current_user)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Cloud run fails with Error: Path (TestResolveVariableReferencesToBundleVariables/bar/files) doesn't start with '/'
LocalOnly = true
3 changes: 3 additions & 0 deletions acceptance/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type TestConfig struct {
// If absent, default to true.
GOOS map[string]bool

// If true, do not run this test against cloud environment
LocalOnly bool

// List of additional replacements to apply on this test.
// Old is a regexp, New is a replacement expression.
Repls []testdiff.Replacement
Expand Down
2 changes: 1 addition & 1 deletion acceptance/terraform/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ commands will detect it and remind you to do so if necessary.

>>> $TERRAFORM plan -no-color
data.databricks_current_user.me: Reading...
data.databricks_current_user.me: Read complete after 0s [id=$USER.Id]
data.databricks_current_user.me: Read complete after (redacted) [id=$USER.Id]

Changes to Outputs:
+ username = "$USERNAME"
Expand Down
3 changes: 3 additions & 0 deletions acceptance/terraform/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[Repls]]
Old = 'Read complete after [^\s]+'
New = 'Read complete after (redacted)'
1 change: 1 addition & 0 deletions acceptance/workspace/jobs/create/test.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LocalOnly = true # request recording currently does not work with cloud environment
RecordRequests = true

[[Server]]
Expand Down

0 comments on commit f267318

Please sign in to comment.