diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-04-27 00:49:27 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-04-27 00:49:27 -0400 |
| commit | 34b8d8ff1f9d65c08a9156d72f08cf548183c6f4 (patch) | |
| tree | a00fa0410a7bcde125a37b50b3a4956c838fa569 /pkg/data/db_test.go | |
| parent | 42527fdb0aca0d30652bb3052b80ab75ab057572 (diff) | |
Large commit; many features
Diffstat (limited to 'pkg/data/db_test.go')
| -rw-r--r-- | pkg/data/db_test.go | 65 |
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) + } + }) + } +} |
