Skip to content

Commit

Permalink
fix AnsibleGalaxyRoleInstallCmd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apenella committed Apr 3, 2024
1 parent d927a62 commit 40388c0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
11 changes: 7 additions & 4 deletions pkg/galaxy/role/install/ansibleGalaxyRoleInstallCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const (
// DefaultAnsibleGalaxyRoleInstallBinary is the ansible-galaxy binary file default value
DefaultAnsibleGalaxyRoleInstallBinary = "ansible-galaxy"

//AnsibleGalaxyRoleInstallCommand is the ansible-galaxy command to install roles
AnsibleGalaxyRoleInstallCommand = "role install"
// AnsibleGalaxyRoleSubCommand is the ansible-galaxy role subcommand
AnsibleGalaxyRoleSubCommand = "role"

// AnsibleGalaxyRoleInstallSubCommand is the ansible-galaxy role install subcommand
AnsibleGalaxyRoleInstallSubCommand = "install"
)

// AnsibleGalaxyRoleInstallOptionsFunc is a function to set executor options
Expand Down Expand Up @@ -68,7 +71,7 @@ func (p *AnsibleGalaxyRoleInstallCmd) Command() ([]string, error) {
p.Binary = DefaultAnsibleGalaxyRoleInstallBinary
}

cmd = append(cmd, p.Binary, "role", "install")
cmd = append(cmd, p.Binary, AnsibleGalaxyRoleSubCommand, AnsibleGalaxyRoleInstallSubCommand)

// Add the options
if p.GalaxyRoleInstallOptions != nil {
Expand All @@ -93,7 +96,7 @@ func (p *AnsibleGalaxyRoleInstallCmd) String() string {
p.Binary = DefaultAnsibleGalaxyRoleInstallBinary
}

str := fmt.Sprintf("%s %s", p.Binary, AnsibleGalaxyRoleInstallCommand)
str := fmt.Sprintf("%s %s %s", p.Binary, AnsibleGalaxyRoleSubCommand, AnsibleGalaxyRoleInstallSubCommand)

if p.GalaxyRoleInstallOptions != nil {
str = fmt.Sprintf("%s %s", str, p.GalaxyRoleInstallOptions.String())
Expand Down
84 changes: 78 additions & 6 deletions pkg/galaxy/role/install/ansibleGalaxyRoleInstallCmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,55 @@ func TestAnsibleGalaxyRoleInstallCmdCommand(t *testing.T) {
command []string
err error
}{
{
desc: "Testing generate a command for AnsibleGalaxyRoleInstallCmd with all flags using default binary",
cmd: NewAnsibleGalaxyRoleInstallCmd(
WithRoleNames("role-name"),
WithGalaxyRoleInstallOptions(&AnsibleGalaxyRoleInstallOptions{
ApiKey: "apikey",
Force: true,
ForceWithDeps: true,
IgnoreCerts: true,
IgnoreErrors: true,
KeepSCMMeta: true,
NoDeps: true,
RoleFile: "rolefile",
RolesPath: "rolespath",
Server: "server",
Timeout: "timeout",
Token: "token",
Verbose: true,
VerboseV: true,
VerboseVV: true,
VerboseVVV: true,
VerboseVVVV: true,
Version: true,
}),
),
err: &errors.Error{},
command: []string{"ansible-galaxy", "role", "install",
ApiKeyFlag, "apikey",
ForceFlag,
ForceWithDepsFlag,
IgnoreCertsFlag,
IgnoreErrorsFlag,
KeepSCMMetaFlag,
NoDepsFlag,
RoleFileFlag, "rolefile",
RolesPathFlag, "rolespath",
ServerFlag, "server",
TimeoutFlag, "timeout",
TokenFlag, "token",
VerboseVVVVFlag,
VersionFlag,
"role-name",
},
},
{
desc: "Testing generate a command for AnsibleGalaxyRoleInstallCmd with all flags",
cmd: NewAnsibleGalaxyRoleInstallCmd(
WithBinary("ansible-galaxy-binary"),
WithRoleNames("nginx"),
WithRoleNames("role-name"),
WithGalaxyRoleInstallOptions(&AnsibleGalaxyRoleInstallOptions{
ApiKey: "apikey",
Force: true,
Expand All @@ -62,7 +106,7 @@ func TestAnsibleGalaxyRoleInstallCmdCommand(t *testing.T) {
}),
),
err: &errors.Error{},
command: []string{"ansible-galaxy-binary", "role install",
command: []string{"ansible-galaxy-binary", "role", "install",
ApiKeyFlag, "apikey",
ForceFlag,
ForceWithDepsFlag,
Expand All @@ -77,7 +121,7 @@ func TestAnsibleGalaxyRoleInstallCmdCommand(t *testing.T) {
TokenFlag, "token",
VerboseVVVVFlag,
VersionFlag,
"nginx",
"role-name",
},
},
}
Expand All @@ -97,17 +141,45 @@ func TestAnsibleGalaxyRoleInstallCmdCommand(t *testing.T) {
}
}

func TestAnsibleGalaxyRoleInstallCmdS(t *testing.T) {
func TestAnsibleGalaxyRoleInstallCmdString(t *testing.T) {
tests := []struct {
desc string
cmd *AnsibleGalaxyRoleInstallCmd
command string
}{

{
desc: "Testing generate a command for AnsibleGalaxyRoleInstallCmd with all flags using default binary",
cmd: NewAnsibleGalaxyRoleInstallCmd(
WithRoleNames("role-name"),
WithGalaxyRoleInstallOptions(&AnsibleGalaxyRoleInstallOptions{
ApiKey: "apikey",
Force: true,
ForceWithDeps: true,
IgnoreCerts: true,
IgnoreErrors: true,
KeepSCMMeta: true,
NoDeps: true,
RoleFile: "rolefile",
RolesPath: "rolespath",
Server: "server",
Timeout: "timeout",
Token: "token",
Verbose: true,
VerboseV: true,
VerboseVV: true,
VerboseVVV: true,
VerboseVVVV: true,
Version: true,
}),
),
command: "ansible-galaxy role install --api-key apikey --force --force-with-deps --ignore-certs --ignore-errors --keep-scm-meta --no-deps --role-file rolefile --roles-path rolespath --server server --timeout timeout --token token -vvvv -v -vv -vvv -vvvv --version role-name",
},
{
desc: "Testing generate a command for AnsibleGalaxyRoleInstallCmd with all flags",
cmd: NewAnsibleGalaxyRoleInstallCmd(
WithBinary("ansible-galaxy-binary"),
WithRoleNames("nginx"),
WithRoleNames("role-name"),
WithGalaxyRoleInstallOptions(&AnsibleGalaxyRoleInstallOptions{
ApiKey: "apikey",
Force: true,
Expand All @@ -129,7 +201,7 @@ func TestAnsibleGalaxyRoleInstallCmdS(t *testing.T) {
Version: true,
}),
),
command: "ansible-galaxy-binary role install --api-key apikey --force --force-with-deps --ignore-certs --ignore-errors --keep-scm-meta --no-deps --role-file rolefile --roles-path rolespath --server server --timeout timeout --token token -vvvv -v -vv -vvv -vvvv --version nginx",
command: "ansible-galaxy-binary role install --api-key apikey --force --force-with-deps --ignore-certs --ignore-errors --keep-scm-meta --no-deps --role-file rolefile --roles-path rolespath --server server --timeout timeout --token token -vvvv -v -vv -vvv -vvvv --version role-name",
},
}

Expand Down

0 comments on commit 40388c0

Please sign in to comment.