Skip to content

Commit 20b86e8

Browse files
Update variable names to Go convention + Simplify map lookups (#894)
* Update variable names to Go convention * Update translator.go * Update translator.go
1 parent 7e09ba4 commit 20b86e8

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

internal/build/cmd/generate/commands/genexamples/translator.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,13 +1058,7 @@ var ConsoleToGo = []TranslateRule{
10581058
fmt.Fprint(&src, args)
10591059
}
10601060

1061-
var hasPretty bool
1062-
for k, _ := range params {
1063-
if k == "pretty" {
1064-
hasPretty = true
1065-
}
1066-
}
1067-
1061+
_, hasPretty := params["pretty"]
10681062
if !hasPretty {
10691063
src.WriteString("\tes.Scroll.WithPretty(),\n")
10701064
}
@@ -1111,13 +1105,7 @@ var ConsoleToGo = []TranslateRule{
11111105
fmt.Fprint(&src, args)
11121106
}
11131107

1114-
var hasPretty bool
1115-
for k, _ := range params {
1116-
if k == "pretty" {
1117-
hasPretty = true
1118-
}
1119-
}
1120-
1108+
_, hasPretty := params["pretty"]
11211109
if !hasPretty {
11221110
src.WriteString("\tes.Search.WithPretty(),\n")
11231111
}
@@ -1164,13 +1152,7 @@ var ConsoleToGo = []TranslateRule{
11641152
fmt.Fprint(&src, args)
11651153
}
11661154

1167-
var hasPretty bool
1168-
for k, _ := range params {
1169-
if k == "pretty" {
1170-
hasPretty = true
1171-
}
1172-
}
1173-
1155+
_, hasPretty := params["pretty"]
11741156
if !hasPretty {
11751157
src.WriteString("\tes.Count.WithPretty(),\n")
11761158
}

internal/build/cmd/generate/commands/gentests/generator.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,15 +1350,15 @@ func (g *Generator) genAction(a Action, skipBody ...bool) {
13501350
}
13511351

13521352
if name == "Authorization" {
1353-
auth_fields := strings.Split(value, " ")
1354-
auth_name := auth_fields[0]
1355-
auth_value := auth_fields[1]
1356-
if strings.HasPrefix(auth_value, "$") {
1357-
auth_value = `fmt.Sprintf("%s", stash["` + strings.ReplaceAll(strings.ReplaceAll(auth_value, "{", ""), "}", "") + `"])`
1353+
authFields := strings.Split(value, " ")
1354+
authName := authFields[0]
1355+
authValue := authFields[1]
1356+
if strings.HasPrefix(authValue, "$") {
1357+
authValue = `fmt.Sprintf("%s", stash["` + strings.ReplaceAll(strings.ReplaceAll(authValue, "{", ""), "}", "") + `"])`
13581358
} else {
1359-
auth_value = `"` + auth_value + `"`
1359+
authValue = `"` + authValue + `"`
13601360
}
1361-
g.w("\t\t\t" + `"Authorization": []string{"` + auth_name + ` " + ` + auth_value + `},` + "\n")
1361+
g.w("\t\t\t" + `"Authorization": []string{"` + authName + ` " + ` + authValue + `},` + "\n")
13621362

13631363
} else {
13641364
g.w("\t\t\t\"" + name + "\": []string{\"" + value + "\"},\n")

internal/build/cmd/generate/commands/gentests/model.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ func NewTestSuite(fpath string, payloads []TestPayload) TestSuite {
111111
}
112112

113113
for _, payload := range payloads {
114-
sec_keys := utils.MapKeys(payload.Payload)
114+
secKeys := utils.MapKeys(payload.Payload)
115115
switch {
116-
case len(sec_keys) > 0 && strings.Contains(strings.Join(sec_keys, ","), "setup") || strings.Contains(strings.Join(sec_keys, ","), "teardown"):
116+
case len(secKeys) > 0 && strings.Contains(strings.Join(secKeys, ","), "setup") || strings.Contains(strings.Join(secKeys, ","), "teardown"):
117117
for k, v := range payload.Payload.(map[interface{}]interface{}) {
118118
switch k {
119119
case "setup":
@@ -144,25 +144,25 @@ func NewTestSuite(fpath string, payloads []TestPayload) TestSuite {
144144
case "skip":
145145
var (
146146
ok bool
147-
skip_v string
148-
skip_r string
147+
skipV string
148+
skipR string
149149
)
150150

151151
skip := vv.(map[interface{}]interface{})["skip"]
152152

153-
if skip_v, ok = skip.(map[interface{}]interface{})["version"].(string); ok {
154-
if skip_rr, ok := skip.(map[interface{}]interface{})["reason"].(string); ok {
155-
skip_r = skip_rr
153+
if skipV, ok = skip.(map[interface{}]interface{})["version"].(string); ok {
154+
if skipRR, ok := skip.(map[interface{}]interface{})["reason"].(string); ok {
155+
skipR = skipRR
156156
}
157-
if skip_v == "all" {
157+
if skipV == "all" {
158158
t.Skip = true
159159
t.SkipInfo = "Skipping all versions"
160160
break
161161
}
162-
if ts.SkipEsVersion(skip_v) {
163-
// fmt.Printf("Skip: %q, EsVersion: %s, Skip: %v, Reason: %s\n", skip_v, EsVersion, ts.SkipEsVersion(skip_v), skip_r)
162+
if ts.SkipEsVersion(skipV) {
163+
// fmt.Printf("Skip: %q, EsVersion: %s, Skip: %v, Reason: %s\n", skipV, EsVersion, ts.SkipEsVersion(skipV), skipR)
164164
t.Skip = true
165-
t.SkipInfo = skip_r
165+
t.SkipInfo = skipR
166166
}
167167
}
168168
case "setup":

0 commit comments

Comments
 (0)