docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

feat: Add back BATS for testing images

Open MasonM opened this issue 4 years ago • 5 comments

Description

BATS was initially added to this repository in https://github.com/nodejs/docker-node/pull/802, but was then removed in https://github.com/nodejs/docker-node/pull/1339. This adds it back, and hooks it up to Github Actions.

This also fixes #1583, which happened due to a bug in the "Build image" step: the build context was set to the root project directory, which meant the COPY docker-entrypoint.sh /usr/local/bin/ instruction was copying the base docker-entrypoint.sh file into the Docker image instead of the one in the variant directory. Changing the context to the variant directory solves that.

Motivation and Context

https://github.com/nodejs/docker-node/pull/1579#issuecomment-947302579

Testing Details

Link to run for this PR: https://github.com/nodejs/docker-node/actions/runs/1374569169

Example Output(if appropriate)

N/A

Types of changes

  • [ ] Documentation
  • [ ] Version change (Update, remove or add more Node.js versions)
  • [ ] Variant change (Update, remove or add more variants, or versions of variants)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [X] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Others (non of above)

Checklist

  • [X] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [X] I have read the CONTRIBUTING.md document.
  • [X] All new and existing tests passed.

MasonM avatar Oct 21 '21 03:10 MasonM

@nschonni

If we do add it back, I think using the old install apt-install method would be better than a submodule.

Unfortunately, the version of "bats" in Ubuntu 20.04 is quite old and lacks support for the --verbose-run flag. I'm using that flag in this PR because it makes it easier to debug. This is one way BATS is superior to the old method: when tests fail, it clearly shows the expected output and the actual output, without any extra work.

I guess I could have Github Actions download the BATS source with curl and extract it, like this: https://github.com/hyperupcall/basalt/blob/d60b8a101ed3d9c2bb3cf6ae27286d944d03779c/.github/workflows/ci.yml#L35-L42

But that's more complicated than using a submodule.

MasonM avatar Oct 28 '21 20:10 MasonM

I think using a submodule makes sense since that's what the official docs recommend: https://bats-core.readthedocs.io/en/stable/tutorial.html#quick-installation.

I know I suggested it in https://github.com/nodejs/docker-node/pull/1588#discussion_r734280534, but since it has no dependencies we could also just run it through npm exec. As long as we specify a version I don't see any security risk. It is up to date with 1.6.0 released 4 days ago, and maintained by the same person (I assume it's auto-published somehow, haven't dug into i)

SimenB avatar Feb 28 '22 14:02 SimenB

@SimenB Okay, I removed the submodule and changed it to use npx [email protected] instead.

MasonM avatar Mar 01 '22 05:03 MasonM

Is this still pending another review?

chorrell avatar Aug 16 '22 18:08 chorrell

I would like one 😀

SimenB avatar Aug 17 '22 07:08 SimenB