github.com/goravel/framework@v1.13.9/contracts/testing/testing.go (about)

     1  package testing
     2  
     3  import (
     4  	"github.com/ory/dockertest/v3"
     5  
     6  	"github.com/goravel/framework/contracts/database/orm"
     7  	"github.com/goravel/framework/contracts/database/seeder"
     8  )
     9  
    10  type Testing interface {
    11  	// Docker get the Docker instance.
    12  	Docker() Docker
    13  }
    14  
    15  type Docker interface {
    16  	// Database get a database connection instance.
    17  	Database(connection ...string) (Database, error)
    18  }
    19  
    20  type Database interface {
    21  	// Build the database.
    22  	Build() error
    23  	// Config gets the database configuration.
    24  	Config() Config
    25  	// Clear clears the database.
    26  	Clear() error
    27  	// Image gets the database image.
    28  	Image(Image)
    29  	// Seed runs the database seeds.
    30  	Seed(seeds ...seeder.Seeder)
    31  }
    32  
    33  type DatabaseDriver interface {
    34  	// Config gets the database configuration.
    35  	Config(resource *dockertest.Resource) Config
    36  	// Clear clears the database.
    37  	Clear(pool *dockertest.Pool, resource *dockertest.Resource) error
    38  	// Name gets the database driver name.
    39  	Name() orm.Driver
    40  	// Image gets the database image.
    41  	Image() *dockertest.RunOptions
    42  }
    43  
    44  type Config struct {
    45  	Host     string
    46  	Port     int
    47  	Database string
    48  	Username string
    49  	Password string
    50  }
    51  
    52  type Image struct {
    53  	Env        []string
    54  	Repository string
    55  	Tag        string
    56  	// unit: second
    57  	Timeout uint
    58  }