Skip to content

Commit

Permalink
Update variable names to Go convention + Simplify map lookups (#894)
Browse files Browse the repository at this point in the history
* Update variable names to Go convention

* Update translator.go

* Update translator.go
  • Loading branch information
HaraldNordgren authored Aug 2, 2024
1 parent 7e09ba4 commit 20b86e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
24 changes: 3 additions & 21 deletions internal/build/cmd/generate/commands/genexamples/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,13 +1058,7 @@ var ConsoleToGo = []TranslateRule{
fmt.Fprint(&src, args)
}

var hasPretty bool
for k, _ := range params {
if k == "pretty" {
hasPretty = true
}
}

_, hasPretty := params["pretty"]
if !hasPretty {
src.WriteString("\tes.Scroll.WithPretty(),\n")
}
Expand Down Expand Up @@ -1111,13 +1105,7 @@ var ConsoleToGo = []TranslateRule{
fmt.Fprint(&src, args)
}

var hasPretty bool
for k, _ := range params {
if k == "pretty" {
hasPretty = true
}
}

_, hasPretty := params["pretty"]
if !hasPretty {
src.WriteString("\tes.Search.WithPretty(),\n")
}
Expand Down Expand Up @@ -1164,13 +1152,7 @@ var ConsoleToGo = []TranslateRule{
fmt.Fprint(&src, args)
}

var hasPretty bool
for k, _ := range params {
if k == "pretty" {
hasPretty = true
}
}

_, hasPretty := params["pretty"]
if !hasPretty {
src.WriteString("\tes.Count.WithPretty(),\n")
}
Expand Down
14 changes: 7 additions & 7 deletions internal/build/cmd/generate/commands/gentests/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1350,15 +1350,15 @@ func (g *Generator) genAction(a Action, skipBody ...bool) {
}

if name == "Authorization" {
auth_fields := strings.Split(value, " ")
auth_name := auth_fields[0]
auth_value := auth_fields[1]
if strings.HasPrefix(auth_value, "$") {
auth_value = `fmt.Sprintf("%s", stash["` + strings.ReplaceAll(strings.ReplaceAll(auth_value, "{", ""), "}", "") + `"])`
authFields := strings.Split(value, " ")
authName := authFields[0]
authValue := authFields[1]
if strings.HasPrefix(authValue, "$") {
authValue = `fmt.Sprintf("%s", stash["` + strings.ReplaceAll(strings.ReplaceAll(authValue, "{", ""), "}", "") + `"])`
} else {
auth_value = `"` + auth_value + `"`
authValue = `"` + authValue + `"`
}
g.w("\t\t\t" + `"Authorization": []string{"` + auth_name + ` " + ` + auth_value + `},` + "\n")
g.w("\t\t\t" + `"Authorization": []string{"` + authName + ` " + ` + authValue + `},` + "\n")

} else {
g.w("\t\t\t\"" + name + "\": []string{\"" + value + "\"},\n")
Expand Down
22 changes: 11 additions & 11 deletions internal/build/cmd/generate/commands/gentests/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func NewTestSuite(fpath string, payloads []TestPayload) TestSuite {
}

for _, payload := range payloads {
sec_keys := utils.MapKeys(payload.Payload)
secKeys := utils.MapKeys(payload.Payload)
switch {
case len(sec_keys) > 0 && strings.Contains(strings.Join(sec_keys, ","), "setup") || strings.Contains(strings.Join(sec_keys, ","), "teardown"):
case len(secKeys) > 0 && strings.Contains(strings.Join(secKeys, ","), "setup") || strings.Contains(strings.Join(secKeys, ","), "teardown"):
for k, v := range payload.Payload.(map[interface{}]interface{}) {
switch k {
case "setup":
Expand Down Expand Up @@ -144,25 +144,25 @@ func NewTestSuite(fpath string, payloads []TestPayload) TestSuite {
case "skip":
var (
ok bool
skip_v string
skip_r string
skipV string
skipR string
)

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

if skip_v, ok = skip.(map[interface{}]interface{})["version"].(string); ok {
if skip_rr, ok := skip.(map[interface{}]interface{})["reason"].(string); ok {
skip_r = skip_rr
if skipV, ok = skip.(map[interface{}]interface{})["version"].(string); ok {
if skipRR, ok := skip.(map[interface{}]interface{})["reason"].(string); ok {
skipR = skipRR
}
if skip_v == "all" {
if skipV == "all" {
t.Skip = true
t.SkipInfo = "Skipping all versions"
break
}
if ts.SkipEsVersion(skip_v) {
// fmt.Printf("Skip: %q, EsVersion: %s, Skip: %v, Reason: %s\n", skip_v, EsVersion, ts.SkipEsVersion(skip_v), skip_r)
if ts.SkipEsVersion(skipV) {
// fmt.Printf("Skip: %q, EsVersion: %s, Skip: %v, Reason: %s\n", skipV, EsVersion, ts.SkipEsVersion(skipV), skipR)
t.Skip = true
t.SkipInfo = skip_r
t.SkipInfo = skipR
}
}
case "setup":
Expand Down

0 comments on commit 20b86e8

Please sign in to comment.