go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/db/dbgen/main_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package dbgen
     9  
    10  import (
    11  	"context"
    12  	"testing"
    13  	"time"
    14  
    15  	"go.charczuk.com/sdk/testutil"
    16  	"go.charczuk.com/sdk/uuid"
    17  )
    18  
    19  func TestMain(m *testing.M) {
    20  	testutil.New(m,
    21  		testutil.OptWithDefaultDB(),
    22  		testutil.OptBefore(
    23  			func(ctx context.Context) error {
    24  				_, err := testutil.DefaultDB().Invoke().Exec(`CREATE EXTENSION IF NOT EXISTS "pgcrypto"`)
    25  				return err
    26  			},
    27  		),
    28  	).Run()
    29  }
    30  
    31  type modelTest struct {
    32  	ID         uuid.UUID     `db:"id,pk,auto"`
    33  	CreatedUTC time.Time     `db:"created_utc"`
    34  	UpdatedUTC *time.Time    `db:"updated_utc"`
    35  	Elapsed    time.Duration `db:"elapsed"`
    36  	Int64      int64         `db:"int_64"`
    37  	Int        int           `db:"int"`
    38  	Int32      int32         `db:"int_32"`
    39  	Name       string        `db:"name"`
    40  	IsEnabled  bool          `db:"is_enabled"`
    41  	Cost       float64       `db:"cost"`
    42  	Ratio      float32       `db:"ratio"`
    43  }
    44  
    45  func (mt modelTest) TableName() string { return "model_test" }
    46  
    47  type childModelTest struct {
    48  	ID       uuid.UUID `db:"id,pk,auto"`
    49  	ParentID uuid.UUID `db:"parent_id"`
    50  	Name     string    `db:"name"`
    51  }
    52  
    53  func (cmt childModelTest) TableName() string { return "child_model_test" }