add update statement
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package sqimple
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
)
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
type TestCase struct {
|
||||
In *UpdateStatement
|
||||
Args []any
|
||||
String string
|
||||
}
|
||||
|
||||
testCases := []TestCase{
|
||||
{
|
||||
In: Update("customer").Set("name", "Adam"),
|
||||
Args: []any{"Adam"},
|
||||
String: "update customer set name = ?",
|
||||
},
|
||||
{
|
||||
In: Update("customer").Set("name", "Adam").Where("id = ?", 1234),
|
||||
Args: []any{"Adam", 1234},
|
||||
String: "update customer set name = ? where id = ?",
|
||||
},
|
||||
{
|
||||
// Same as previous, but backwards
|
||||
In: Update("customer").Where("id = ?", 1234).Set("name", "Adam"),
|
||||
Args: []any{"Adam", 1234},
|
||||
String: "update customer set name = ? where id = ?",
|
||||
},
|
||||
}
|
||||
|
||||
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