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

Generate coverage statistics for integration tests #767

Merged
merged 5 commits into from
May 8, 2019

Conversation

efekarakus
Copy link
Contributor

Description of changes: make integ-test now outputs our code coverage. For example, the fargate tutorial e2e test covers 29.2% of our statements.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing

  • Unit tests passed
  • Integration tests passed
  • [N/A] Unit tests added for new functionality
  • Listed manual checks and their outputs in the comments (example)
  • [N/A] Link to issue or PR for the integration tests:

Documentation

  • [N/A] Contacted our doc writer
  • [N/A] Updated our README

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@efekarakus
Copy link
Contributor Author

Sample output from CodeBuild: https://gist.github.com/efekarakus/db0faa4bd48b6acb395280b8f3c23016

go test -tags integ ./ecs-cli/integ/e2e/...

.PHONY: integ-test-run-with-coverage
integ-test-run-with-coverage: integ-test-run
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my own understanding... what this is technically doing is just processing the coverage report produced by integ-test-build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add these explanations into our Makefile as comments:

  • integ-test-build builds a test binary called ecs-cli.test. This binary is the same as regular ecs-cli but it additionally gives coverage stats to stdout after each execution.
  • integ-test-run runs our integration tests using the ecs-cli.test binary.
  • integ-test-run-with-coverage first runs integ-test-run and merges all the coverage files for each command in the e2e tests into 1 file. After merging them all in 1 file, we can get the full coverage stats for our tests.

Does that help?

@@ -177,6 +176,7 @@ func testServiceHasAllRunningContainers(t *testing.T, p *Project, wantedNumOfCon

// Then
lines := strings.Split(string(out), "\n")
lines = lines[:len(lines)-3] // remove coverage metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

Dumb question: How come this is only needed in the compose command?

Minor nit: 3 feels like magic number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great question :) You're right this information should be redacted from all other commands. The other tests only search if substrings are contained in the command's output. So the tests never broke.

However, for ecs-cli compose service ps we have to parse the output properly to count the number of running containers so I had to modify this function.

I moved this logic to a new function Lines() in stdout.go. This way any test that cares about individual lines can use that function.

return exec.Command(cmdPath, args...)
}

// createTempCoverageFile creates a coverage file for a CLI command under $TMPDIR.
Copy link
Contributor

@allisaurus allisaurus May 1, 2019

Choose a reason for hiding this comment

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

is $TMPDIR an env set by ioutil or something we set explicitly elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's set by default depending on your OS.
ioutil refers to the tempDir() function in the end to figure out the location of your tmp directory.

For CodeBuild, I had to add the env variable TMPDIR that's set to /tmp. I added a new section in the README to set this variable locally if your environment doesn't set it.

imageCommand "github.com/aws/amazon-ecs-cli/ecs-cli/modules/commands/image"
licenseCommand "github.com/aws/amazon-ecs-cli/ecs-cli/modules/commands/license"
logsCommand "github.com/aws/amazon-ecs-cli/ecs-cli/modules/commands/log"
regcredsCommand "github.com/aws/amazon-ecs-cli/ecs-cli/modules/commands/regcreds"
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like these import aliases ("regcredsCommand", etc.) are new, but references to them later in the file (e.g., lines 70-82) appear unchanged. Were these updating previously somehow? Wondering how these and their usages could be updated separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we didn't run goimports on this file before.

So I when I made modifications to this file, it automatically restructured our imports :/
I think it's fine to keep it as is instead of reverting to the previous look since we want to use goimports.

@@ -0,0 +1,28 @@
// +build testrunmain

// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

update year to 2019

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@efekarakus
Copy link
Contributor Author

Coverage increased to 38.4% from 29.4% after adding the ec2 task integ test.

@efekarakus efekarakus merged commit 479a3d0 into aws:dev May 8, 2019
@efekarakus efekarakus deleted the integ-tests/binary branch June 6, 2019 18:44
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.

3 participants