Improve code coverage.
This commit is contained in:
parent
acd9d20339
commit
f5287628aa
15 changed files with 155 additions and 79 deletions
|
|
@ -2,6 +2,7 @@ package jet
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/go-jet/jet/internal/3rdparty/pq"
|
||||
"github.com/go-jet/jet/internal/utils"
|
||||
"github.com/google/uuid"
|
||||
"strconv"
|
||||
|
|
@ -173,7 +174,7 @@ func argToString(value interface{}) string {
|
|||
case uuid.UUID:
|
||||
return stringQuote(bindVal.String())
|
||||
case time.Time:
|
||||
return stringQuote(string(utils.FormatTimestamp(bindVal)))
|
||||
return stringQuote(string(pq.FormatTimestamp(bindVal)))
|
||||
default:
|
||||
return "[Unsupported type]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,17 @@ type Table interface {
|
|||
}
|
||||
|
||||
// NewTable creates new table with schema Name, table Name and list of columns
|
||||
func NewTable(schemaName, name string, columns ...ColumnExpression) SerializerTable {
|
||||
func NewTable(schemaName, name string, column ColumnExpression, columns ...ColumnExpression) SerializerTable {
|
||||
|
||||
columnList := append([]ColumnExpression{column}, columns...)
|
||||
|
||||
t := tableImpl{
|
||||
schemaName: schemaName,
|
||||
name: name,
|
||||
columnList: columns,
|
||||
columnList: columnList,
|
||||
}
|
||||
|
||||
for _, c := range columns {
|
||||
for _, c := range columnList {
|
||||
c.setTableName(name)
|
||||
}
|
||||
|
||||
|
|
|
|||
33
internal/jet/table_test.go
Normal file
33
internal/jet/table_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package jet
|
||||
|
||||
import (
|
||||
"gotest.tools/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewTable(t *testing.T) {
|
||||
newTable := NewTable("schema", "table", IntegerColumn("intCol"))
|
||||
|
||||
assert.Equal(t, newTable.SchemaName(), "schema")
|
||||
assert.Equal(t, newTable.TableName(), "table")
|
||||
|
||||
assert.Equal(t, len(newTable.columns()), 1)
|
||||
assert.Equal(t, newTable.columns()[0].Name(), "intCol")
|
||||
}
|
||||
|
||||
func TestNewJoinTable(t *testing.T) {
|
||||
newTable1 := NewTable("schema", "table", IntegerColumn("intCol1"))
|
||||
newTable2 := NewTable("schema", "table2", IntegerColumn("intCol2"))
|
||||
|
||||
joinTable := NewJoinTable(newTable1, newTable2, InnerJoin, IntegerColumn("intCol1").EQ(IntegerColumn("intCol2")))
|
||||
|
||||
assertClauseSerialize(t, joinTable, `schema.table
|
||||
INNER JOIN schema.table2 ON ("intCol1" = "intCol2")`)
|
||||
|
||||
assert.Equal(t, joinTable.SchemaName(), "schema")
|
||||
assert.Equal(t, joinTable.TableName(), "")
|
||||
|
||||
assert.Equal(t, len(joinTable.columns()), 2)
|
||||
assert.Equal(t, joinTable.columns()[0].Name(), "intCol1")
|
||||
assert.Equal(t, joinTable.columns()[1].Name(), "intCol2")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue