-
Notifications
You must be signed in to change notification settings - Fork 221
Serialize inline serialized_dashboard to a JSON string early #6471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
384e2d1
Add acceptance test for inline serialized_dashboard
Sankalp-Mittal b806ba1
Add acceptance test for changing an inline serialized_dashboard
Sankalp-Mittal aba995f
Output the JSON plan and drop request capture in change test
Sankalp-Mittal 0e49107
Stop overriding INJECT_STALE_ON_DIRECT in serialized-inline test
Sankalp-Mittal 25cd386
Address review: update_file.py, READPLAN, and capture the update request
Sankalp-Mittal 2cd3934
Trim verbose comments in the serialized-inline test scripts
Sankalp-Mittal 484300e
Serialize inline serialized_dashboard to a JSON string early
Sankalp-Mittal 9aea125
Address review on serialized-inline: replace_ids.py and READPLAN
Sankalp-Mittal 2d72fb2
remove comment
Sankalp-Mittal 722f8eb
Assert the change plan with contains.py
Sankalp-Mittal b591e5a
Capture the update request per engine, not direct-only
Sankalp-Mittal ea01eaf
Merge remote-tracking branch 'origin/sankalp-mittal/dashboards-serial…
Sankalp-Mittal 2806b22
Project change-serialized-inline plan golden to the asserted change
Sankalp-Mittal da5627c
Make change-serialized-inline local-only, revert plan projection
Sankalp-Mittal 94fc393
humanize comment
Sankalp-Mittal d0b32fc
Merge remote-tracking branch 'origin/sankalp-mittal/dashboards-serial…
Sankalp-Mittal 88bd169
Fix Windows: unset MSYS_NO_PATHCONV so bare python helpers resolve
Sankalp-Mittal 67b3827
Merge remote-tracking branch 'origin/sankalp-mittal/dashboards-serial…
Sankalp-Mittal 8766edc
address comments
Sankalp-Mittal 9bf4b58
Merge remote-tracking branch 'origin/sankalp-mittal/dashboards-serial…
Sankalp-Mittal b3232d4
trim strings
Sankalp-Mittal 5b66b75
Retrigger CI
Sankalp-Mittal c93a349
Merge remote-tracking branch 'origin/main' into sankalp-mittal/dashbo…
Sankalp-Mittal 245df99
restore comment
Sankalp-Mittal bf16b52
remove sequence
Sankalp-Mittal 49c7ce5
revert wrong commit
Sankalp-Mittal f40a8a0
update test
Sankalp-Mittal 3a89112
keep older content
Sankalp-Mittal 85ce5e4
Fix syntax error in dashboard serialized_dashboard mutator test
Sankalp-Mittal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
bundle/config/mutator/resourcemutator/configure_dashboards_serialized_dashboard_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package resourcemutator_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config" | ||
| "github.com/databricks/cli/bundle/config/mutator/resourcemutator" | ||
| "github.com/databricks/cli/bundle/config/resources" | ||
| "github.com/databricks/cli/libs/vfs" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestConfigureDashboardSerializedDashboard(t *testing.T) { | ||
| const fileName = "dashboard.lvdash.json" | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| // filePath is set on the resource as-is (already sync-root-relative). | ||
| filePath string | ||
| // writeFile creates filePath with fileContents before the mutator runs. | ||
| writeFile bool | ||
| fileContents string | ||
| setSerialized bool | ||
| serializedDashboard any | ||
| // wantSerialized is the expected serialized_dashboard after a successful run. | ||
| wantSerialized any | ||
| // wantErr, when non-empty, is a substring expected in the diagnostics. | ||
| wantErr string | ||
| }{ | ||
| { | ||
| // The file is read verbatim, so formatting and the trailing newline | ||
| // are preserved (unlike the inline path, which re-marshals). | ||
| name: "file_path reads file contents verbatim", | ||
| filePath: fileName, | ||
| writeFile: true, | ||
| fileContents: `{"pages": 1}` + "\n", | ||
| wantSerialized: `{"pages": 1}` + "\n", | ||
| }, | ||
| { | ||
| // Inline maps are marshaled to a compact JSON string with sorted keys | ||
| // so config and state hold an identical string and don't drift. | ||
| name: "inline map is marshaled to a JSON string", | ||
| setSerialized: true, | ||
| serializedDashboard: map[string]any{"pages": 1}, | ||
| wantSerialized: `{"pages":1}`, | ||
| }, | ||
| { | ||
| name: "inline string is left unchanged", | ||
| setSerialized: true, | ||
| serializedDashboard: `{"pages":1}`, | ||
| wantSerialized: `{"pages":1}`, | ||
| }, | ||
| { | ||
| // Neither field set: the absent field must pass through, not error. | ||
| name: "neither file_path nor serialized_dashboard passes through", | ||
| wantSerialized: nil, | ||
| }, | ||
| { | ||
| name: "both file_path and serialized_dashboard is rejected", | ||
| filePath: fileName, | ||
| setSerialized: true, | ||
| serializedDashboard: map[string]any{"pages": 1}, | ||
| wantErr: "both file_path and serialized_dashboard are set; specify only one", | ||
| }, | ||
| { | ||
| name: "non-structured serialized_dashboard is rejected", | ||
| setSerialized: true, | ||
| serializedDashboard: true, | ||
| wantErr: "serialized_dashboard must be a string or map, got bool", | ||
| }, | ||
| { | ||
| name: "inline sequence is rejected", | ||
| setSerialized: true, | ||
| serializedDashboard: []any{map[string]any{"version": 1}}, | ||
| wantErr: "serialized_dashboard must be a string or map, got sequence", | ||
| }, | ||
| { | ||
| name: "unreadable file_path is an error", | ||
| filePath: "does_not_exist.json", | ||
| wantErr: "failed to read serialized dashboard", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| dir := t.TempDir() | ||
| if tt.writeFile { | ||
| require.NoError(t, os.WriteFile(filepath.Join(dir, tt.filePath), []byte(tt.fileContents), 0o600)) | ||
| } | ||
|
|
||
| dash := &resources.Dashboard{ | ||
| DashboardConfig: resources.DashboardConfig{DisplayName: "My Dashboard"}, | ||
| FilePath: tt.filePath, | ||
| } | ||
| if tt.setSerialized { | ||
| dash.SerializedDashboard = tt.serializedDashboard | ||
| } | ||
|
|
||
| b := &bundle.Bundle{ | ||
| SyncRootPath: dir, | ||
| BundleRootPath: dir, | ||
| SyncRoot: vfs.MustNew(dir), | ||
| Config: config.Root{ | ||
| Resources: config.Resources{ | ||
| Dashboards: map[string]*resources.Dashboard{"my_dashboard": dash}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| diags := bundle.ApplySeq(t.Context(), b, resourcemutator.ConfigureDashboardSerializedDashboard()) | ||
|
|
||
| if tt.wantErr != "" { | ||
| require.Error(t, diags.Error()) | ||
| assert.ErrorContains(t, diags.Error(), tt.wantErr) | ||
| return | ||
| } | ||
|
|
||
| require.NoError(t, diags.Error()) | ||
| assert.Equal(t, tt.wantSerialized, b.Config.Resources.Dashboards["my_dashboard"].SerializedDashboard) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.