nidus-sync/db/sql/org_by_oauth_id.bob_test.go
Eli Ribble 7c4fb02908
Move to latest bobgen, add fieldseeker schema references
This is an intermediate step between shifting from the old fs_* prefixed
table names to an entire fieldseeker schema. At this point we have both,
and we aren't doing much with the new schema but compiling.
2025-12-02 00:28:14 +00:00

103 lines
2.3 KiB
Go

// Code generated by BobGen psql v0.42.0. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
"fmt"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/dialect/psql"
testutils "github.com/stephenafamo/bob/test/utils"
)
func TestOrgByOauthId(t *testing.T) {
t.Run("Base", func(t *testing.T) {
var sb strings.Builder
query := OrgByOauthId(random_int32(nil))
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(orgByOauthIdSQL, sb.String()); diff != "" {
t.Fatalf("unexpected result (-got +want):\n%s", diff)
}
})
t.Run("Mod", func(t *testing.T) {
var sb strings.Builder
query := OrgByOauthId(random_int32(nil))
if _, err := psql.Select(query).WriteQuery(t.Context(), &sb, 1); err != nil {
t.Fatal(err)
}
queryDiff, err := testutils.QueryDiff(orgByOauthIdSQL, sb.String(), formatQuery)
if err != nil {
t.Fatal(err)
}
if queryDiff != "" {
fmt.Println(sb.String())
t.Fatalf("unexpected result (-got +want):\n%s", queryDiff)
}
})
t.Run("Scanning", func(t *testing.T) {
if testDB == nil {
t.Skip("skipping test, no DSN provided")
}
ctxTx, cancel := context.WithCancel(t.Context())
defer cancel()
tx, err := testDB.Begin(ctxTx)
if err != nil {
t.Fatalf("Error starting transaction: %v", err)
}
defer func() {
if err := tx.Rollback(ctxTx); err != nil {
t.Fatalf("Error rolling back transaction: %v", err)
}
}()
query, args, err := bob.Build(ctxTx, psql.Select(OrgByOauthId(random_int32(nil))))
if err != nil {
t.Fatal(err)
}
rows, err := tx.QueryContext(ctxTx, query, args...)
if err != nil {
t.Fatal(err)
}
defer rows.Close()
columns, err := rows.Columns()
if err != nil {
t.Fatal(err)
}
if len(columns) != 3 {
t.Fatalf("expected %d columns, got %d", 3, len(columns))
}
if columns[0] != "organization_id" {
t.Fatalf("expected column %d to be %s, got %s", 0, "organization_id", columns[0])
}
if columns[1] != "arcgis_id" {
t.Fatalf("expected column %d to be %s, got %s", 1, "arcgis_id", columns[1])
}
if columns[2] != "fieldseeker_url" {
t.Fatalf("expected column %d to be %s, got %s", 2, "fieldseeker_url", columns[2])
}
})
}