add insert statement
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package sqimple
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
)
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
type TestCase struct {
|
||||
In *InsertStatement
|
||||
Args []any
|
||||
String string
|
||||
}
|
||||
|
||||
testCases := []TestCase{
|
||||
{
|
||||
In: Insert("customer").Columns("name").Values(Values{"name": "Adam"}),
|
||||
Args: []any{"Adam"},
|
||||
String: "insert into customer (name) values (?)",
|
||||
},
|
||||
{
|
||||
In: Insert("customer").Columns("name").Values(Values{"name": "Adam"}, Values{"name": "Bernard"}),
|
||||
Args: []any{"Adam", "Bernard"},
|
||||
String: "insert into customer (name) values (?), (?)",
|
||||
},
|
||||
{
|
||||
In: Insert("customer").Or("update").Columns("id", "name").Values(Values{"id": 1234, "name": "Adam"}),
|
||||
Args: []any{1234, "Adam"},
|
||||
String: "insert or update into customer (id, name) values (?, ?)",
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.String, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.Args, testCase.In.Args(), "collected arguments incorrectly")
|
||||
assert.Equal(t, testCase.String, testCase.In.String(), "stringified incorrectly")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user