Skip to content

Commit

Permalink
fix(dockertestx): Enable Factory to be defined externally
Browse files Browse the repository at this point in the history
  • Loading branch information
rxnew committed Feb 16, 2024
1 parent d7a1c9f commit 34159eb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions dockertestx/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (f *DynamoDBFactory) repository() string {
return "amazon/dynamodb-local"
}

func (f *DynamoDBFactory) create(p *Pool, opt ContainerOption) (*state, error) {
func (f *DynamoDBFactory) create(p *Pool, opt ContainerOption) (*State, error) {
rOpt := &dockertest.RunOptions{
Name: opt.Name,
Repository: f.repository(),
Expand All @@ -27,7 +27,7 @@ func (f *DynamoDBFactory) create(p *Pool, opt ContainerOption) (*state, error) {
if err != nil {
return nil, fmt.Errorf("could not start resource: %w", err)
}
return &state{
return &State{
ContainerName: opt.Name,
Repository: f.repository(),
Tag: opt.Tag,
Expand All @@ -37,7 +37,7 @@ func (f *DynamoDBFactory) create(p *Pool, opt ContainerOption) (*state, error) {
}, nil
}

func (f *DynamoDBFactory) ready(p *Pool, s *state) error {
func (f *DynamoDBFactory) ready(p *Pool, s *State) error {
return p.Pool.Retry(func() error {
cl := dynamodb.New(dynamodb.Options{
Credentials: credentials.NewStaticCredentialsProvider("dummy", "dummy", ""),
Expand Down
12 changes: 6 additions & 6 deletions dockertestx/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *Pool) Save() error {
return nil
}

s := make([]state, 0)
s := make([]State, 0)
if p.option.KeepContainer {
s = p.states
}
Expand All @@ -120,9 +120,9 @@ func (p *Pool) Save() error {
return nil
}

type stateList []state
type stateList []State

func (l stateList) find(name, repository, tag string) (*state, bool) {
func (l stateList) find(name, repository, tag string) (*State, bool) {
if len(name) > 0 {
for _, s := range l {
if s.ContainerName == name {
Expand All @@ -140,7 +140,7 @@ func (l stateList) find(name, repository, tag string) (*state, bool) {
return nil, false
}

type state struct {
type State struct {
ContainerName string `json:"container_name"`
Repository string `json:"repository"`
Tag string `json:"tag"`
Expand All @@ -165,10 +165,10 @@ type ContainerFactory interface {
repository() string

// create docker container in pool
create(p *Pool, opt ContainerOption) (*state, error)
create(p *Pool, opt ContainerOption) (*State, error)

// ready to access
ready(p *Pool, s *state) error
ready(p *Pool, s *State) error
}

func (p *Pool) NewResource(factory ContainerFactory, opt ContainerOption) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions dockertestx/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (f *PostgresFactory) repository() string {
return "postgres"
}

func (f *PostgresFactory) create(p *Pool, opt ContainerOption) (*state, error) {
func (f *PostgresFactory) create(p *Pool, opt ContainerOption) (*State, error) {
dbUser := "dockertestx"
dbPassword := "passw0rd"
dbName := "test"
Expand All @@ -33,7 +33,7 @@ func (f *PostgresFactory) create(p *Pool, opt ContainerOption) (*state, error) {
if err != nil {
return nil, fmt.Errorf("could not start resource: %w", err)
}
return &state{
return &State{
ContainerName: opt.Name,
Repository: f.repository(),
Tag: opt.Tag,
Expand All @@ -49,7 +49,7 @@ func (f *PostgresFactory) create(p *Pool, opt ContainerOption) (*state, error) {
}, nil
}

func (f *PostgresFactory) ready(p *Pool, s *state) error {
func (f *PostgresFactory) ready(p *Pool, s *State) error {
return p.Retry(func() error {
db, err := sql.Open("postgres", s.DSN)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions dockertestx/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (f *S3Factory) repository() string {
return "minio/minio"
}

func (f *S3Factory) create(p *Pool, opt ContainerOption) (*state, error) {
func (f *S3Factory) create(p *Pool, opt ContainerOption) (*State, error) {
rOpt := &dockertest.RunOptions{
Name: opt.Name,
Repository: f.repository(),
Expand All @@ -35,7 +35,7 @@ func (f *S3Factory) create(p *Pool, opt ContainerOption) (*state, error) {
if err != nil {
return nil, fmt.Errorf("could not start resource: %w", err)
}
return &state{
return &State{
ContainerName: opt.Name,
Repository: f.repository(),
Tag: opt.Tag,
Expand All @@ -45,7 +45,7 @@ func (f *S3Factory) create(p *Pool, opt ContainerOption) (*state, error) {
}, nil
}

func (f *S3Factory) ready(p *Pool, s *state) error {
func (f *S3Factory) ready(p *Pool, s *State) error {
return p.Pool.Retry(func() error {
cl := s3.New(s3.Options{
Credentials: credentials.NewStaticCredentialsProvider(S3AWSAccessKeyID, S3AWSSecretAccessKey, ""),
Expand Down

0 comments on commit 34159eb

Please sign in to comment.