Test record output and its serializers
Tests / vet + fmt + tests (pull_request) Successful in 1m3s

This commit is contained in:
2026-09-03 22:56:56 +02:00
parent ca40fe0c2c
commit 7383e8d0ca
3 changed files with 305 additions and 0 deletions
+25
View File
@@ -43,6 +43,31 @@ func TestReadmeExamplesLoadAndRender(t *testing.T) {
}
}
func TestReadmeRecordExample(t *testing.T) {
src := readme(t)
section := src[strings.Index(src, "### Records"):]
section = section[:strings.Index(section, "## Library")]
block := jsonBlock.FindStringSubmatch(section)
if block == nil {
t.Fatal("README lost the Records example")
}
f, err := New(WithDataPath(writeData(t, map[string]string{"users": block[1]})), WithSeed(1))
if err != nil {
t.Fatal(err)
}
r, err := f.Record("users")
if err != nil {
t.Fatal(err)
}
got := r.Fields()
if len(got) != 2 || got[0].Name != "first" || got[1].Name != "last" {
t.Fatalf("record columns = %v, want first, last", got)
}
if r.CSVHeader() != "first,last" || !strings.HasPrefix(r.SQLInsert("users"), "INSERT INTO users (first, last) VALUES (") {
t.Fatalf("serializers = %q, %q, want first,last and an INSERT", r.CSVHeader(), r.SQLInsert("users"))
}
}
func TestReadmeSQLExampleOutput(t *testing.T) {
src := readme(t)
src = src[strings.Index(src, "### Your own data"):]