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

[RFC] hooks: add support for .test files and add some initial tests #110

Merged
merged 5 commits into from Jan 14, 2019

Conversation

mvo5
Copy link
Collaborator

@mvo5 mvo5 commented Jan 7, 2019

The current hooks do not have a good testing story. To fix this
this PR adds support for "hook/foo.test" files that will be run
at the end of the prime phase during the snap build.

It also adds two initial tests and converts the existing ABI test.
If this looks reasonable we can write tests for the remaining hooks
to ensure we do not regress again.

The current hooks do not have a good testing story. To fix this
this PR adds support for "hook/foo.test" files that will be run
at the end of the prime phase during the snap build.

It also adds two initial tests and converts the existing ABI test.
If this looks reasonable we can write tests for the remaining hooks
to ensure we do not regress again.
@mvo5 mvo5 changed the title hooks: add support for .test files and add some initial tests [RFC] hooks: add support for .test files and add some initial tests Jan 7, 2019
snapcraft.yaml Outdated
@@ -26,3 +26,5 @@ parts:
unset LD_LIBRARY_PATH;
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin";
snapcraftctl prime
# ensure buildin tests are run
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# ensure buildin tests are run
# ensure built-in tests are run

fi

if [ -s /etc/machine-id ]; then
echo "/etc/machine-id must exit but must be empty"
Copy link
Collaborator

@zyga zyga Jan 7, 2019

Choose a reason for hiding this comment

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

Suggested change
echo "/etc/machine-id must exit but must be empty"
echo "/etc/machine-id exists but must be empty"

fi

if [ ! -e /etc/machine-id ]; then
echo "/etc/machine-id must exit"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
echo "/etc/machine-id must exit"
echo "/etc/machine-id must exist"

README.md Outdated
are run inside the base image filesystem.

Each hook should have a matching `.test` file that validates that the
`.chroot` file works as expected. Those `.test` scripts will be run
Copy link

@pedronis pedronis Jan 7, 2019

Choose a reason for hiding this comment

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

it is not very clear from this description that these tests will be run after building with snapcraft, if I understand the travis.yml.

Also I wonder whether "sanity" or "check" would be a better name for them and this process.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I updated the documentation now. As for test vs check vs sanity I have no super strong opinion. Those are not tests in the traditional sense so a rename does make sense. I feel the upside of using tests is that people who write code may look for "tests" when wanting to write tests more readily than looking for check or sanity.

Copy link
Contributor

@sil2100 sil2100 left a comment

Choose a reason for hiding this comment

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

Ok, this looks fine (besides those small typos as highlighted by zyga).

Personally (that's just a preference though) I don't like the idea of having both the hooks and the tests in the same directory. It might get a bit confusing at first glance, since looking at the hooks/ directory you'll see files that are not actual hooks. What I would prefer personally is moving those tests to a separate hook-tests/ or similar directory, still following the same layout for running them as here.

But that's just my 5 cents.

@mvo5
Copy link
Collaborator Author

mvo5 commented Jan 14, 2019

@sil2100 Thank you! I moved the test files out now, the original "design" was inspired by go (which mixes source and test in a very similar way) but as foundations own this I'm fine accommodating your preferences :)

@mvo5 mvo5 force-pushed the more-tests branch 2 times, most recently from 6ff2911 to f786c48 Compare January 14, 2019 08:54
Only run hook tests when root otherwise the chroot to the prime
dir will not work.
@sil2100 sil2100 merged commit 4e4e7ae into snapcore:master Jan 14, 2019
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.

None yet

4 participants