Move database logic into separate subdirectory
I'm trying to see if this speeds up builds a bit. May not without a module boundary, but for now it's nice organization to have as the program grows.
This commit is contained in:
parent
338f90708e
commit
41587c3694
333 changed files with 206 additions and 200 deletions
131
db/sql/oauth_by_user_id.bob_test.go
Normal file
131
db/sql/oauth_by_user_id.bob_test.go
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
// Code generated by BobGen psql v0.41.1. 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 TestOauthTokenByUserId(t *testing.T) {
|
||||
t.Run("Base", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := OauthTokenByUserId(random_int32(nil))
|
||||
|
||||
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(oauthTokenByUserIdSQL, sb.String()); diff != "" {
|
||||
t.Fatalf("unexpected result (-got +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Mod", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := OauthTokenByUserId(random_int32(nil))
|
||||
|
||||
if _, err := psql.Select(query).WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queryDiff, err := testutils.QueryDiff(oauthTokenByUserIdSQL, 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(OauthTokenByUserId(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) != 10 {
|
||||
t.Fatalf("expected %d columns, got %d", 10, len(columns))
|
||||
}
|
||||
|
||||
if columns[0] != "id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 0, "id", columns[0])
|
||||
}
|
||||
|
||||
if columns[1] != "access_token" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 1, "access_token", columns[1])
|
||||
}
|
||||
|
||||
if columns[2] != "access_token_expires" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 2, "access_token_expires", columns[2])
|
||||
}
|
||||
|
||||
if columns[3] != "refresh_token" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 3, "refresh_token", columns[3])
|
||||
}
|
||||
|
||||
if columns[4] != "username" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 4, "username", columns[4])
|
||||
}
|
||||
|
||||
if columns[5] != "user_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 5, "user_id", columns[5])
|
||||
}
|
||||
|
||||
if columns[6] != "arcgis_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 6, "arcgis_id", columns[6])
|
||||
}
|
||||
|
||||
if columns[7] != "arcgis_license_type_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 7, "arcgis_license_type_id", columns[7])
|
||||
}
|
||||
|
||||
if columns[8] != "refresh_token_expires" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 8, "refresh_token_expires", columns[8])
|
||||
}
|
||||
|
||||
if columns[9] != "invalidated_at" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 9, "invalidated_at", columns[9])
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue