Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TestWebserverType() #1154

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,27 +977,36 @@ func (app *DdevApp) GetAllURLs() []string {
URLs = append(URLs, "http://"+name+httpPort, "https://"+name+httpsPort)
}

URLs = append(URLs, app.GetWebContainerDirectURL())

return URLs
}

// GetWebContainerDirectURL returns the URL that can be used without the router to get to web container.
func (app *DdevApp) GetWebContainerDirectURL() string {
// Get direct address of web container
dockerIP, err := dockerutil.GetDockerIP()
if err != nil {
util.Error("Unable to get Docker IP: %v", err)
return URLs
util.Warning("Unable to get Docker IP: %v", err)
}
port, _ := app.GetWebContainerPublicPort()
return fmt.Sprintf("http://%s:%d", dockerIP, port)
}

// GetWebContainerPublicPort returns the direct-access public tcp port for http
func (app *DdevApp) GetWebContainerPublicPort() (int, error) {

webContainer, err := app.FindContainerByType("web")
if err != nil {
util.Error("Unable to find web container for app: %s, err %v", app.Name, err)
return URLs
return -1, fmt.Errorf("Unable to find web container for app: %s, err %v", app.Name, err)
}

for _, p := range webContainer.Ports {
if p.PrivatePort == 80 {
URLs = append(URLs, fmt.Sprintf("http://%s:%d", dockerIP, p.PublicPort))
break
return int(p.PublicPort), nil
}
}

return URLs
return -1, fmt.Errorf("No public port found for private port 80")
}

// HostName returns the hostname of a given application.
Expand Down
8 changes: 4 additions & 4 deletions pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1574,14 +1574,14 @@ func TestWebserverType(t *testing.T) {
assert.NoError(err)

// nolint: vetshadow
out, _, err := testcommon.GetLocalHTTPResponse(t, app.GetHTTPURL()+"/phpinfo.php")
out, resp, err := testcommon.GetLocalHTTPResponse(t, app.GetWebContainerDirectURL()+"/phpinfo.php")
assert.NoError(err)

expectedServerType := "Apache/2.4"
expectedServerType := "Apache/2"
if app.WebserverType == "nginx-fpm" {
expectedServerType = "nginx/1"
expectedServerType = "nginx"
}
//assert.Contains(resp.Header["Server"], expectedServerType, "Server header for project=%s, app.WebserverType=%s should be %s", app.Name, app.WebserverType, expectedServerType)
assert.Contains(resp.Header["Server"][0], expectedServerType, "Server header for project=%s, app.WebserverType=%s should be %s", app.Name, app.WebserverType, expectedServerType)
assert.Contains(out, "$_SERVER['SERVER_SOFTWARE']</td><td class=\"v\">"+expectedServerType, "For app.WebserverType=%s expected $_SERVER['SERVER_SOFTWARE'] to show %s", app.WebserverType, expectedServerType)

}
Expand Down