Stop generating bob test files
They just slow things down.
This commit is contained in:
parent
4ca734cc10
commit
d377d9a7d2
13 changed files with 1 additions and 2311 deletions
|
|
@ -4,6 +4,7 @@ aliases:
|
|||
up_singular: "User"
|
||||
down_plural: "users"
|
||||
down_singular: "user"
|
||||
no_tests: true
|
||||
psql:
|
||||
schemas:
|
||||
- "public"
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
import "github.com/stephenafamo/bob"
|
||||
|
||||
// Set the testDB to enable tests that use the database
|
||||
var testDB bob.Transactor[bob.Tx]
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
factory "github.com/Gleipnir-Technology/nidus-sync/db/factory"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
func TestH3AggregationUniqueConstraintErrors(t *testing.T) {
|
||||
if testDB == nil {
|
||||
t.Skip("No database connection provided")
|
||||
}
|
||||
|
||||
f := factory.New()
|
||||
tests := []struct {
|
||||
name string
|
||||
expectedErr *UniqueConstraintError
|
||||
conflictMods func(context.Context, *testing.T, bob.Executor, *models.H3Aggregation) factory.H3AggregationModSlice
|
||||
}{
|
||||
{
|
||||
name: "ErrUniqueH3AggregationPkey",
|
||||
expectedErr: H3AggregationErrors.ErrUniqueH3AggregationPkey,
|
||||
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.H3Aggregation) factory.H3AggregationModSlice {
|
||||
shouldUpdate := false
|
||||
updateMods := make(factory.H3AggregationModSlice, 0, 1)
|
||||
|
||||
if shouldUpdate {
|
||||
if err := obj.Update(ctx, exec, f.NewH3AggregationWithContext(ctx, updateMods...).BuildSetter()); err != nil {
|
||||
t.Fatalf("Error updating object: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return factory.H3AggregationModSlice{
|
||||
factory.H3AggregationMods.ID(obj.ID),
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ErrUniqueH3AggregationCellOrganizationIdType_Key",
|
||||
expectedErr: H3AggregationErrors.ErrUniqueH3AggregationCellOrganizationIdType_Key,
|
||||
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.H3Aggregation) factory.H3AggregationModSlice {
|
||||
shouldUpdate := false
|
||||
updateMods := make(factory.H3AggregationModSlice, 0, 3)
|
||||
|
||||
if shouldUpdate {
|
||||
if err := obj.Update(ctx, exec, f.NewH3AggregationWithContext(ctx, updateMods...).BuildSetter()); err != nil {
|
||||
t.Fatalf("Error updating object: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return factory.H3AggregationModSlice{
|
||||
factory.H3AggregationMods.Cell(obj.Cell),
|
||||
factory.H3AggregationMods.OrganizationID(obj.OrganizationID),
|
||||
factory.H3AggregationMods.Type(obj.Type),
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
tx, err := testDB.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't start database transaction: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := tx.Rollback(ctx); err != nil {
|
||||
t.Fatalf("Error rolling back transaction: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
var exec bob.Executor = tx
|
||||
|
||||
obj, err := f.NewH3AggregationWithContext(ctx, factory.H3AggregationMods.WithParentsCascading()).Create(ctx, exec)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
obj2, err := f.NewH3AggregationWithContext(ctx).Create(ctx, exec)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = obj2.Update(ctx, exec, f.NewH3AggregationWithContext(ctx, tt.conflictMods(ctx, t, exec, obj)...).BuildSetter())
|
||||
if !errors.Is(ErrUniqueConstraint, err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
|
||||
}
|
||||
if !errors.Is(tt.expectedErr, err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
|
||||
}
|
||||
if !ErrUniqueConstraint.Is(err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
|
||||
}
|
||||
if !tt.expectedErr.Is(err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
factory "github.com/Gleipnir-Technology/nidus-sync/db/factory"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
func TestPublicreportQuickUniqueConstraintErrors(t *testing.T) {
|
||||
if testDB == nil {
|
||||
t.Skip("No database connection provided")
|
||||
}
|
||||
|
||||
f := factory.New()
|
||||
tests := []struct {
|
||||
name string
|
||||
expectedErr *UniqueConstraintError
|
||||
conflictMods func(context.Context, *testing.T, bob.Executor, *models.PublicreportQuick) factory.PublicreportQuickModSlice
|
||||
}{
|
||||
{
|
||||
name: "ErrUniqueQuickPkey",
|
||||
expectedErr: PublicreportQuickErrors.ErrUniqueQuickPkey,
|
||||
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.PublicreportQuick) factory.PublicreportQuickModSlice {
|
||||
shouldUpdate := false
|
||||
updateMods := make(factory.PublicreportQuickModSlice, 0, 1)
|
||||
|
||||
if shouldUpdate {
|
||||
if err := obj.Update(ctx, exec, f.NewPublicreportQuickWithContext(ctx, updateMods...).BuildSetter()); err != nil {
|
||||
t.Fatalf("Error updating object: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return factory.PublicreportQuickModSlice{
|
||||
factory.PublicreportQuickMods.ID(obj.ID),
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ErrUniqueQuickPublicIdKey",
|
||||
expectedErr: PublicreportQuickErrors.ErrUniqueQuickPublicIdKey,
|
||||
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.PublicreportQuick) factory.PublicreportQuickModSlice {
|
||||
shouldUpdate := false
|
||||
updateMods := make(factory.PublicreportQuickModSlice, 0, 1)
|
||||
|
||||
if shouldUpdate {
|
||||
if err := obj.Update(ctx, exec, f.NewPublicreportQuickWithContext(ctx, updateMods...).BuildSetter()); err != nil {
|
||||
t.Fatalf("Error updating object: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return factory.PublicreportQuickModSlice{
|
||||
factory.PublicreportQuickMods.PublicID(obj.PublicID),
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
tx, err := testDB.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't start database transaction: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := tx.Rollback(ctx); err != nil {
|
||||
t.Fatalf("Error rolling back transaction: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
var exec bob.Executor = tx
|
||||
|
||||
obj, err := f.NewPublicreportQuickWithContext(ctx, factory.PublicreportQuickMods.WithParentsCascading()).Create(ctx, exec)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
obj2, err := f.NewPublicreportQuickWithContext(ctx).Create(ctx, exec)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = obj2.Update(ctx, exec, f.NewPublicreportQuickWithContext(ctx, tt.conflictMods(ctx, t, exec, obj)...).BuildSetter())
|
||||
if !errors.Is(ErrUniqueConstraint, err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
|
||||
}
|
||||
if !errors.Is(tt.expectedErr, err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
|
||||
}
|
||||
if !ErrUniqueConstraint.Is(err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
|
||||
}
|
||||
if !tt.expectedErr.Is(err) {
|
||||
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,147 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
// Set the testDB to enable tests that use the database
|
||||
var testDB bob.Transactor[bob.Tx]
|
||||
|
||||
func TestRandom___byte(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random___byte(nil)
|
||||
val2 := random___byte(nil)
|
||||
|
||||
if bytes.Equal(val1, val2) {
|
||||
t.Fatalf("random___byte() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_float32(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_float32(nil)
|
||||
val2 := random_float32(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_float32() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_float64(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_float64(nil)
|
||||
val2 := random_float64(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_float64() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_int16(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_int16(nil)
|
||||
val2 := random_int16(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_int16() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_int32(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_int32(nil)
|
||||
val2 := random_int32(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_int32() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_int64(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_int64(nil)
|
||||
val2 := random_int64(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_int64() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_pq_Float64Array(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_pq_Float64Array(nil)
|
||||
val2 := random_pq_Float64Array(nil)
|
||||
|
||||
if slices.Equal(val1, val2) {
|
||||
t.Fatalf("random_pq_Float64Array() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_pq_StringArray(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_pq_StringArray(nil)
|
||||
val2 := random_pq_StringArray(nil)
|
||||
|
||||
if slices.Equal(val1, val2) {
|
||||
t.Fatalf("random_pq_StringArray() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_string(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_string(nil)
|
||||
val2 := random_string(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_string() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_time_Time(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_time_Time(nil)
|
||||
val2 := random_time_Time(nil)
|
||||
|
||||
if val1.Equal(val2) {
|
||||
t.Fatalf("random_time_Time() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_types_JSON_json_RawMessage_(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_types_JSON_json_RawMessage_(nil)
|
||||
val2 := random_types_JSON_json_RawMessage_(nil)
|
||||
|
||||
if bytes.Equal(val1.Val, val2.Val) {
|
||||
t.Fatalf("random_types_JSON_json_RawMessage_() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_uuid_UUID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_uuid_UUID(nil)
|
||||
val2 := random_uuid_UUID(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_uuid_UUID() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,223 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/types"
|
||||
)
|
||||
|
||||
// Set the testDB to enable tests that use the database
|
||||
var testDB bob.Transactor[bob.Tx]
|
||||
|
||||
// Make sure the type FieldseekerContainerrelate runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerContainerrelate{}
|
||||
|
||||
// Make sure the type FieldseekerFieldscoutinglog runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerFieldscoutinglog{}
|
||||
|
||||
// Make sure the type FieldseekerHabitatrelate runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerHabitatrelate{}
|
||||
|
||||
// Make sure the type FieldseekerInspectionsample runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerInspectionsample{}
|
||||
|
||||
// Make sure the type FieldseekerInspectionsampledetail runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerInspectionsampledetail{}
|
||||
|
||||
// Make sure the type FieldseekerLinelocation runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerLinelocation{}
|
||||
|
||||
// Make sure the type FieldseekerLocationtracking runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerLocationtracking{}
|
||||
|
||||
// Make sure the type FieldseekerMosquitoinspection runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerMosquitoinspection{}
|
||||
|
||||
// Make sure the type FieldseekerPointlocation runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerPointlocation{}
|
||||
|
||||
// Make sure the type FieldseekerPolygonlocation runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerPolygonlocation{}
|
||||
|
||||
// Make sure the type FieldseekerPool runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerPool{}
|
||||
|
||||
// Make sure the type FieldseekerPooldetail runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerPooldetail{}
|
||||
|
||||
// Make sure the type FieldseekerProposedtreatmentarea runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerProposedtreatmentarea{}
|
||||
|
||||
// Make sure the type FieldseekerQamosquitoinspection runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerQamosquitoinspection{}
|
||||
|
||||
// Make sure the type FieldseekerRodentlocation runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerRodentlocation{}
|
||||
|
||||
// Make sure the type FieldseekerSamplecollection runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerSamplecollection{}
|
||||
|
||||
// Make sure the type FieldseekerSamplelocation runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerSamplelocation{}
|
||||
|
||||
// Make sure the type FieldseekerServicerequest runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerServicerequest{}
|
||||
|
||||
// Make sure the type FieldseekerSpeciesabundance runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerSpeciesabundance{}
|
||||
|
||||
// Make sure the type FieldseekerStormdrain runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerStormdrain{}
|
||||
|
||||
// Make sure the type FieldseekerTimecard runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerTimecard{}
|
||||
|
||||
// Make sure the type FieldseekerTrapdatum runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerTrapdatum{}
|
||||
|
||||
// Make sure the type FieldseekerTraplocation runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerTraplocation{}
|
||||
|
||||
// Make sure the type FieldseekerTreatment runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerTreatment{}
|
||||
|
||||
// Make sure the type FieldseekerTreatmentarea runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerTreatmentarea{}
|
||||
|
||||
// Make sure the type FieldseekerZone runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerZone{}
|
||||
|
||||
// Make sure the type FieldseekerZones2 runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerZones2{}
|
||||
|
||||
// Make sure the type FieldseekerSync runs hooks after queries
|
||||
var _ bob.HookableType = &FieldseekerSync{}
|
||||
|
||||
// Make sure the type GeographyColumn runs hooks after queries
|
||||
var _ bob.HookableType = &GeographyColumn{}
|
||||
|
||||
// Make sure the type GeometryColumn runs hooks after queries
|
||||
var _ bob.HookableType = &GeometryColumn{}
|
||||
|
||||
// Make sure the type GooseDBVersion runs hooks after queries
|
||||
var _ bob.HookableType = &GooseDBVersion{}
|
||||
|
||||
// Make sure the type H3Aggregation runs hooks after queries
|
||||
var _ bob.HookableType = &H3Aggregation{}
|
||||
|
||||
// Make sure the type NoteAudio runs hooks after queries
|
||||
var _ bob.HookableType = &NoteAudio{}
|
||||
|
||||
// Make sure the type NoteAudioBreadcrumb runs hooks after queries
|
||||
var _ bob.HookableType = &NoteAudioBreadcrumb{}
|
||||
|
||||
// Make sure the type NoteAudioDatum runs hooks after queries
|
||||
var _ bob.HookableType = &NoteAudioDatum{}
|
||||
|
||||
// Make sure the type NoteImage runs hooks after queries
|
||||
var _ bob.HookableType = &NoteImage{}
|
||||
|
||||
// Make sure the type NoteImageBreadcrumb runs hooks after queries
|
||||
var _ bob.HookableType = &NoteImageBreadcrumb{}
|
||||
|
||||
// Make sure the type NoteImageDatum runs hooks after queries
|
||||
var _ bob.HookableType = &NoteImageDatum{}
|
||||
|
||||
// Make sure the type Notification runs hooks after queries
|
||||
var _ bob.HookableType = &Notification{}
|
||||
|
||||
// Make sure the type OauthToken runs hooks after queries
|
||||
var _ bob.HookableType = &OauthToken{}
|
||||
|
||||
// Make sure the type Organization runs hooks after queries
|
||||
var _ bob.HookableType = &Organization{}
|
||||
|
||||
// Make sure the type PublicreportQuick runs hooks after queries
|
||||
var _ bob.HookableType = &PublicreportQuick{}
|
||||
|
||||
// Make sure the type PublicreportQuickPhoto runs hooks after queries
|
||||
var _ bob.HookableType = &PublicreportQuickPhoto{}
|
||||
|
||||
// Make sure the type RasterColumn runs hooks after queries
|
||||
var _ bob.HookableType = &RasterColumn{}
|
||||
|
||||
// Make sure the type RasterOverview runs hooks after queries
|
||||
var _ bob.HookableType = &RasterOverview{}
|
||||
|
||||
// Make sure the type Session runs hooks after queries
|
||||
var _ bob.HookableType = &Session{}
|
||||
|
||||
// Make sure the type SpatialRefSy runs hooks after queries
|
||||
var _ bob.HookableType = &SpatialRefSy{}
|
||||
|
||||
// Make sure the type User runs hooks after queries
|
||||
var _ bob.HookableType = &User{}
|
||||
|
||||
// Make sure the type uuid.UUID satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*uuid.UUID)(nil)
|
||||
|
||||
// Make sure the type uuid.UUID satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(uuid.UUID)
|
||||
|
||||
// Make sure the type types.JSON[json.RawMessage] satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*types.JSON[json.RawMessage])(nil)
|
||||
|
||||
// Make sure the type types.JSON[json.RawMessage] satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(types.JSON[json.RawMessage])
|
||||
|
||||
// Make sure the type enums.H3aggregationtype satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*enums.H3aggregationtype)(nil)
|
||||
|
||||
// Make sure the type enums.H3aggregationtype satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(enums.H3aggregationtype)
|
||||
|
||||
// Make sure the type enums.Audiodatatype satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*enums.Audiodatatype)(nil)
|
||||
|
||||
// Make sure the type enums.Audiodatatype satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(enums.Audiodatatype)
|
||||
|
||||
// Make sure the type enums.Notificationtype satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*enums.Notificationtype)(nil)
|
||||
|
||||
// Make sure the type enums.Notificationtype satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(enums.Notificationtype)
|
||||
|
||||
// Make sure the type pq.StringArray satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*pq.StringArray)(nil)
|
||||
|
||||
// Make sure the type pq.StringArray satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(pq.StringArray)
|
||||
|
||||
// Make sure the type pq.Float64Array satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*pq.Float64Array)(nil)
|
||||
|
||||
// Make sure the type pq.Float64Array satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(pq.Float64Array)
|
||||
|
||||
// Make sure the type pq.BoolArray satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*pq.BoolArray)(nil)
|
||||
|
||||
// Make sure the type pq.BoolArray satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(pq.BoolArray)
|
||||
|
||||
// Make sure the type enums.Arcgislicensetype satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*enums.Arcgislicensetype)(nil)
|
||||
|
||||
// Make sure the type enums.Arcgislicensetype satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(enums.Arcgislicensetype)
|
||||
|
||||
// Make sure the type enums.Hashtype satisfies database/sql.Scanner
|
||||
var _ sql.Scanner = (*enums.Hashtype)(nil)
|
||||
|
||||
// Make sure the type enums.Hashtype satisfies database/sql/driver.Valuer
|
||||
var _ driver.Valuer = *new(enums.Hashtype)
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
pg_query "github.com/wasilibs/go-pgquery"
|
||||
)
|
||||
|
||||
// Set the testDB to enable tests that use the database
|
||||
var testDB bob.Transactor[bob.Tx]
|
||||
|
||||
func formatQuery(s string) (string, error) {
|
||||
aTree, err := pg_query.Parse(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return pg_query.Deparse(aTree)
|
||||
}
|
||||
|
||||
var defaultFaker = faker.New()
|
||||
|
||||
func random_enums_Arcgislicensetype(f *faker.Faker, limits ...string) enums.Arcgislicensetype {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
var e enums.Arcgislicensetype
|
||||
all := e.All()
|
||||
return all[f.IntBetween(0, len(all)-1)]
|
||||
}
|
||||
|
||||
func random_enums_Hashtype(f *faker.Faker, limits ...string) enums.Hashtype {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
var e enums.Hashtype
|
||||
all := e.All()
|
||||
return all[f.IntBetween(0, len(all)-1)]
|
||||
}
|
||||
|
||||
func random_int32(f *faker.Faker, limits ...string) int32 {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
return f.Int32()
|
||||
}
|
||||
|
||||
func random_int64(f *faker.Faker, limits ...string) int64 {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
return f.Int64()
|
||||
}
|
||||
|
||||
func random_string(f *faker.Faker, limits ...string) string {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := strings.Join(f.Lorem().Words(f.IntBetween(1, 5)), " ")
|
||||
if len(limits) == 0 {
|
||||
return val
|
||||
}
|
||||
limitInt, _ := strconv.Atoi(limits[0])
|
||||
if limitInt > 0 && limitInt < len(val) {
|
||||
val = val[:limitInt]
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func random_time_Time(f *faker.Faker, limits ...string) time.Time {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
year := time.Hour * 24 * 365
|
||||
min := time.Now().Add(-year)
|
||||
max := time.Now().Add(year)
|
||||
return f.Time().TimeBetween(min, max)
|
||||
}
|
||||
|
||||
func random_uuid_UUID(f *faker.Faker, limits ...string) uuid.UUID {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
return uuid.New()
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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 TestTrapLocationBySourceID(t *testing.T) {
|
||||
t.Run("Base", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := TrapLocationBySourceID(random_int32(nil), random_uuid_UUID(nil))
|
||||
|
||||
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(trapLocationBySourceIDSQL, sb.String()); diff != "" {
|
||||
t.Fatalf("unexpected result (-got +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Mod", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := TrapLocationBySourceID(random_int32(nil), random_uuid_UUID(nil))
|
||||
|
||||
if _, err := psql.Select(query).WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queryDiff, err := testutils.QueryDiff(trapLocationBySourceIDSQL, 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(TrapLocationBySourceID(random_int32(nil), random_uuid_UUID(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) != 2 {
|
||||
t.Fatalf("expected %d columns, got %d", 2, len(columns))
|
||||
}
|
||||
|
||||
if columns[0] != "trap_location_globalid" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 0, "trap_location_globalid", columns[0])
|
||||
}
|
||||
|
||||
if columns[1] != "distance" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 1, "distance", columns[1])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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 TestUpdateOauthTokenOrg(t *testing.T) {
|
||||
t.Run("Base", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil))
|
||||
|
||||
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(updateOauthTokenOrgSQL, sb.String()); diff != "" {
|
||||
t.Fatalf("unexpected result (-got +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Mod", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil))
|
||||
|
||||
if _, err := psql.Update(query).WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queryDiff, err := testutils.QueryDiff(updateOauthTokenOrgSQL, 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("Exec", 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 := psql.Update(UpdateOauthTokenOrg(random_string(nil), random_string(nil), random_string(nil)))
|
||||
if _, err := bob.Exec(ctxTx, tx, query); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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 TestUserByUsername(t *testing.T) {
|
||||
t.Run("Base", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := UserByUsername(random_string(nil))
|
||||
|
||||
if _, err := query.WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(userByUsernameSQL, sb.String()); diff != "" {
|
||||
t.Fatalf("unexpected result (-got +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Mod", func(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
|
||||
query := UserByUsername(random_string(nil))
|
||||
|
||||
if _, err := psql.Select(query).WriteQuery(t.Context(), &sb, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queryDiff, err := testutils.QueryDiff(userByUsernameSQL, 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(UserByUsername(random_string(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) != 12 {
|
||||
t.Fatalf("expected %d columns, got %d", 12, len(columns))
|
||||
}
|
||||
|
||||
if columns[0] != "id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 0, "id", columns[0])
|
||||
}
|
||||
|
||||
if columns[1] != "arcgis_access_token" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 1, "arcgis_access_token", columns[1])
|
||||
}
|
||||
|
||||
if columns[2] != "arcgis_license" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 2, "arcgis_license", columns[2])
|
||||
}
|
||||
|
||||
if columns[3] != "arcgis_refresh_token" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 3, "arcgis_refresh_token", columns[3])
|
||||
}
|
||||
|
||||
if columns[4] != "arcgis_refresh_token_expires" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 4, "arcgis_refresh_token_expires", columns[4])
|
||||
}
|
||||
|
||||
if columns[5] != "arcgis_role" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 5, "arcgis_role", columns[5])
|
||||
}
|
||||
|
||||
if columns[6] != "display_name" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 6, "display_name", columns[6])
|
||||
}
|
||||
|
||||
if columns[7] != "email" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 7, "email", columns[7])
|
||||
}
|
||||
|
||||
if columns[8] != "organization_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 8, "organization_id", columns[8])
|
||||
}
|
||||
|
||||
if columns[9] != "username" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 9, "username", columns[9])
|
||||
}
|
||||
|
||||
if columns[10] != "password_hash_type" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 10, "password_hash_type", columns[10])
|
||||
}
|
||||
|
||||
if columns[11] != "password_hash" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 11, "password_hash", columns[11])
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue