From 9e9c8d9b3a921b98e6317c9a9e488e0648fd5d1f Mon Sep 17 00:00:00 2001 From: Venelin Date: Fri, 17 Jan 2025 16:00:42 +0200 Subject: [PATCH] fix mws workspaces mishandling empty response --- mws/data_mws_workspaces.go | 2 +- mws/data_mws_workspaces_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mws/data_mws_workspaces.go b/mws/data_mws_workspaces.go index da5eabb2c5..4c2d48a9a4 100755 --- a/mws/data_mws_workspaces.go +++ b/mws/data_mws_workspaces.go @@ -9,7 +9,7 @@ import ( func DataSourceMwsWorkspaces() common.Resource { type mwsWorkspacesData struct { - Ids map[string]int64 `json:"ids,omitempty" tf:"computed"` + Ids map[string]int64 `json:"ids" tf:"computed"` } return common.DataResource(mwsWorkspacesData{}, func(ctx context.Context, e any, c *common.DatabricksClient) error { data := e.(*mwsWorkspacesData) diff --git a/mws/data_mws_workspaces_test.go b/mws/data_mws_workspaces_test.go index 064e29721d..1284b9fc9c 100755 --- a/mws/data_mws_workspaces_test.go +++ b/mws/data_mws_workspaces_test.go @@ -48,3 +48,23 @@ func TestCatalogsData_Error(t *testing.T) { ID: "_", }.ExpectError(t, "i'm a teapot") } + +func TestDataSourceMwsWorkspaces_Empty(t *testing.T) { + qa.ResourceFixture{ + Fixtures: []qa.HTTPFixture{ + { + Method: "GET", + Resource: "/api/2.0/accounts/abc/workspaces", + + Response: []Workspace{}, + }, + }, + AccountID: "abc", + Resource: DataSourceMwsWorkspaces(), + Read: true, + NonWritable: true, + ID: "_", + }.ApplyAndExpectData(t, map[string]any{ + "ids": map[string]any{}, + }) +}