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

Add infrastructure for running unit tests #19

Merged
merged 3 commits into from
Mar 22, 2016

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Mar 21, 2016

There haven’t been any unit tests in the code base so far; after adding them,

  • Just running them is more difficult than go test ., so Makefile targets are useful.
  • A full test run (Docker,Travis,non-Docker) now means validate+unit+integration tests, and it is easy to forget one or more; so, this adds new all-in-one Makefile targets.
  • Travis should run the unit tests; by using the all-in-one target we get this for free.
  • IDEs should be able to run the tests; this adds a demo for VS Code

The VS Code aspect is honestly a bit dubious; I’ll gladly drop it if you think it does not belong upstream.

@runcom
Copy link
Member

runcom commented Mar 22, 2016

The VS Code aspect is honestly a bit dubious; I’ll gladly drop it if you think it does not belong upstream.

honestly I don't believe, as you, this belongs upstream, I'll merge after you drop it
Thanks @mtrmac

@mtrmac
Copy link
Collaborator Author

mtrmac commented Mar 22, 2016

VS Code commit dropped.

@@ -20,6 +20,8 @@ ifeq ($(INTERACTIVE), 1)
DOCKER_FLAGS += -t
endif
DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
# Use =, not :=, so that this is not expanded when we are not running unit tests.
UNIT_TEST_PACKAGES = $(shell find -name '*_test.go' | sed 's,/[^/]*$$,,' | sort -u | grep -v '^\./\(integration\|vendor\)$$')
Copy link
Member

Choose a reason for hiding this comment

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

should go list ./... take care of this filtering?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • go list ./... does not automatically filter integration and vendor subdirectories; are you saying that should somehow happen?
  • go list lists all packages; this only finds packages which contain tests. I am unsure about which is better; go list causes ? $package_name [no test files] lines to be output, arguably both useful and useless. Right now the find -name '*.test.go' variant means $(UNIT_TEST_PACKAGES) is empty and make test-unit does not even start the container, but this difference will go away with the first added unit test.

Copy link
Member

Choose a reason for hiding this comment

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

go list ./... does not automatically filter integration and vendor subdirectories; are you saying that should somehow happen?

Nope
go list ./... | grep -v ^vendor/|integration/ (or something like this)

go list lists all packages; this only finds packages which contain tests. I am unsure about which is better; go list causes ? $package_name [no test files] lines to be output, arguably both useful and useless. Right now the find -name '*.test.go' variant means $(UNIT_TEST_PACKAGES) is empty and make test-unit does not even start the container, but this difference will go away with the first added unit test.

I'm ok with the "no tests found" line (cause somehow helps figuring instantly when running tests coverage)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Getting go list to work was surprisingly non-trivial (e.g. it doesn't work within sudo when GOPATH is not set), but it allowed to drop the "empty package list" case and generally simplified the Makefile.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

unfortunately anything dealing with sudo and env variables is fine with go :(

Running unit tests without the integration tests is non-trivial, so add
a Makefile target to help with this.
- (make check): GNU coding standards-compliant primary entry point,
  running all available tests in the best environment (i.e. Docker
  container).
- (make test-all-local): Local entry point, running only tests
  which do not require a special environment; intended for IDE
  integration and quick turnaround cycles.

Also modifies the Travis configuration to run (make check), to prevent
duplication.
@runcom
Copy link
Member

runcom commented Mar 22, 2016

LGTM

runcom added a commit that referenced this pull request Mar 22, 2016
Add infrastructure for running unit tests
@runcom runcom merged commit ffcb8f8 into containers:master Mar 22, 2016
@mtrmac mtrmac deleted the unit-tests branch March 22, 2016 13:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants