Skip to content

Commit

Permalink
added test run command
Browse files Browse the repository at this point in the history
PR feedback to verify interface
  • Loading branch information
Dave Storey committed Jun 16, 2020
1 parent 9c81f69 commit cf84787
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
3 changes: 3 additions & 0 deletions client/service/commands_test.go
Expand Up @@ -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"`
Expand Down
81 changes: 51 additions & 30 deletions databricks/mounts_test.go
Expand Up @@ -23,32 +23,37 @@ 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",
Data: fmt.Sprintf("abfss://%s@%s.dfs.core.windows.net/%s", cn, sacc, dir),
},
},
{
Name: "Mount not found - no match in db",
ExpectedError: errors.New("unable to find mount point"),
CommandResult: &model.CommandResults{
ResultType: "text",
Data: "",
},
},
{
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",
Data: "abfss://x@y.dfs.core.windows.net/z",
},
},
{
Name: "Error - db returns error",
ExpectedError: errors.New("out of wibble error"),
CommandResult: &model.CommandResults{
ResultType: "error",
Expand All @@ -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)
})
}
}

Expand All @@ -79,32 +86,37 @@ 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",
Data: fmt.Sprintf("adl://%s.azuredatalakestore.net/%s", sacc, dir),
},
},
{
Name: "Mount not found - no match in db",
ExpectedError: errors.New("unable to find mount point"),
CommandResult: &model.CommandResults{
ResultType: "text",
Data: "",
},
},
{
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",
Data: "adl://x.azuredatalakestore.net/z",
},
},
{
Name: "Error - db returns error",
ExpectedError: errors.New("out of wibble error"),
CommandResult: &model.CommandResults{
ResultType: "error",
Expand All @@ -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)
})
}
}

Expand All @@ -136,32 +150,37 @@ 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",
Data: fmt.Sprintf("abfss://%s@%s.dfs.core.windows.net/%s", cn, sacc, dir),
},
},
{
Name: "Mount not found - no match in db",
ExpectedError: errors.New("unable to find mount point"),
CommandResult: &model.CommandResults{
ResultType: "text",
Data: "",
},
},
{
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",
Data: "abfss://x@y.dfs.core.windows.net/z",
},
},
{
Name: "Error - db returns error",
ExpectedError: errors.New("out of wibble error"),
CommandResult: &model.CommandResults{
ResultType: "error",
Expand All @@ -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)
})
}
}

Expand Down

0 comments on commit cf84787

Please sign in to comment.