-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package dialect | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/artie-labs/transfer/lib/mocks" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDatabricksDialect_QuoteIdentifier(t *testing.T) { | ||
dialect := DatabricksDialect{} | ||
assert.Equal(t, "`foo`", dialect.QuoteIdentifier("foo")) | ||
assert.Equal(t, "`FOO`", dialect.QuoteIdentifier("FOO")) | ||
} | ||
|
||
func TestDatabricksDialect_IsColumnAlreadyExistsErr(t *testing.T) { | ||
{ | ||
// No error | ||
assert.False(t, DatabricksDialect{}.IsColumnAlreadyExistsErr(nil)) | ||
} | ||
{ | ||
// Random error | ||
assert.False(t, DatabricksDialect{}.IsColumnAlreadyExistsErr(fmt.Errorf("random error"))) | ||
} | ||
{ | ||
// Valid | ||
assert.True(t, DatabricksDialect{}.IsColumnAlreadyExistsErr(fmt.Errorf("[FIELDS_ALREADY_EXISTS] Cannot add column, because `first_name` already exists]"))) | ||
} | ||
} | ||
|
||
func TestDatabricksDialect_IsTableDoesNotExistErr(t *testing.T) { | ||
{ | ||
// No error | ||
assert.False(t, DatabricksDialect{}.IsTableDoesNotExistErr(nil)) | ||
} | ||
{ | ||
// Random error | ||
assert.False(t, DatabricksDialect{}.IsTableDoesNotExistErr(fmt.Errorf("random error"))) | ||
} | ||
{ | ||
// Valid | ||
assert.True(t, DatabricksDialect{}.IsTableDoesNotExistErr(fmt.Errorf("[TABLE_OR_VIEW_NOT_FOUND] Table or view not found: `foo`]"))) | ||
} | ||
} | ||
|
||
func TestDatabricksDialect_BuildCreateTableQuery(t *testing.T) { | ||
fakeTableID := &mocks.FakeTableIdentifier{} | ||
fakeTableID.FullyQualifiedNameReturns("{TABLE}") | ||
|
||
{ | ||
// Temporary | ||
assert.Equal(t, | ||
`CREATE TABLE IF NOT EXISTS {TABLE} ({PART_1}, {PART_2})`, | ||
DatabricksDialect{}.BuildCreateTableQuery(fakeTableID, true, []string{"{PART_1}", "{PART_2}"}), | ||
) | ||
} | ||
{ | ||
// Not temporary | ||
assert.Equal(t, | ||
`CREATE TABLE IF NOT EXISTS {TABLE} ({PART_1}, {PART_2})`, | ||
DatabricksDialect{}.BuildCreateTableQuery(fakeTableID, false, []string{"{PART_1}", "{PART_2}"}), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters