aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/data/db_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/data/db_test.go')
-rw-r--r--pkg/data/db_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/pkg/data/db_test.go b/pkg/data/db_test.go
new file mode 100644
index 0000000..b90a943
--- /dev/null
+++ b/pkg/data/db_test.go
@@ -0,0 +1,65 @@
+package data_test
+
+import (
+ "slices"
+ "testing"
+
+ "github.com/jpappel/atlas/pkg/data"
+)
+
+func TestBatchQuery(t *testing.T) {
+ tests := []struct {
+ name string
+ query string
+ start string
+ val string
+ delim string
+ stop string
+ n int
+ args []int
+ wantQuery string
+ wantArgs []any
+ }{
+ {
+ "1 val group",
+ "INSERT INTO Foo VALUES",
+ "(",
+ "?",
+ ",",
+ ")",
+ 5,
+ []int{1, 2, 3, 4, 5},
+ "INSERT INTO Foo VALUES (?,?,?,?,?)",
+ []any{1, 2, 3, 4, 5},
+ },
+ {
+ "multiple val groups",
+ "INSERT INTO Bar VALUES",
+ "",
+ "(?,?)",
+ ",",
+ "",
+ 2,
+ []int{1, 2, 3, 4},
+ "INSERT INTO Bar VALUES (?,?),(?,?)",
+ []any{1, 2, 3, 4},
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotQuery, gotArgs := data.BatchQuery(tt.query, tt.start, tt.val, tt.delim, tt.stop, tt.n, tt.args)
+ if gotQuery != tt.wantQuery {
+ t.Error("Got different query than wanted")
+ t.Log("Wanted:\n" + tt.wantQuery)
+ t.Log("Got:\n" + gotQuery)
+ }
+
+ if !slices.Equal(tt.wantArgs, gotArgs) {
+ t.Error("Got different args than wanted")
+ t.Logf("Wanted:\t%v", tt.wantArgs)
+ t.Logf("Got:\t%v", gotArgs)
+ }
+ })
+ }
+}