1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Test the alphabetical sorting of a `generate-config` JSON structure.
func TestJSONSorted(t *testing.T) {
projectEntries := make(map[string]any)
projectEntries["entityKey1"] = map[string]any{
"groupKey1": map[string]any{
"keys": []any{
map[string]any{
"a.core.server.test.b": map[string]string{
"todo5": "stuff",
"todo6": "stuff",
},
},
map[string]any{
"a.core.server.test.c": map[string]string{
"todo3": "stuff",
"todo4": "stuff",
},
},
map[string]any{
"b.core.server.test.a": map[string]string{
"todo1": "stuff",
"todo2": "stuff",
},
},
},
},
}
projectEntries["entityKey2"] = map[string]any{
"groupKey2": map[string]any{
"keys": []any{
map[string]any{
"000.111.222": map[string]string{
"todo9": "stuff",
"todo10": "stuff",
},
},
map[string]any{
"aaa.ccc.bbb": map[string]string{
"todo7": "stuff",
"todo8": "stuff",
},
},
map[string]any{
"zzz.*": map[string]string{
"todo11": "stuff",
"todo12": "stuff",
},
},
},
},
}
sortedProjectEntries := make(map[string]any)
sortedProjectEntries["entityKey1"] = map[string]any{
"groupKey1": map[string]any{
"keys": []any{
map[string]any{
"a.core.server.test.b": map[string]string{
"todo5": "stuff",
"todo6": "stuff",
},
},
map[string]any{
"a.core.server.test.c": map[string]string{
"todo3": "stuff",
"todo4": "stuff",
},
},
map[string]any{
"b.core.server.test.a": map[string]string{
"todo1": "stuff",
"todo2": "stuff",
},
},
},
},
}
sortedProjectEntries["entityKey2"] = map[string]any{
"groupKey2": map[string]any{
"keys": []any{
map[string]any{
"000.111.222": map[string]string{
"todo9": "stuff",
"todo10": "stuff",
},
},
map[string]any{
"aaa.ccc.bbb": map[string]string{
"todo7": "stuff",
"todo8": "stuff",
},
},
map[string]any{
"zzz.*": map[string]string{
"todo11": "stuff",
"todo12": "stuff",
},
},
},
},
}
sortConfigKeys(projectEntries)
assert.Equal(t, sortedProjectEntries, projectEntries)
}
|