Skip to content

Commit

Permalink
server_url template function: changed return value from string to *ur…
Browse files Browse the repository at this point in the history
…l.URL
  • Loading branch information
martinrode committed Jul 8, 2020
1 parent ec68634 commit 3a0c71c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ As an example, the URL _http://localhost/myimage.jpg_ would be changed into _htt
## server_url
**server_url** returns the configured server url (endpoint server), which can be globally provided in the yaml config file or directly by the command line parameter `--server`.
**server_url** returns the server url, which can be globally provided in the config file or directly by the command line parameter `--server`. This is a *url.URL.
# HTTP Server
Expand Down
18 changes: 4 additions & 14 deletions api_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewTestSuite(config TestToolConfig, manifestPath string, r *report.ReportEl
hsru := new(url.URL)
shsu := new(url.URL)
if httpServerReplaceHost != "" {
hsru, err = url.Parse("//"+httpServerReplaceHost)
hsru, err = url.Parse("//" + httpServerReplaceHost)
if err != nil {
return nil, errors.Wrap(err, "set http_server_host failed (command argument)")
}
Expand All @@ -113,7 +113,7 @@ func NewTestSuite(config TestToolConfig, manifestPath string, r *report.ReportEl
} else {
suitePreload.HTTPServerHost = "localhost"
}
if suite.HTTPServerHost== "0.0.0.0" {
if suite.HTTPServerHost == "0.0.0.0" {
suitePreload.HTTPServerHost = "localhost"
}
if hsru.Port() != "" {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (ats *Suite) parseAndRunTest(v interface{}, manifestDir, testFilePath strin
loader := template.NewLoader(ats.datastore)

loader.HTTPServerHost = ats.HTTPServerHost
serverURL, err := getURLWithoutAuth(ats.Config.ServerURL)
serverURL, err := url.Parse(ats.Config.ServerURL)
if err != nil {
logrus.Error(fmt.Errorf("can not load server url into test (%s): %s", testFilePath, err))
return false
Expand Down Expand Up @@ -343,7 +343,7 @@ func (ats *Suite) loadManifest() ([]byte, error) {
logrus.Tracef("Loading manifest: %s", ats.manifestPath)
loader := template.NewLoader(ats.datastore)
loader.HTTPServerHost = ats.HTTPServerHost
serverURL, err := getURLWithoutAuth(ats.Config.ServerURL)
serverURL, err := url.Parse(ats.Config.ServerURL)
if err != nil {
return nil, fmt.Errorf("can not load server url into manifest (%s): %s", ats.manifestPath, err)
}
Expand Down Expand Up @@ -386,13 +386,3 @@ func testGoRoutine(k, ki int, v json.RawMessage, ats *Suite, testFilePath, manif
<-waitCh
}
}

// getURLWithoutAuth helper
func getURLWithoutAuth(srcURL string) (string, error) {
parsedURL, err := url.Parse(srcURL)
if err != nil {
return "", err
}
parsedURL.User = nil
return parsedURL.String(), nil
}
4 changes: 2 additions & 2 deletions pkg/lib/template/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newTemplateParams(params []interface{}) (interface{}, error) {
type Loader struct {
datastore *datastore.Datastore
HTTPServerHost string
ServerURL string
ServerURL *url.URL
}

func NewLoader(datastore *datastore.Datastore) Loader {
Expand Down Expand Up @@ -300,7 +300,7 @@ func (loader *Loader) Render(
parsedURL.Host = loader.HTTPServerHost
return parsedURL.String(), nil
},
"server_url": func() string {
"server_url": func() *url.URL {
return loader.ServerURL
},
}
Expand Down

0 comments on commit 3a0c71c

Please sign in to comment.