diff --git a/clients/databricks/dialect/dialect_test.go b/clients/databricks/dialect/dialect_test.go new file mode 100644 index 000000000..c144e4fd9 --- /dev/null +++ b/clients/databricks/dialect/dialect_test.go @@ -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}"}), + ) + } +} diff --git a/clients/databricks/dialect/typing_test.go b/clients/databricks/dialect/typing_test.go index 1c38946e5..51b0aedf3 100644 --- a/clients/databricks/dialect/typing_test.go +++ b/clients/databricks/dialect/typing_test.go @@ -3,11 +3,9 @@ package dialect import ( "testing" + "github.com/artie-labs/transfer/lib/typing" "github.com/artie-labs/transfer/lib/typing/decimal" - "github.com/artie-labs/transfer/lib/typing/ext" - - "github.com/artie-labs/transfer/lib/typing" "github.com/stretchr/testify/assert" )