mirror of https://github.com/databricks/cli.git
Rename remote modification check
This commit is contained in:
parent
93155f1c77
commit
c4df41c3d6
|
@ -16,7 +16,7 @@ type dashboardState struct {
|
|||
ETag string
|
||||
}
|
||||
|
||||
func collectDashboards(ctx context.Context, b *bundle.Bundle) ([]dashboardState, error) {
|
||||
func collectDashboardsFromState(ctx context.Context, b *bundle.Bundle) ([]dashboardState, error) {
|
||||
state, err := ParseResourcesState(ctx, b)
|
||||
if err != nil && state == nil {
|
||||
return nil, err
|
||||
|
@ -28,22 +28,12 @@ func collectDashboards(ctx context.Context, b *bundle.Bundle) ([]dashboardState,
|
|||
continue
|
||||
}
|
||||
for _, instance := range resource.Instances {
|
||||
id := instance.Attributes.ID
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
switch resource.Type {
|
||||
case "databricks_dashboard":
|
||||
etag := instance.Attributes.ETag
|
||||
if etag == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
dashboards = append(dashboards, dashboardState{
|
||||
Name: resource.Name,
|
||||
ID: id,
|
||||
ETag: etag,
|
||||
ID: instance.Attributes.ID,
|
||||
ETag: instance.Attributes.ETag,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -52,14 +42,14 @@ func collectDashboards(ctx context.Context, b *bundle.Bundle) ([]dashboardState,
|
|||
return dashboards, nil
|
||||
}
|
||||
|
||||
type checkModifiedDashboards struct {
|
||||
type checkDashboardsModifiedRemotely struct {
|
||||
}
|
||||
|
||||
func (l *checkModifiedDashboards) Name() string {
|
||||
return "CheckModifiedDashboards"
|
||||
func (l *checkDashboardsModifiedRemotely) Name() string {
|
||||
return "CheckDashboardsModifiedRemotely"
|
||||
}
|
||||
|
||||
func (l *checkModifiedDashboards) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||
func (l *checkDashboardsModifiedRemotely) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||
// This mutator is relevant only if the bundle includes dashboards.
|
||||
if len(b.Config.Resources.Dashboards) == 0 {
|
||||
return nil
|
||||
|
@ -70,7 +60,7 @@ func (l *checkModifiedDashboards) Apply(ctx context.Context, b *bundle.Bundle) d
|
|||
return nil
|
||||
}
|
||||
|
||||
dashboards, err := collectDashboards(ctx, b)
|
||||
dashboards, err := collectDashboardsFromState(ctx, b)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
@ -122,6 +112,6 @@ func (l *checkModifiedDashboards) Apply(ctx context.Context, b *bundle.Bundle) d
|
|||
return diags
|
||||
}
|
||||
|
||||
func CheckModifiedDashboards() *checkModifiedDashboards {
|
||||
return &checkModifiedDashboards{}
|
||||
func CheckDashboardsModifiedRemotely() *checkDashboardsModifiedRemotely {
|
||||
return &checkDashboardsModifiedRemotely{}
|
||||
}
|
|
@ -40,7 +40,7 @@ func mockDashboardBundle(t *testing.T) *bundle.Bundle {
|
|||
return b
|
||||
}
|
||||
|
||||
func TestCheckModifiedDashboards_NoDashboards(t *testing.T) {
|
||||
func TestCheckDashboardsModifiedRemotely_NoDashboards(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
b := &bundle.Bundle{
|
||||
BundleRootPath: dir,
|
||||
|
@ -52,17 +52,17 @@ func TestCheckModifiedDashboards_NoDashboards(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
diags := bundle.Apply(context.Background(), b, CheckModifiedDashboards())
|
||||
diags := bundle.Apply(context.Background(), b, CheckDashboardsModifiedRemotely())
|
||||
assert.Empty(t, diags)
|
||||
}
|
||||
|
||||
func TestCheckModifiedDashboards_FirstDeployment(t *testing.T) {
|
||||
func TestCheckDashboardsModifiedRemotely_FirstDeployment(t *testing.T) {
|
||||
b := mockDashboardBundle(t)
|
||||
diags := bundle.Apply(context.Background(), b, CheckModifiedDashboards())
|
||||
diags := bundle.Apply(context.Background(), b, CheckDashboardsModifiedRemotely())
|
||||
assert.Empty(t, diags)
|
||||
}
|
||||
|
||||
func TestCheckModifiedDashboards_ExistingStateNoChange(t *testing.T) {
|
||||
func TestCheckDashboardsModifiedRemotely_ExistingStateNoChange(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
b := mockDashboardBundle(t)
|
||||
|
@ -81,11 +81,11 @@ func TestCheckModifiedDashboards_ExistingStateNoChange(t *testing.T) {
|
|||
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||
|
||||
// No changes, so no diags.
|
||||
diags := bundle.Apply(ctx, b, CheckModifiedDashboards())
|
||||
diags := bundle.Apply(ctx, b, CheckDashboardsModifiedRemotely())
|
||||
assert.Empty(t, diags)
|
||||
}
|
||||
|
||||
func TestCheckModifiedDashboards_ExistingStateChange(t *testing.T) {
|
||||
func TestCheckDashboardsModifiedRemotely_ExistingStateChange(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
b := mockDashboardBundle(t)
|
||||
|
@ -104,14 +104,14 @@ func TestCheckModifiedDashboards_ExistingStateChange(t *testing.T) {
|
|||
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||
|
||||
// The dashboard has changed, so expect an error.
|
||||
diags := bundle.Apply(ctx, b, CheckModifiedDashboards())
|
||||
diags := bundle.Apply(ctx, b, CheckDashboardsModifiedRemotely())
|
||||
if assert.Len(t, diags, 1) {
|
||||
assert.Equal(t, diag.Error, diags[0].Severity)
|
||||
assert.Equal(t, `dashboard "dash1" has been modified remotely`, diags[0].Summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckModifiedDashboards_ExistingStateFailureToGet(t *testing.T) {
|
||||
func TestCheckDashboardsModifiedRemotely_ExistingStateFailureToGet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
b := mockDashboardBundle(t)
|
||||
|
@ -127,7 +127,7 @@ func TestCheckModifiedDashboards_ExistingStateFailureToGet(t *testing.T) {
|
|||
b.SetWorkpaceClient(m.WorkspaceClient)
|
||||
|
||||
// Unable to get the dashboard, so expect an error.
|
||||
diags := bundle.Apply(ctx, b, CheckModifiedDashboards())
|
||||
diags := bundle.Apply(ctx, b, CheckDashboardsModifiedRemotely())
|
||||
if assert.Len(t, diags, 1) {
|
||||
assert.Equal(t, diag.Error, diags[0].Severity)
|
||||
assert.Equal(t, `failed to get dashboard "dash1"`, diags[0].Summary)
|
|
@ -152,7 +152,7 @@ func Deploy(outputHandler sync.OutputHandler) bundle.Mutator {
|
|||
bundle.Defer(
|
||||
bundle.Seq(
|
||||
terraform.StatePull(),
|
||||
terraform.CheckModifiedDashboards(),
|
||||
terraform.CheckDashboardsModifiedRemotely(),
|
||||
deploy.StatePull(),
|
||||
mutator.ValidateGitDetails(),
|
||||
artifacts.CleanUp(),
|
||||
|
|
Loading…
Reference in New Issue