diff --git a/client/service/commands_test.go b/client/service/commands_test.go index 6481e7487..673625275 100644 --- a/client/service/commands_test.go +++ b/client/service/commands_test.go @@ -7,6 +7,9 @@ import ( "github.com/databrickslabs/databricks-terraform/client/model" ) +// Test interface compliance +var _ CommandExecutor = (*CommandsAPI)(nil) + func TestCommandsAPI_Execute(t *testing.T) { type context struct { Language string `json:"language,omitempty"` diff --git a/databricks/mounts_test.go b/databricks/mounts_test.go index fc767a690..173e7f578 100644 --- a/databricks/mounts_test.go +++ b/databricks/mounts_test.go @@ -23,11 +23,13 @@ func TestAzureBlobMountReadRetrievesMountInformation(t *testing.T) { const dir = "mydirectory" testCases := []struct { + Name string ExpectedResult string ExpectedError error CommandResult *model.CommandResults }{ { + Name: "Mount found successfully", ExpectedResult: fmt.Sprintf("abfss://%s@%s.dfs.core.windows.net/%s", cn, sacc, dir), CommandResult: &model.CommandResults{ ResultType: "text", @@ -35,6 +37,7 @@ func TestAzureBlobMountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Mount not found - no match in db", ExpectedError: errors.New("unable to find mount point"), CommandResult: &model.CommandResults{ ResultType: "text", @@ -42,6 +45,7 @@ func TestAzureBlobMountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Mount found - but does not match configuration", ExpectedError: fmt.Errorf("does not match uri with storage account and container values %s@%s != abfss://x@y.dfs.core.windows.net/z!", cn, sacc), CommandResult: &model.CommandResults{ ResultType: "text", @@ -49,6 +53,7 @@ func TestAzureBlobMountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Error - db returns error", ExpectedError: errors.New("out of wibble error"), CommandResult: &model.CommandResults{ ResultType: "error", @@ -58,19 +63,21 @@ func TestAzureBlobMountReadRetrievesMountInformation(t *testing.T) { } for _, tc := range testCases { - executeMock = func(clusterID, language, commandStr string) (model.Command, error) { - return model.Command{ - Results: tc.CommandResult, - }, nil - } - executorMock := commandExecutorMock{} + t.Run(tc.Name, func(t *testing.T) { + executeMock = func(clusterID, language, commandStr string) (model.Command, error) { + return model.Command{ + Results: tc.CommandResult, + }, nil + } + executorMock := commandExecutorMock{} - blobMount := NewAzureBlobMount(cn, sacc, dir, "mount", "", "", "") + blobMount := NewAzureBlobMount(cn, sacc, dir, "mount", "", "", "") - result, err := blobMount.Read(executorMock, "wibble") + result, err := blobMount.Read(executorMock, "wibble") - assert.Equal(t, tc.ExpectedResult, result) - assert.Equal(t, tc.ExpectedError, err) + assert.Equal(t, tc.ExpectedResult, result) + assert.Equal(t, tc.ExpectedError, err) + }) } } @@ -79,11 +86,13 @@ func TestAzureADLSGen1MountReadRetrievesMountInformation(t *testing.T) { const dir = "mydirectory" testCases := []struct { + Name string ExpectedResult string ExpectedError error CommandResult *model.CommandResults }{ { + Name: "Mount found successfully", ExpectedResult: fmt.Sprintf("adl://%s.azuredatalakestore.net/%s", sacc, dir), CommandResult: &model.CommandResults{ ResultType: "text", @@ -91,6 +100,7 @@ func TestAzureADLSGen1MountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Mount not found - no match in db", ExpectedError: errors.New("unable to find mount point"), CommandResult: &model.CommandResults{ ResultType: "text", @@ -98,6 +108,7 @@ func TestAzureADLSGen1MountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Mount found - but does not match configuration", ExpectedError: fmt.Errorf("does not match uri with storage account and container values %s@%s != adl://x.azuredatalakestore.net/z!", sacc, dir), CommandResult: &model.CommandResults{ ResultType: "text", @@ -105,6 +116,7 @@ func TestAzureADLSGen1MountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Error - db returns error", ExpectedError: errors.New("out of wibble error"), CommandResult: &model.CommandResults{ ResultType: "error", @@ -114,19 +126,21 @@ func TestAzureADLSGen1MountReadRetrievesMountInformation(t *testing.T) { } for _, tc := range testCases { - executeMock = func(clusterID, language, commandStr string) (model.Command, error) { - return model.Command{ - Results: tc.CommandResult, - }, nil - } - executorMock := commandExecutorMock{} + t.Run(tc.Name, func(t *testing.T) { + executeMock = func(clusterID, language, commandStr string) (model.Command, error) { + return model.Command{ + Results: tc.CommandResult, + }, nil + } + executorMock := commandExecutorMock{} - adlsGen2Mount := NewAzureADLSGen1Mount(sacc, dir, "mount", "", "", "", "", "") + adlsGen2Mount := NewAzureADLSGen1Mount(sacc, dir, "mount", "", "", "", "", "") - result, err := adlsGen2Mount.Read(executorMock, "wibble") + result, err := adlsGen2Mount.Read(executorMock, "wibble") - assert.Equal(t, tc.ExpectedResult, result) - assert.Equal(t, tc.ExpectedError, err) + assert.Equal(t, tc.ExpectedResult, result) + assert.Equal(t, tc.ExpectedError, err) + }) } } @@ -136,11 +150,13 @@ func TestAzureADLSGen2MountReadRetrievesMountInformation(t *testing.T) { const dir = "mydirectory" testCases := []struct { + Name string ExpectedResult string ExpectedError error CommandResult *model.CommandResults }{ { + Name: "Mount found successfully", ExpectedResult: fmt.Sprintf("abfss://%s@%s.dfs.core.windows.net/%s", cn, sacc, dir), CommandResult: &model.CommandResults{ ResultType: "text", @@ -148,6 +164,7 @@ func TestAzureADLSGen2MountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Mount not found - no match in db", ExpectedError: errors.New("unable to find mount point"), CommandResult: &model.CommandResults{ ResultType: "text", @@ -155,6 +172,7 @@ func TestAzureADLSGen2MountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Mount found - but does not match configuration", ExpectedError: fmt.Errorf("does not match uri with storage account and container values %s@%s != abfss://x@y.dfs.core.windows.net/z!", cn, sacc), CommandResult: &model.CommandResults{ ResultType: "text", @@ -162,6 +180,7 @@ func TestAzureADLSGen2MountReadRetrievesMountInformation(t *testing.T) { }, }, { + Name: "Error - db returns error", ExpectedError: errors.New("out of wibble error"), CommandResult: &model.CommandResults{ ResultType: "error", @@ -171,19 +190,21 @@ func TestAzureADLSGen2MountReadRetrievesMountInformation(t *testing.T) { } for _, tc := range testCases { - executeMock = func(clusterID, language, commandStr string) (model.Command, error) { - return model.Command{ - Results: tc.CommandResult, - }, nil - } - executorMock := commandExecutorMock{} + t.Run(tc.Name, func(t *testing.T) { + executeMock = func(clusterID, language, commandStr string) (model.Command, error) { + return model.Command{ + Results: tc.CommandResult, + }, nil + } + executorMock := commandExecutorMock{} - adlsGen2Mount := NewAzureADLSGen2Mount(cn, sacc, dir, "mount", "", "", "", "", true) + adlsGen2Mount := NewAzureADLSGen2Mount(cn, sacc, dir, "mount", "", "", "", "", true) - result, err := adlsGen2Mount.Read(executorMock, "wibble") + result, err := adlsGen2Mount.Read(executorMock, "wibble") - assert.Equal(t, tc.ExpectedResult, result) - assert.Equal(t, tc.ExpectedError, err) + assert.Equal(t, tc.ExpectedResult, result) + assert.Equal(t, tc.ExpectedError, err) + }) } }