mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
package testcontainers |
|
|
|
import ( |
|
"context" |
|
|
|
"github.com/pkg/errors" |
|
) |
|
|
|
// GenericContainerRequest represents parameters to a generic container |
|
type GenericContainerRequest struct { |
|
ContainerRequest // embedded request for provider |
|
Started bool // whether to auto-start the container |
|
ProviderType ProviderType // which provider to use, Docker if empty |
|
} |
|
|
|
// GenericContainer creates a generic container with parameters |
|
func GenericContainer(ctx context.Context, req GenericContainerRequest) (Container, error) { |
|
provider, err := req.ProviderType.GetProvider() |
|
if err != nil { |
|
return nil, err |
|
} |
|
|
|
c, err := provider.CreateContainer(ctx, req.ContainerRequest) |
|
if err != nil { |
|
return nil, errors.Wrap(err, "failed to create container") |
|
} |
|
|
|
if req.Started { |
|
if err := c.Start(ctx); err != nil { |
|
return c, errors.Wrap(err, "failed to start container") |
|
} |
|
} |
|
|
|
return c, nil |
|
} |
|
|
|
// GenericProvider represents an abstraction for container and network providers |
|
type GenericProvider interface { |
|
ContainerProvider |
|
NetworkProvider |
|
}
|
|
|