Skip to content

Commit

Permalink
Minor test improvements (tests only) (#2771)
Browse files Browse the repository at this point in the history
* Use default (longer timeout) for a few instances of GetLocalHTTPResponse()
* Turn off TestShareCmd for Windows
* Try to stabilize TestHttpsRedirection
* Try to improve TestHttpsRedirection
  • Loading branch information
rfay committed Feb 3, 2021
1 parent a205053 commit 4a0767a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cmd/ddev/cmd/share_test.go
Expand Up @@ -17,6 +17,9 @@ import (

// TestShareCmd tests `ddev share`
func TestShareCmd(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping because unreliable on Windows due to DNS lookup failure")
}
assert := asrt.New(t)
urlRead := false

Expand Down
4 changes: 2 additions & 2 deletions pkg/ddevapp/config_test.go
Expand Up @@ -620,9 +620,9 @@ func TestConfigValidate(t *testing.T) {
err = app.Start()
assert.NoError(err)
staticURI := site.Safe200URIWithExpectation.URI
_, _, err = testcommon.GetLocalHTTPResponse(t, "http://x.ddev.site/"+staticURI, 1)
_, _, err = testcommon.GetLocalHTTPResponse(t, "http://x.ddev.site/"+staticURI)
assert.NoError(err)
_, _, err = testcommon.GetLocalHTTPResponse(t, "http://somethjingrandom.any.ddev.site/"+staticURI, 1)
_, _, err = testcommon.GetLocalHTTPResponse(t, "http://somethjingrandom.any.ddev.site/"+staticURI)
assert.NoError(err)

// Make sure that a bare "*" in the additional_hostnames does *not* work
Expand Down
18 changes: 12 additions & 6 deletions pkg/ddevapp/ddevapp_test.go
Expand Up @@ -741,7 +741,7 @@ func TestDdevXdebugEnabled(t *testing.T) {
}

// Curl to the project's index.php or anything else
_, _, _ = testcommon.GetLocalHTTPResponse(t, app.GetHTTPURL(), 1)
_, _, _ = testcommon.GetLocalHTTPResponse(t, app.GetHTTPURL())

fmt.Printf("Attempting accept of port 9000 with xdebug enabled, XDebug version=%s\n", v)

Expand Down Expand Up @@ -2628,7 +2628,6 @@ func TestHttpsRedirection(t *testing.T) {
packageDir, _ := os.Getwd()

testDir := testcommon.CreateTmpDir(t.Name())
defer testcommon.CleanupDir(testDir)
appDir := filepath.Join(testDir, t.Name())
err := fileutil.CopyDir(filepath.Join(packageDir, "testdata", t.Name()), appDir)
assert.NoError(err)
Expand All @@ -2639,8 +2638,15 @@ func TestHttpsRedirection(t *testing.T) {
assert.NoError(err)

_ = app.Stop(true, false)
//nolint: errcheck
defer app.Stop(true, false)

t.Cleanup(func() {
err = app.Stop(true, false)
assert.NoError(err)
err = os.Chdir(packageDir)
assert.NoError(err)
err = os.RemoveAll(testDir)
assert.NoError(err)
})

expectations := []URLRedirectExpectations{
{"https", "/subdir", "/subdir/"},
Expand Down Expand Up @@ -2672,7 +2678,7 @@ func TestHttpsRedirection(t *testing.T) {
// Do a start on the configured site.
app, err = ddevapp.GetActiveApp("")
assert.NoError(err)
startErr := app.Start()
startErr := app.StartAndWait(5)
assert.NoError(startErr, "app.Start() failed with projectType=%s, webserverType=%s", projectType, webserverType)
if startErr != nil {
appLogs, getLogsErr := ddevapp.GetErrLogsFromApp(app, startErr)
Expand All @@ -2684,7 +2690,7 @@ func TestHttpsRedirection(t *testing.T) {
reqURL := parts.scheme + "://" + strings.ToLower(app.GetHostname()) + parts.uri
//t.Logf("TestHttpsRedirection trying URL %s with webserver_type=%s", reqURL, webserverType)
out, resp, err := testcommon.GetLocalHTTPResponse(t, reqURL)
assert.NotNil(resp, "resp was nil for projectType=%s webserver_type=%s url=%s, err=%v, out='%s'", projectType, webserverType, reqURL, err, out)
require.NotNil(t, resp, "resp was nil for projectType=%s webserver_type=%s url=%s, err=%v, out='%s'", projectType, webserverType, reqURL, err, out)
if resp != nil {
locHeader := resp.Header.Get("Location")

Expand Down

0 comments on commit 4a0767a

Please sign in to comment.