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

     1  package docker
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ory/dockertest/v3"
     7  	"github.com/stretchr/testify/suite"
     8  
     9  	configmocks "github.com/goravel/framework/contracts/config/mocks"
    10  	"github.com/goravel/framework/contracts/database/orm"
    11  )
    12  
    13  type PostgresqlTestSuite struct {
    14  	suite.Suite
    15  	mockConfig *configmocks.Config
    16  	postgresql *Postgresql
    17  }
    18  
    19  func TestPostgresqlTestSuite(t *testing.T) {
    20  	suite.Run(t, new(PostgresqlTestSuite))
    21  }
    22  
    23  func (s *PostgresqlTestSuite) SetupTest() {
    24  	s.mockConfig = configmocks.NewConfig(s.T())
    25  	s.postgresql = &Postgresql{
    26  		config:     s.mockConfig,
    27  		connection: "postgresql",
    28  	}
    29  }
    30  
    31  func (s *PostgresqlTestSuite) TestName() {
    32  	s.Equal(orm.DriverPostgresql, s.postgresql.Name())
    33  }
    34  
    35  func (s *PostgresqlTestSuite) TestImage() {
    36  	s.mockConfig.On("GetString", "database.connections.postgresql.database").Return("goravel").Once()
    37  	s.mockConfig.On("GetString", "database.connections.postgresql.username").Return("root").Once()
    38  	s.mockConfig.On("GetString", "database.connections.postgresql.password").Return("123123").Once()
    39  
    40  	s.Equal(&dockertest.RunOptions{
    41  		Repository: "postgres",
    42  		Tag:        "latest",
    43  		Env: []string{
    44  			"POSTGRES_USER=root",
    45  			"POSTGRES_PASSWORD=123123",
    46  			"POSTGRES_DB=goravel",
    47  			"listen_addresses = '*'",
    48  		},
    49  	}, s.postgresql.Image())
    50  }