Skip to content

Commit

Permalink
tgly double loading for including http server host replacement in man…
Browse files Browse the repository at this point in the history
…ifest.json files
  • Loading branch information
ugarcia committed Jun 18, 2020
1 parent e5d5eab commit d4b6ac0
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions api_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ func NewTestSuite(config TestToolConfig, manifestPath string, r *report.ReportEl
datastore: datastore,
index: index,
}
suitePreload := Suite{
Config: config,
manifestDir: filepath.Dir(manifestPath),
manifestPath: manifestPath,
reporterRoot: r,
datastore: datastore,
index: index,
}

manifest, err := suite.loadManifest()
manifest, err := suitePreload.loadManifest()
if err != nil {
err = fmt.Errorf("error loading manifest: %s", err)
suite.reporterRoot.Failure = fmt.Sprintf("%s", err)
return &suite, err
suitePreload.reporterRoot.Failure = fmt.Sprintf("%s", err)
return &suitePreload, err
}

err = cjson.Unmarshal(manifest, &suite)
err = cjson.Unmarshal(manifest, &suitePreload)
if err != nil {
err = fmt.Errorf("error unmarshaling manifest '%s': %s", manifestPath, err)
suite.reporterRoot.Failure = fmt.Sprintf("%s", err)
return &suite, err
suitePreload.reporterRoot.Failure = fmt.Sprintf("%s", err)
return &suitePreload, err
}

// Add external http server url here, as only after this point the http_server.addr may be available
Expand All @@ -83,30 +91,45 @@ func NewTestSuite(config TestToolConfig, manifestPath string, r *report.ReportEl
return nil, errors.Wrap(err, "set http_server_host failed (command argument)")
}
}
if suite.HttpServer != nil && suite.HttpServer.Addr != "" {
if suitePreload.HttpServer != nil && suitePreload.HttpServer.Addr != "" {
// We need to append it as the golang URL parser is not smart enough to differenciate between hostname and protocol
shsu, err = url.Parse("//" + suite.HttpServer.Addr)
shsu, err = url.Parse("//" + suitePreload.HttpServer.Addr)
if err != nil {
return nil, errors.Wrap(err, "set http_server_host failed (manifesr addr)")
}
}
suite.HTTPServerHost = ""
suitePreload.HTTPServerHost = ""
if hsru.Hostname() != "" {
suite.HTTPServerHost = hsru.Hostname()
suitePreload.HTTPServerHost = hsru.Hostname()
} else if shsu.Hostname() != "" {
suite.HTTPServerHost = shsu.Hostname()
suitePreload.HTTPServerHost = shsu.Hostname()
} else {
suite.HTTPServerHost = "localhost"
suitePreload.HTTPServerHost = "localhost"
}
if suite.HTTPServerHost== "0.0.0.0" {
suite.HTTPServerHost = "localhost"
suitePreload.HTTPServerHost = "localhost"
}
if hsru.Port() != "" {
suite.HTTPServerHost += ":" + hsru.Port()
suitePreload.HTTPServerHost += ":" + hsru.Port()
} else if shsu.Port() != "" {
suite.HTTPServerHost += ":" + shsu.Port()
suitePreload.HTTPServerHost += ":" + shsu.Port()
}

manifest, err = suitePreload.loadManifest()
if err != nil {
err = fmt.Errorf("error loading manifest: %s", err)
suite.reporterRoot.Failure = fmt.Sprintf("%s", err)
return &suite, err
}
// fmt.Printf("%s", string(manifest))
err = cjson.Unmarshal(manifest, &suite)
if err != nil {
err = fmt.Errorf("error unmarshaling manifest '%s': %s", manifestPath, err)
suite.reporterRoot.Failure = fmt.Sprintf("%s", err)
return &suite, err
}
suite.HTTPServerHost = suitePreload.HTTPServerHost

//Append suite manifest path to name, so we know in an automatic setup where the test is loaded from
suite.Name = fmt.Sprintf("%s (%s)", suite.Name, manifestPath)

Expand Down Expand Up @@ -306,6 +329,9 @@ func (ats *Suite) loadManifest() ([]byte, error) {
var res []byte
logrus.Tracef("Loading manifest: %s", ats.manifestPath)
loader := template.NewLoader(ats.datastore)
if ats.HTTPServerHost != "" {
loader.HTTPServerHost = ats.HTTPServerHost
}
manifestFile, err := filesystem.Fs.Open(ats.manifestPath)
if err != nil {
return res, fmt.Errorf("error opening manifestPath (%s): %s", ats.manifestPath, err)
Expand Down

0 comments on commit d4b6ac0

Please sign in to comment.