Skip to content

Commit

Permalink
Fix: Adding check for alias suffix and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthis Holleville committed Mar 28, 2020
1 parent 0038bb1 commit 106a162
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion kcli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func GenerateAlias(module string) string {
}
splittedModule := strings.SplitN(module, "-", 2)
if val, ok := aliasMap[splittedModule[0]]; ok {
return val + splittedModule[1]
suffix := ""
if len(splittedModule) > 1 {
suffix = splittedModule[1]
}
return val + suffix
} else {
return module
}
Expand Down
14 changes: 12 additions & 2 deletions kcli/test/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ import (
)

// GenerateAlias(module string) string //
func TestTFAlias(t *testing.T){
func TestTFProjectAlias(t *testing.T){
result := kcli.GenerateAlias("terraform-project")
equals(t, "tfproject", result)
}

func TestASAlias(t *testing.T){
func TestTFAlias(t *testing.T){
result := kcli.GenerateAlias("terraform")
equals(t, "tf", result)
}

func TestASRoleAlias(t *testing.T){
result := kcli.GenerateAlias("ansible-role")
equals(t, "asrole", result)
}

func TestASAlias(t *testing.T){
result := kcli.GenerateAlias("ansible")
equals(t, "as", result)
}

func TestHelmAlias(t *testing.T){
result := kcli.GenerateAlias("helm")
equals(t, "helm", result)
Expand Down

0 comments on commit 106a162

Please sign in to comment.