Skip to content

Commit

Permalink
fix sort of map output
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden committed Jun 10, 2023
1 parent 9d3524e commit 29eadea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/arm/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"regexp"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -190,13 +191,21 @@ func ArrayToString(defaultValue []interface{}) string {

// Tags take map into a string for tags
func Tags(tags map[string]interface{}) string {
keys := make([]string, 0, len(tags))
for k := range tags {
keys = append(keys, k)
}

sort.Strings(keys)

tagged := "{\n"

for item, name := range tags {
if _, ok := name.(string); ok {
tagged += "\t\"" + item + "\"" + " = " + "\"" + name.(string) + "\"\n"
for _, k := range keys {
if value, ok := tags[k].(string); ok {
tagged += "\t\"" + k + "\"" + " = " + "\"" + value + "\"\n"

} else {
tagged += "\t\"" + item + "\"" + " = " + "\"OBJECT\"\n"
tagged += "\t\"" + k + "\"" + " = " + "\"OBJECT\"\n"
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/arm/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ func Test_tags(t *testing.T) {
tags map[string]interface{}
}

result := "{\n\t\"test\" = \"something\"\n\t\"another\" = \"stuff\"\n\t}"
bodge := "{\n\t\"test\" = \"something\"\n\t\"another\" = \"OBJECT\"\n\t}"
result := "{\n\t\"another\" = \"stuff\"\n\t\"test\" = \"something\"\n\t}"
bodge := "{\n\t\"another\" = \"OBJECT\"\n\t\"test\" = \"something\"\n\t}"

tests := []struct {
name string
Expand Down

0 comments on commit 29eadea

Please sign in to comment.