Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Jul 18, 2024
1 parent cc14761 commit c82e424
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions dashboards/resource_dashboard_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dashboards

import (
"fmt"
"testing"

"github.com/databricks/databricks-sdk-go/experimental/mocks"
Expand Down Expand Up @@ -61,6 +62,64 @@ func TestDashboardCreate(t *testing.T) {
})
}

func TestDashboardCreate_NoParent(t *testing.T) {
qa.ResourceFixture{
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
lv := w.GetMockLakeviewAPI().EXPECT()
lv.Create(mock.Anything, dashboards.CreateDashboardRequest{
DisplayName: "Dashboard name",
WarehouseId: "abc",
ParentPath: "/path",
SerializedDashboard: "serialized_json",
}).Return(nil, fmt.Errorf("Path (/path) doesn't exist.")).Once()
w.GetMockWorkspaceAPI().EXPECT().MkdirsByPath(mock.Anything, "/path").Return(nil)
lv.Create(mock.Anything, dashboards.CreateDashboardRequest{
DisplayName: "Dashboard name",
WarehouseId: "abc",
ParentPath: "/path",
SerializedDashboard: "serialized_json",
}).Return(&dashboards.Dashboard{
DashboardId: "xyz",
DisplayName: "Dashboard name",
SerializedDashboard: "serialized_json_2",
WarehouseId: "abc",
UpdateTime: "2125678",
}, nil)
lv.Publish(mock.Anything, dashboards.PublishRequest{
EmbedCredentials: true,
WarehouseId: "abc",
DashboardId: "xyz",
ForceSendFields: []string{"EmbedCredentials"},
}).Return(&dashboards.PublishedDashboard{
EmbedCredentials: true,
WarehouseId: "abc",
DisplayName: "Dashboard name",
RevisionCreateTime: "823828",
}, nil)
lv.Get(mock.Anything, dashboards.GetDashboardRequest{
DashboardId: "xyz",
}).Return(&dashboards.Dashboard{
DashboardId: "xyz",
DisplayName: "Dashboard name",
SerializedDashboard: "serialized_json_2",
WarehouseId: "abc",
UpdateTime: "2125678",
}, nil)
},
Resource: ResourceDashboard(),
Create: true,
HCL: `
display_name = "Dashboard name"
warehouse_id = "abc"
parent_path = "/path"
serialized_dashboard = "serialized_json"
`,
}.ApplyAndExpectData(t, map[string]any{
"id": "xyz",
"display_name": "Dashboard name",
})
}

func TestDashboardRead(t *testing.T) {
qa.ResourceFixture{
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
Expand Down

0 comments on commit c82e424

Please sign in to comment.