Skip to content

Commit a0418ac

Browse files
authored
direct: always return non-nil config internally; fixes panic in invariant/migrate test (#4438)
Fixes panic in TestAccept/bundle/invariant/migrate/DATABRICKS_BUNDLE_ENGINE=direct/INPUT_CONFIG=synced_database_table.yml.tmpl when run on Cloud. Also, fix contains.py to include matching line in the error message and update the script to match on "panic:" instead of "panic".
1 parent c88f570 commit a0418ac

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

acceptance/bin/contains.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
found.add(t)
1919
for t in must_not_find:
2020
if t in line:
21-
sys.stderr.write(f"contains error: {t!r} was not expected\n")
21+
sys.stderr.write(f"contains error: {t!r} was not expected: {line.strip()!r}\n")
2222

2323
sys.stdout.flush()
2424

acceptance/bundle/invariant/migrate/script

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cp databricks.yml LOG.config
1818

1919
cleanup() {
2020
trace $CLI bundle destroy --auto-approve &> LOG.destroy
21-
cat LOG.destroy | contains.py '!panic' '!internal error' > /dev/null
21+
cat LOG.destroy | contains.py '!panic:' '!internal error' > /dev/null
2222

2323
# Run cleanup script if present
2424
CLEANUP_SCRIPT="$TESTDIR/../configs/$INPUT_CONFIG-cleanup.sh"
@@ -30,14 +30,14 @@ cleanup() {
3030
trap cleanup EXIT
3131

3232
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy &> LOG.deploy
33-
cat LOG.deploy | contains.py '!panic' '!internal error' > /dev/null
33+
cat LOG.deploy | contains.py '!panic:' '!internal error' > /dev/null
3434

3535
echo INPUT_CONFIG_OK
3636

3737
trace $CLI bundle deployment migrate &> LOG.migrate
3838

39-
cat LOG.migrate | contains.py '!panic' '!internal error' > /dev/null
39+
cat LOG.migrate | contains.py '!panic:' '!internal error' > /dev/null
4040

4141
$CLI bundle plan -o json &> plan.json
42-
cat plan.json | contains.py '!panic' '!internal error' > /dev/null
42+
cat plan.json | contains.py '!panic:' '!internal error' > /dev/null
4343
verify_no_drift.py plan.json

acceptance/selftest/contains/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Failed script
2020
=== This should complain about Hello present in output
2121
>>> python3 ./success.py
2222
Hello world
23-
contains error: 'Hello' was not expected
23+
contains error: 'Hello' was not expected: 'Hello world'
2424

2525
=== This should not complain
2626
>>> python3 ./success.py

bundle/direct/dresources/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ var (
3939
globalConfig *Config
4040
generatedConfigOnce sync.Once
4141
generatedConfig *Config
42+
empty = ResourceLifecycleConfig{
43+
IgnoreRemoteChanges: nil,
44+
IgnoreLocalChanges: nil,
45+
RecreateOnChanges: nil,
46+
UpdateIDOnChanges: nil,
47+
}
4248
)
4349

4450
// MustLoadConfig loads and parses the embedded resources.yml configuration.
@@ -78,7 +84,7 @@ func GetResourceConfig(resourceType string) *ResourceLifecycleConfig {
7884
if rc, ok := cfg.Resources[resourceType]; ok {
7985
return &rc
8086
}
81-
return nil
87+
return &empty
8288
}
8389

8490
// GetGeneratedResourceConfig returns the generated lifecycle config for a given resource type.
@@ -88,5 +94,5 @@ func GetGeneratedResourceConfig(resourceType string) *ResourceLifecycleConfig {
8894
if rc, ok := cfg.Resources[resourceType]; ok {
8995
return &rc
9096
}
91-
return nil
97+
return &empty
9298
}

bundle/direct/dresources/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ func TestMustLoadConfig(t *testing.T) {
1212
}
1313

1414
func TestGetResourceConfig(t *testing.T) {
15-
assert.NotNil(t, GetResourceConfig("volumes"))
16-
assert.Nil(t, GetResourceConfig("nonexistent"))
15+
assert.NotEmpty(t, GetResourceConfig("volumes").RecreateOnChanges)
16+
assert.Empty(t, GetResourceConfig("nonexistent").RecreateOnChanges)
1717
}

0 commit comments

Comments
 (0)