Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

if repoPath != "" {
affected, _, _, _, err = ExecuteDescribeAffectedWithTargetRepoPath(
atmosConfig,
&atmosConfig,

Check warning on line 158 in internal/exec/atlantis_generate_repo_config.go

View check run for this annotation

Codecov / codecov/patch

internal/exec/atlantis_generate_repo_config.go#L158

Added line #L158 was not covered by tests
repoPath,
verbose,
false,
Expand All @@ -167,7 +167,7 @@
)
} else if cloneTargetRef {
affected, _, _, _, err = ExecuteDescribeAffectedWithTargetRefClone(
atmosConfig,
&atmosConfig,
ref,
sha,
sshKeyPath,
Expand All @@ -182,7 +182,7 @@
)
} else {
affected, _, _, _, err = ExecuteDescribeAffectedWithTargetRefCheckout(
atmosConfig,
&atmosConfig,

Check warning on line 185 in internal/exec/atlantis_generate_repo_config.go

View check run for this annotation

Codecov / codecov/patch

internal/exec/atlantis_generate_repo_config.go#L185

Added line #L185 was not covered by tests
ref,
sha,
verbose,
Expand Down
9 changes: 2 additions & 7 deletions internal/exec/describe_affected.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

type DescribeAffectedCmdArgs struct {
CLIConfig schema.AtmosConfiguration
CLIConfig *schema.AtmosConfiguration
CloneTargetRef bool
Format string
IncludeDependents bool
Expand Down Expand Up @@ -178,7 +178,7 @@ func parseDescribeAffectedCliArgs(cmd *cobra.Command, args []string) (DescribeAf
}

result := DescribeAffectedCmdArgs{
CLIConfig: atmosConfig,
CLIConfig: &atmosConfig,
CloneTargetRef: cloneTargetRef,
Format: format,
IncludeDependents: includeDependents,
Expand Down Expand Up @@ -316,11 +316,6 @@ func ExecuteDescribeAffectedCmd(cmd *cobra.Command, args []string) error {
}
}
} else {
atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, true)
if err != nil {
return err
}

res, err := u.EvaluateYqExpression(&atmosConfig, affected, a.Query)
if err != nil {
return err
Expand Down
123 changes: 123 additions & 0 deletions internal/exec/describe_affected_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package exec

import (
"os"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"

cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

func TestExecuteDescribeAffectedCmd(t *testing.T) {
stacksPath := "../../tests/fixtures/scenarios/atmos-describe-affected"

err := os.Setenv("ATMOS_CLI_CONFIG_PATH", stacksPath)
assert.NoError(t, err, "Setting 'ATMOS_CLI_CONFIG_PATH' environment variable should execute without error")

err = os.Setenv("ATMOS_BASE_PATH", stacksPath)
assert.NoError(t, err, "Setting 'ATMOS_BASE_PATH' environment variable should execute without error")

defer func() {
err := os.Unsetenv("ATMOS_BASE_PATH")
assert.NoError(t, err)
err = os.Unsetenv("ATMOS_CLI_CONFIG_PATH")
assert.NoError(t, err)
}()

cmd := &cobra.Command{
Use: "describe affected",
Short: "List Atmos components and stacks affected by two Git commits",
Long: "Identify and list Atmos components and stacks impacted by changes between two Git commits.",
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Run: func(cmd *cobra.Command, args []string) {
err := ExecuteDescribeAffectedCmd(cmd, args)
if err != nil {
u.PrintErrorMarkdownAndExit("", err, "")
}
},
}

cmd.PersistentFlags().String("repo-path", "", "Filesystem path to the already cloned target repository with which to compare the current branch")
cmd.PersistentFlags().String("ref", "", "Git reference with which to compare the current branch. Refer to [10.3 Git Internals Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References) for more details")
cmd.PersistentFlags().String("sha", "", "Git commit SHA with which to compare the current branch")
cmd.PersistentFlags().String("file", "", "Write the result to the file")
cmd.PersistentFlags().String("format", "json", "The output format. (`json` is default)")
cmd.PersistentFlags().Bool("verbose", false, "Print more detailed output when cloning and checking out the Git repository")
cmd.PersistentFlags().String("ssh-key", "", "Path to PEM-encoded private key to clone private repos using SSH")
cmd.PersistentFlags().String("ssh-key-password", "", "Encryption password for the PEM-encoded private key if the key contains a password-encrypted PEM block")
cmd.PersistentFlags().Bool("include-spacelift-admin-stacks", false, "Include the Spacelift admin stack of any stack that is affected by config changes")
cmd.PersistentFlags().Bool("include-dependents", false, "Include the dependent components and stacks")
cmd.PersistentFlags().Bool("include-settings", false, "Include the `settings` section for each affected component")
cmd.PersistentFlags().Bool("upload", false, "Upload the affected components and stacks to a specified HTTP endpoint")
cmd.PersistentFlags().Bool("clone-target-ref", false, "Clone the target reference with which to compare the current branch\n"+
"If set to `false` (default), the target reference will be checked out instead\n"+
"This requires that the target reference is already cloned by Git, and the information about it exists in the `.git` directory")
cmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
cmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
cmd.PersistentFlags().StringSlice("skip", nil, "Skip executing a YAML function when processing Atmos stack manifests")
cmd.PersistentFlags().Bool("no-color", false, "Disable color output")
cmd.PersistentFlags().StringP("query", "q", "", "Query the results of an `atmos describe` command using `yq` expressions")
cmd.PersistentFlags().String("logs-level", "Info", "Logs level. Supported log levels are Trace, Debug, Info, Warning, Off. If the log level is set to Off, Atmos will not log any messages")
cmd.PersistentFlags().String("logs-file", "/dev/stderr", "The file to write Atmos logs to. Logs can be written to any file or any standard file descriptor, including '/dev/stdout', '/dev/stderr' and '/dev/null'")
cmd.PersistentFlags().String("base-path", "", "Base path for Atmos project")
cmd.PersistentFlags().StringSlice("config", []string{}, "Paths to configuration files (comma-separated or repeated flag)")
cmd.PersistentFlags().StringSlice("config-path", []string{}, "Paths to configuration directories (comma-separated or repeated flag)")
cmd.PersistentFlags().StringP("stack", "s", "",
"Filter by a specific stack\n"+
"The filter supports names of the top-level stack manifests (including subfolder paths), and `atmos` stack names (derived from the context vars)",
)

// Execute the command
cmd.SetArgs([]string{"--clone-target-ref=true", "--include-settings=true"})
err = cmd.Execute()
assert.NoError(t, err, "'atmos describe affected' command should execute without error")
}

func TestExecuteDescribeAffectedWithTargetRepoPath(t *testing.T) {
stacksPath := "../../tests/fixtures/scenarios/atmos-describe-affected"

err := os.Setenv("ATMOS_CLI_CONFIG_PATH", stacksPath)
assert.NoError(t, err, "Setting 'ATMOS_CLI_CONFIG_PATH' environment variable should execute without error")

err = os.Setenv("ATMOS_BASE_PATH", stacksPath)
assert.NoError(t, err, "Setting 'ATMOS_BASE_PATH' environment variable should execute without error")

defer func() {
err := os.Unsetenv("ATMOS_BASE_PATH")
assert.NoError(t, err)
err = os.Unsetenv("ATMOS_CLI_CONFIG_PATH")
assert.NoError(t, err)
}()

atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, true)
assert.Nil(t, err)

// We are using `atmos.yaml` from this dir. This `atmos.yaml` has set base_path: "./",
// which will be wrong for the remote repo which is cloned into a temp dir.
// Set the correct base path for the cloned remote repo
atmosConfig.BasePath = "./tests/fixtures/scenarios/atmos-describe-affected"

// Point to the same local repository
// This will compare this local repository with itself as the remote target, which should result in an empty `affected` list
repoPath := "../../"

affected, _, _, _, err := ExecuteDescribeAffectedWithTargetRepoPath(
&atmosConfig,
repoPath,
false,
false,
true,
"",
false,
false,
nil,
)
assert.Nil(t, err)

// The `affected` list should be empty, since the local repo is compared with itself.
assert.Equal(t, 0, len(affected))
}
Loading
Loading