-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_test.go
More file actions
135 lines (120 loc) · 3.34 KB
/
json_test.go
File metadata and controls
135 lines (120 loc) · 3.34 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package batcha
import "testing"
func TestToPascalCase(t *testing.T) {
tests := []struct {
input string
want string
}{
{"", ""},
{"a", "A"},
{"jobDefinitionName", "JobDefinitionName"},
{"type", "Type"},
{"containerProperties", "ContainerProperties"},
{"VCPU", "VCPU"},
{"Already", "Already"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := toPascalCase(tt.input)
if got != tt.want {
t.Errorf("toPascalCase(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
func TestToCamelCase(t *testing.T) {
tests := []struct {
input string
want string
}{
{"", ""},
{"A", "a"},
{"JobDefinitionName", "jobDefinitionName"},
{"Type", "type"},
{"ContainerProperties", "containerProperties"},
{"VCPU", "vCPU"},
{"already", "already"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := toCamelCase(tt.input)
if got != tt.want {
t.Errorf("toCamelCase(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
func TestWalkMap(t *testing.T) {
input := map[string]any{
"jobDefinitionName": "test-job",
"containerProperties": map[string]any{
"image": "nginx",
"environment": []any{
map[string]any{
"name": "FOO",
"value": "bar",
},
},
},
"tags": map[string]any{
"myTag": "value",
},
"parameters": map[string]any{
"inputFile": "s3://bucket/file",
},
}
result := walkMap(input, toPascalCase).(map[string]any)
// Top-level keys should be PascalCase
if _, ok := result["JobDefinitionName"]; !ok {
t.Error("expected JobDefinitionName key")
}
// Nested keys should be PascalCase
cp := result["ContainerProperties"].(map[string]any)
if _, ok := cp["Image"]; !ok {
t.Error("expected Image key in ContainerProperties")
}
// Environment inside array should be PascalCase
envList := cp["Environment"].([]any)
envItem := envList[0].(map[string]any)
if _, ok := envItem["Name"]; !ok {
t.Error("expected Name key in environment item")
}
// Tags keys should NOT be converted (skipConvertKeys)
tags := result["Tags"].(map[string]any)
if _, ok := tags["myTag"]; !ok {
t.Error("expected tags keys to be preserved as-is")
}
// Parameters keys should NOT be converted (skipConvertKeys)
params := result["Parameters"].(map[string]any)
if _, ok := params["inputFile"]; !ok {
t.Error("expected parameters keys to be preserved as-is")
}
}
func TestWalkMap_ToCamelCase_SkipConvertKeys(t *testing.T) {
// Simulate AWS response with PascalCase keys
input := map[string]any{
"JobDefinitionName": "test-job",
"Tags": map[string]any{
"ProjectName": "my-project",
"Environment": "dev",
},
"Parameters": map[string]any{
"InputFile": "s3://bucket/file",
},
}
result := walkMap(input, toCamelCase).(map[string]any)
// Top-level keys should be camelCase
if _, ok := result["jobDefinitionName"]; !ok {
t.Error("expected jobDefinitionName key")
}
// Tags children should NOT be converted even with PascalCase parent key
tags := result["tags"].(map[string]any)
if _, ok := tags["ProjectName"]; !ok {
t.Error("expected Tags children to be preserved as-is, but ProjectName was converted")
}
// Parameters children should NOT be converted
params := result["parameters"].(map[string]any)
if _, ok := params["InputFile"]; !ok {
t.Error("expected Parameters children to be preserved as-is, but InputFile was converted")
}
}