Skip to content

Reintroduce binary-based test coverage - #83

Merged
beeradb merged 16 commits into
ddev:masterfrom
beeradb:test-recovery
Mar 22, 2017
Merged

beeradb merged 16 commits into
ddev:masterfrom
beeradb:test-recovery

Conversation

@beeradb

@beeradb beeradb commented Mar 20, 2017 •

Copy link
Copy Markdown
Contributor

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 ddev commands

  • start
  • rm
  • restart
  • logs
  • exec
  • list

This also refactors the testcommon package to support a TestSite struct, which has the following methods

  • Prepare()
  • 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

@beeradb beeradb mentioned this pull request Mar 21, 2017
7 tasks done

@TopherGopher TopherGopher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code itself looks pretty clean - the tests ran great. I'm signing off.

@beeradb
beeradb merged commit 8aa82da into ddev:master Mar 22, 2017
// TestDevAddSites tests a `drud Dev add` on a wp site
func TestDevAddSites(t *testing.T) {
assert := assert.New(t)
for _, site := range DevTestSites {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmd/ddev/cmd/logs_test.go

err = os.Chdir(testDir)
if err != nil {
t.Skip("Could not change to temporary directory %s: %v", testDir, err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmd/ddev/cmd/logs_test.go
out, err := system.RunCommand(DdevBin, args)
assert.NoError(err)
assert.Contains(string(out), "Server started")
assert.Contains(string(out), "GET")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the great work on this @beeradb , getting these back. It looks great to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants