Skip to content

Commit

Permalink
Added case for when the extension is larger than 3 characters. Also i…
Browse files Browse the repository at this point in the history
…ncluded a number of testcases to verify the semantics. This closes issue mitchellh#5 and its dependent hashicorp/packer#6083.
  • Loading branch information
arizvisa committed Mar 29, 2018
1 parent 7bae45d commit de06d49
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fat/short_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func generateShortName(longName string, used []string) (string, error) {
simpleName = simpleName[0 : len(simpleName)-1]
}

doSuffix := name != rawName || len(name) > 8
doSuffix := name != rawName || len(name) > 8 || len(ext) > 3
if !doSuffix {
for _, usedSingle := range used {
if strings.ToUpper(usedSingle) == simpleName {
Expand All @@ -53,6 +53,9 @@ func generateShortName(longName string, used []string) (string, error) {
}

if doSuffix {
if len(ext) > 3 {
ext = ext[:3]
}
found := false
for i := 1; i < 99999; i++ {
serial := fmt.Sprintf("~%d", i)
Expand Down
40 changes: 40 additions & 0 deletions fat/short_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,46 @@ func TestGenerateShortName(t *testing.T) {
if result != ".BIG" {
t.Fatalf("unexpected: %s", result)
}

// Test valid extension
result, err = generateShortName("proxy.psm", []string{})
if err != nil {
t.Fatalf("err should be nil: %s", err)
}

if result != "PROXY.PSM" {
t.Fatalf("unexpected: %s", result)
}

// Test long extension
result, err = generateShortName("proxy.psm1", []string{})
if err != nil {
t.Fatalf("err should be nil: %s", err)
}

if result != "PROXY~1.PSM" {
t.Fatalf("unexpected: %s", result)
}

// Test short extension
result, err = generateShortName("proxy.x", []string{})
if err != nil {
t.Fatalf("err should be nil: %s", err)
}

if result != "PROXY.X" {
t.Fatalf("unexpected: %s", result)
}

// Test double shortname
result, err = generateShortName("proxy.x", []string{"PROXY.X", "PROXY~1.X"})
if err != nil {
t.Fatalf("err should be nil: %s", err)
}

if result != "PROXY~2.X" {
t.Fatalf("unexpected: %s", result)
}
}

func TestShortNameEntryValue(t *testing.T) {
Expand Down

0 comments on commit de06d49

Please sign in to comment.