Skip to content

Commit ed38e1c

Browse files
Matt Calhoungoruha
andauthored
add configurable destination path (#55)
* support copying to alternate dest directory * update readme * fix config init --------- Co-authored-by: Igor Rodionov <goruha@gmail.com>
1 parent 13635be commit ed38e1c

File tree

4 files changed

+57
-31
lines changed

4 files changed

+57
-31
lines changed

pkg/atmos/component-helper/00_setup.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,16 @@ func (s *TestSuite) BootstrapTempDir(t *testing.T, config *c.Config) {
122122
}
123123

124124
func (s *TestSuite) CopyComponentToTempDir(t *testing.T, config *c.Config) {
125-
s.logPhaseStatus("setup/copy component to temp dir", "started")
125+
var destPath string
126+
if config.ComponentDestDir != "" {
127+
destPath = filepath.Join(config.TempDir, config.ComponentDestDir)
128+
} else {
129+
destPath = filepath.Join(config.TempDir, "components", "terraform", "target")
130+
}
131+
132+
message := fmt.Sprintf("setup/copy component to temp dir: %s", destPath)
133+
s.logPhaseStatus(message, "started")
126134

127-
destPath := filepath.Join(config.TempDir, "components", "terraform", "target")
128135
err := s.copyDirectoryContents(config.SrcDir, destPath)
129136
if err != nil {
130137
s.logPhaseStatus("setup/copy component to temp dir", "failed")

pkg/atmos/component-helper/README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,34 @@ Finally, The Helper will clean up the temporary directory and any other resource
192192
component under test and its dependencies. This can be useful for debugging issues with the component or its
193193
dependencies.
194194

195+
### Custom Component Directory
196+
197+
In some cases, for example where there are a suite of components that need to be tested together, it's not desirable to have the component copied to the `target` directory under `<TEMP_DIR>/components/terraform/target`. In this case, you can specify a custom directory by using the `-component-dest-dir` flag or by creting a custom `SetupSuite()` method on your Test Suite.
198+
199+
```go
200+
func (s *ExampleTestSuite) SetupSuite() {
201+
s.TestSuite.InitConfig()
202+
s.TestSuite.Config.ComponentDestDir = "components/terraform/myspecialcomponent"
203+
s.TestSuite.SetupSuite()
204+
}
205+
```
206+
195207
## Flags reference
196208

197-
| Flag | Description | Default |
198-
| -------------------------- | ----------------------------------------------------- | ----------------- |
199-
| -config | The path to the config file | test_suite.yaml |
200-
| -fixtures-dir | The path to the fixtures directory | fixtures |
201-
| -only-deploy-dependencies | Only run the deploy dependencies phase of tests | false |
202-
| -skip-deploy-component | Skips running the deploy component phase of tests | false |
203-
| -skip-deploy-dependencies | Skips running the deploy dependencies phase of tests | false |
204-
| -skip-destroy-component | Skips running the destroy component phase of tests | false |
205-
| -skip-destroy-dependencies | Skips running the destroy dependencies phase of tests | false |
206-
| -skip-enabled-flag-test | Skips running the Enabled flag test | false |
207-
| -skip-setup | Skips running the setup test suite phase of tests | false |
208-
| -skip-teardown | Skips running the teardown test suite phase of tests | false |
209-
| -skip-vendor | Skips running the vendor dependencies phase of tests | false |
210-
| -src-dir | The path to the component source directory | src |
211-
| -state-dir | The path to the terraform state directory | {temp_dir}/state |
212-
| -temp-dir | The path to the temp directory | {random temp dir} |
209+
| Flag | Description | Default |
210+
| -------------------------- | ------------------------------------------------------------------------------- | --------------------------- |
211+
| -component-dest-dir | The path to the component destination directory, relative to the temp directory | components/terraform/target |
212+
| -config | The path to the config file | test_suite.yaml |
213+
| -fixtures-dir | The path to the fixtures directory | fixtures |
214+
| -only-deploy-dependencies | Only run the deploy dependencies phase of tests | false |
215+
| -skip-deploy-component | Skips running the deploy component phase of tests | false |
216+
| -skip-deploy-dependencies | Skips running the deploy dependencies phase of tests | false |
217+
| -skip-destroy-component | Skips running the destroy component phase of tests | false |
218+
| -skip-destroy-dependencies | Skips running the destroy dependencies phase of tests | false |
219+
| -skip-enabled-flag-test | Skips running the Enabled flag test | false |
220+
| -skip-setup | Skips running the setup test suite phase of tests | false |
221+
| -skip-teardown | Skips running the teardown test suite phase of tests | false |
222+
| -skip-vendor | Skips running the vendor dependencies phase of tests | false |
223+
| -src-dir | The path to the component source directory | src |
224+
| -state-dir | The path to the terraform state directory | {temp_dir}/state |
225+
| -temp-dir | The path to the temp directory | {random temp dir} |

pkg/atmos/component-helper/config/config.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func init() {
16+
flag.String("component-dest-dir", "", "The path to the component destination directory, relative to the temp directory")
1617
flag.String("config", "test_suite.yaml", "The path to the config file")
1718
flag.String("fixtures-dir", "fixtures", "The path to the fixtures directory")
1819
flag.Bool("only-deploy-dependencies", true, "Only run the deploy dependencies phase of tests")
@@ -30,6 +31,7 @@ func init() {
3031
}
3132

3233
type Config struct {
34+
ComponentDestDir string
3335
ConfigFilePath string
3436
FixturesDir string
3537
RandomIdentifier string
@@ -89,9 +91,11 @@ func InitConfig(t *testing.T) *Config {
8991

9092
viper.SetDefault("ConfigFilePath", "test_suite.yaml")
9193
viper.SetDefault("FixturesDir", "fixtures")
94+
viper.SetDefault("ComponentDestDir", "")
9295

9396
randID := random.UniqueId()
9497
viper.SetDefault("RandomIdentifier", strings.ToLower(randID))
98+
9599
viper.SetDefault("OnlyDeployDependencies", false)
96100
viper.SetDefault("SkipDeployComponent", false)
97101
viper.SetDefault("SkipDeployDependencies", false)
@@ -111,6 +115,9 @@ func InitConfig(t *testing.T) *Config {
111115
err := viper.BindPFlags(pflag.CommandLine)
112116
require.NoError(t, err)
113117

118+
err = viper.BindPFlag("ComponentDestDir", pflag.Lookup("component-dest-dir"))
119+
require.NoError(t, err)
120+
114121
err = viper.BindPFlag("ConfigFilePath", pflag.Lookup("config"))
115122
require.NoError(t, err)
116123

@@ -170,16 +177,5 @@ func InitConfig(t *testing.T) *Config {
170177
err = writeConfigWithoutPFlags(viper.GetString("ConfigFilePath"))
171178
require.NoError(t, err)
172179

173-
if config.OnlyDeployDependencies {
174-
config.SkipDeployComponent = true
175-
config.SkipDeployDependencies = false
176-
config.SkipDestroyComponent = true
177-
config.SkipDestroyDependencies = true
178-
config.SkipEnabledFlagTest = true
179-
config.SkipSetupTestSuite = false
180-
config.SkipTeardownTestSuite = true
181-
config.SkipVendorDependencies = false
182-
}
183-
184180
return config
185181
}

pkg/atmos/component-helper/suite.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ func (s *TestSuite) DestroyAtmosComponent(t *testing.T, componentName string, st
112112
s.logPhaseStatus(phaseName, "completed")
113113
}
114114

115+
116+
func (s *TestSuite) InitConfig() {
117+
t := s.T()
118+
119+
if s.Config == nil {
120+
config := c.InitConfig(t)
121+
s.Config = config
122+
}
123+
}
124+
115125
func (s *TestSuite) BeforeTest(suiteName, testName string) {
116126
if s.Config.OnlyDeployDependencies {
117127
s.T().Skip("Skipping test because OnlyDeployDependencies is true")
@@ -122,8 +132,8 @@ func (s *TestSuite) BeforeTest(suiteName, testName string) {
122132
func (s *TestSuite) SetupSuite() {
123133
t := s.T()
124134

125-
config := c.InitConfig(t)
126-
s.Config = config
135+
s.InitConfig()
136+
config := s.Config
127137

128138
if s.Config.SkipSetupTestSuite {
129139
s.logPhaseStatus("setup", "skipped")

0 commit comments

Comments
 (0)