-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#22: Allow specifying custom docker-db version
- Loading branch information
1 parent
ecfa58c
commit 0707749
Showing
6 changed files
with
115 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
package exasol_test_setup_abstraction_go | ||
|
||
type Configuration struct { | ||
type Builder struct { | ||
configFilePath string | ||
dockerDbVersion string | ||
} | ||
|
||
// New creates a new configuration object that allows creating a new TestSetupAbstraction. | ||
func New() Configuration { | ||
return Configuration{} | ||
// New creates a new builder that allows creating a new TestSetupAbstraction. | ||
func New() Builder { | ||
return Builder{} | ||
} | ||
|
||
// CloudSetupConfigFilePath sets the path to the cloud setup config file. | ||
// Call this to use a cloud test setup e.g. in AWS. | ||
// This will fall back to a local Docker container in case the file does not exist. | ||
func (c Configuration) CloudSetupConfigFilePath(path string) Configuration { | ||
func (c Builder) CloudSetupConfigFilePath(path string) Builder { | ||
c.configFilePath = path | ||
return c | ||
} | ||
|
||
// DockerDbVersion sets the Exasol Docker DB version to start. | ||
// This defaults to the version defined in exasol-test-setup-abstraction-java. | ||
func (c Configuration) DockerDbVersion(dockerDbVersion string) Configuration { | ||
func (c Builder) DockerDbVersion(dockerDbVersion string) Builder { | ||
c.dockerDbVersion = dockerDbVersion | ||
return c | ||
} | ||
|
||
// Start launches the test setup using the given configuration. | ||
// Don't forget to stop the setup after usage by calling TestSetupAbstraction.Stop(). | ||
func (c Configuration) Start() (*TestSetupAbstraction, error) { | ||
func (c Builder) Start() (*TestSetupAbstraction, error) { | ||
return startTestSetupAbstraction(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package exasol_test_setup_abstraction_go | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type BuilderSuite struct { | ||
suite.Suite | ||
setup *TestSetupAbstraction | ||
} | ||
|
||
func TestBuilderSuite(t *testing.T) { | ||
suite.Run(t, new(BuilderSuite)) | ||
} | ||
|
||
func (suite *BuilderSuite) BeforeTest(suiteName, testName string) { | ||
suite.setup = nil | ||
} | ||
|
||
func (suite *BuilderSuite) AfterTest(suiteName, testName string) { | ||
if suite.setup != nil { | ||
suite.NoError(suite.setup.Stop()) | ||
} | ||
} | ||
|
||
func (suite *BuilderSuite) TestDefaultConfiguration() { | ||
var err error | ||
suite.setup, err = New().Start() | ||
suite.NoError(err) | ||
suite.NotNil(suite.getExasolDbVersion()) | ||
} | ||
|
||
func (suite *BuilderSuite) TestCustomMissingConfigFile() { | ||
var err error | ||
suite.setup, err = New().CloudSetupConfigFilePath("missing-config-file.json").Start() | ||
suite.NoError(err) | ||
suite.NotNil(suite.getExasolDbVersion()) | ||
} | ||
|
||
func (suite *BuilderSuite) TestConfigFileWithInvalidContent() { | ||
var err error | ||
suite.setup, err = New().CloudSetupConfigFilePath(suite.writeTempFile("invalid json content")).Start() | ||
suite.ErrorContains(err, "failed to start server. The server did not print a port number") | ||
suite.ErrorContains(err, "E-ETSAS-7: Failed to start server: 'Unexpected char 105 at") | ||
suite.Nil(suite.setup) | ||
} | ||
|
||
func (suite *BuilderSuite) TestCustomExasolVersion() { | ||
var err error | ||
suite.setup, err = New().DockerDbVersion("7.1.14").Start() | ||
suite.NoError(err) | ||
suite.Equal("7.1.14", suite.getExasolDbVersion()) | ||
} | ||
|
||
func (suite *BuilderSuite) writeTempFile(content string) string { | ||
tempDir := suite.T().TempDir() | ||
file := path.Join(tempDir, "temp-file") | ||
err := os.WriteFile(file, []byte(content), 0600) | ||
suite.NoError(err) | ||
return file | ||
} | ||
|
||
func (suite *BuilderSuite) getExasolDbVersion() string { | ||
db, err := suite.setup.CreateConnection() | ||
suite.NoError(err) | ||
defer db.Close() | ||
row := db.QueryRow("select param_value from exa_metadata where param_name = 'databaseProductVersion'") | ||
suite.NoError(err) | ||
var result string | ||
suite.NoError(row.Scan(&result)) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters