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

     1  package docker
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ory/dockertest/v3"
     7  
     8  	contractsconfig "github.com/goravel/framework/contracts/config"
     9  	"github.com/goravel/framework/contracts/database/orm"
    10  	"github.com/goravel/framework/contracts/testing"
    11  	"github.com/goravel/framework/support/file"
    12  )
    13  
    14  type Sqlite struct {
    15  	config     contractsconfig.Config
    16  	connection string
    17  }
    18  
    19  func NewSqlite(config contractsconfig.Config, connection string) *Sqlite {
    20  	return &Sqlite{
    21  		config:     config,
    22  		connection: connection,
    23  	}
    24  }
    25  
    26  func (receiver *Sqlite) Config(resource *dockertest.Resource) testing.Config {
    27  	return testing.Config{
    28  		Database: receiver.config.GetString(fmt.Sprintf("database.connections.%s.database", receiver.connection)),
    29  	}
    30  }
    31  
    32  func (receiver *Sqlite) Clear(pool *dockertest.Pool, resource *dockertest.Resource) error {
    33  	return file.Remove(receiver.config.GetString(fmt.Sprintf("database.connections.%s.database", receiver.connection)))
    34  }
    35  
    36  func (receiver *Sqlite) Name() orm.Driver {
    37  	return orm.DriverSqlite
    38  }
    39  
    40  func (receiver *Sqlite) Image() *dockertest.RunOptions {
    41  	return &dockertest.RunOptions{
    42  		Repository: "nouchka/sqlite3",
    43  		Tag:        "latest",
    44  		Env:        []string{},
    45  	}
    46  }