-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* restore hooks functionality * [autofix.ci] apply automated fixes * Update main_test.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
18197b9
commit b8fd5dc
Showing
15 changed files
with
326 additions
and
136 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/alicebob/miniredis/v2" | ||
) | ||
|
||
func TestMainHooksAndStoreIntegration(t *testing.T) { | ||
// Run the miniredis server so we can store values across calls to main() | ||
s := miniredis.RunT(t) | ||
defer s.Close() | ||
|
||
redisUrl := fmt.Sprintf("redis://%s", s.Addr()) | ||
os.Setenv("ATMOS_REDIS_URL", redisUrl) | ||
|
||
origDir, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("failed to get current working directory: %v", err) | ||
} | ||
defer os.RemoveAll(path.Join(origDir, "testdata", "fixtures", "hooks-test", ".terraform")) | ||
defer os.Chdir(origDir) | ||
|
||
if err := os.Chdir("testdata/fixtures/hooks-test"); err != nil { | ||
t.Fatalf("failed to change directory: %v", err) | ||
} | ||
|
||
// Capture the original arguments | ||
origArgs := os.Args | ||
defer func() { os.Args = origArgs }() | ||
|
||
// Set the arguments for the first call to main() to deeploy the `random1` component, which uses a `hook` to set a | ||
// value in Redis | ||
os.Args = []string{"atmos", "terraform", "deploy", "random1", "-s", "test"} | ||
main() | ||
|
||
// Set the arguments for the second call to main() to deeploy the `random2` component, which uses a `store` to read a | ||
// value that was set in the first apply. | ||
os.Args = []string{"atmos", "terraform", "deploy", "random2", "-s", "test"} | ||
main() | ||
} |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
package hooks | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// Command is the interface for all commands that can be run by hooks | ||
type Command interface { | ||
GetName() string | ||
RunE(hook *Hook, event HookEvent, cmd *cobra.Command, args []string) error | ||
} |
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,10 @@ | ||
package hooks | ||
|
||
type HookEvent string | ||
|
||
const ( | ||
AfterTerraformApply HookEvent = "after.terraform.apply" | ||
BeforeTerraformApply HookEvent = "before.terraform.apply" | ||
AfterTerraformPlan HookEvent = "after.terraform.plan" | ||
BeforeTerraformPlan HookEvent = "before.terraform.plan" | ||
) |
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,14 @@ | ||
package hooks | ||
|
||
// Hook is the structure for a hook and is using in the stack config to define | ||
// a command that should be run when a specific event occurs. | ||
type Hook struct { | ||
Events []string `yaml:"events"` | ||
Command string `yaml:"command"` | ||
|
||
// Dynamic command-specific properties | ||
|
||
// store command | ||
Name string `yaml:"name,omitempty"` // for store command | ||
Outputs map[string]string `yaml:"outputs,omitempty"` // for store command | ||
} |
Oops, something went wrong.