From 34b8d8ff1f9d65c08a9156d72f08cf548183c6f4 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Sun, 27 Apr 2025 00:49:27 -0400 Subject: Large commit; many features --- pkg/data/db_test.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 pkg/data/db_test.go (limited to 'pkg/data/db_test.go') 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) + } + }) + } +} -- cgit v1.2.3