Skip to content

Commit

Permalink
Update how template variable replacement takes place on each test's r…
Browse files Browse the repository at this point in the history
…equest URL before the request is made (#22)
  • Loading branch information
kkajla12 authored Apr 6, 2023
1 parent de5959e commit 68259f4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ func (suite TestSuite) executeTest(test TestSpec, extractedFields map[string]str
if test.Request.BaseUrl != "" {
baseUrl = test.Request.BaseUrl
}
requestUrlParts := strings.Split(test.Request.Url, "/")
var requestUrl string
for _, part := range requestUrlParts {
if part != "" {
requestUrl += "/" + getTemplateValIfPresent(part, extractedFields)
}

// Replace any template variables in test's request url with the appropriate value
requestUrl := test.Request.Url
templateVariableRegex := regexp.MustCompile(`{{\s*[a-zA-Z0-9\.]+\s*}}`)
templateVariables := templateVariableRegex.FindAll([]byte(requestUrl), -1)
for _, templateVariable := range templateVariables {
templateVal := getTemplateValIfPresent(string(templateVariable), extractedFields)
requestUrl = strings.Replace(requestUrl, string(templateVariable), templateVal, -1)
}

req, err := http.NewRequest(test.Request.Method, baseUrl+requestUrl, requestBody)
if err != nil {
testErrors = append(testErrors, fmt.Sprintf("Unable to create request: %v", err))
Expand Down

0 comments on commit 68259f4

Please sign in to comment.