Repository navigation
Reintroduce binary-based test coverage - #83
Conversation
…ormatting of commands
TopherGopher
left a comment
There was a problem hiding this comment.
The code itself looks pretty clean - the tests ran great. I'm signing off.
| // TestDevAddSites tests a `drud Dev add` on a wp site | ||
| func TestDevAddSites(t *testing.T) { | ||
| assert := assert.New(t) | ||
| for _, site := range DevTestSites { |
There was a problem hiding this comment.
I kind of suspect we'll want to have different devTestSites for different types of tests as time goes on, so would rather we parameterize tests than use globals. But it's working for now, so no biggie. Globals are really something we need to use a lot less than we do. They're so easy to use in golang that we forget how evil they are.
| args := []string{"start"} | ||
| out, err := system.RunCommand(DdevBin, args) | ||
| if err != nil { | ||
| log.Println("Error Output from ddev start:", out) |
There was a problem hiding this comment.
No need for change here, but this may be a case where we will probably want to exit on failure?
| if err != nil { | ||
| log.Println("Error Output from ddev start:", out) | ||
| } | ||
| assert.NoError(err) |
There was a problem hiding this comment.
Pretty sure this is too wordy, as we've already checked err. So either the assert can take the extra arg with the error, or the if statement can take care of everything? (I know I'm just reacting to things that were already there, but it shows as new change because of the file rename)
| o.ExpectedStatus = 200 | ||
| o.Timeout = 180 | ||
| o.Headers["Host"] = app.HostName() | ||
| err = network.EnsureHTTPStatus(o) |
There was a problem hiding this comment.
If we do this sort of thing very often (check for HTTP status with a timeout and a hostname) it should be refactored into a utility function.
|
|
||
| err = os.Chdir(testDir) | ||
| if err != nil { | ||
| t.Skip("Could not change to temporary directory %s: %v", testDir, err) |
There was a problem hiding this comment.
I don't think the response to not being able to make temp dir should probably be a test "skip", but OTOH it won't even happen, so no biggie.
| out, err := system.RunCommand(DdevBin, args) | ||
| assert.NoError(err) | ||
| assert.Contains(string(out), "Server started") | ||
| assert.Contains(string(out), "GET") |
There was a problem hiding this comment.
Just a note that wherever asserts are actually likely to fail, or where they fail in practice or in initial tests, it's super nice to add a message with more details about the failure. On most these asserts are simple enough and work fine, but in cases where we actually get failures it's really nice to add more explicit messages.
The Problem:
When removing the legacy plugin we also disabled many of our tests. With the work in #27 to create a local pluugin we're once again in a place that we can reintroduce the binary based testing method for the CLI
The Fix:
This PR resurrects most the tests that still apply. They are modified to use a working directory based approach and no longer require the sitename/siteenv arguments.
Automation Overview:
This is 100% automation. In particular, this re-adds binary based testing for the following
ddevcommandsThis also refactors the
testcommonpackage to support aTestSitestruct, which has the following methodsPrepare()Chdir()Cleanup()Both the binary tests and the local plugin tests now use that struct to track details about sites that are being tested.
Related Issue Link(s):
#27