Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 30, 2024
1 parent 8b328ac commit dbe21bc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
66 changes: 66 additions & 0 deletions clients/databricks/dialect/dialect_test.go
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}"}),
)
}
}
4 changes: 1 addition & 3 deletions clients/databricks/dialect/typing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit dbe21bc

Please sign in to comment.