Skip to content

Conversation

sublimino
Copy link
Member

It should be noted that the tests fail when run in the manner suggested in this help guide.

docker run -it \
  -v $(pwd)/test:/test \
  bats:latest \
  /test

I believe that this should be a valid use case for testing, and that
this will be solved by resolving the bats directory and support files as
per the issues under discussion in #91

Once this is merged I'll paste it into the GitHub wiki, or remove it from this tree - would just like it to be reviewed first.

closes #30

It should be noted that the tests fail when run in the manner suggested:

```bash
docker run -it \
  -v $(pwd)/test:/test \
  bats:latest \
  /test
```

I believe that this should be a valid use case for testing, and that
this will be solved by resolving the bats directory and support files as
per the issues under discussion in bats-core#91
@sublimino sublimino requested a review from a team as a code owner June 8, 2018 14:40
@ghost ghost assigned sublimino Jun 8, 2018
@ghost ghost added the review label Jun 8, 2018
Copy link
Contributor

@mbland mbland left a comment

Choose a reason for hiding this comment

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

Also, can you move this to the docs/ directory instead? (Moving files in there as part of #92 as well, per #95.)

wiki/usage.md Outdated
$ docker run -it bats:latest --tap /opt/bats/test
```

To mount your tests into the container, first built the image as above. Then:
Copy link
Contributor

Choose a reason for hiding this comment

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

"built" => "build"

wiki/usage.md Outdated
```bash
$ docker run -v $(pwd)/test:/test bats /test
```
This has run the `test/` directory from the bats-core repository inside the bats Docker container.
Copy link
Contributor

Choose a reason for hiding this comment

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

"has run" => "runs"

wiki/usage.md Outdated

To mount your tests into the container, first built the image as above. Then:
```bash
$ docker run -v $(pwd)/test:/test bats /test
Copy link
Contributor

Choose a reason for hiding this comment

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

As noted in #93, this should be something like:

docker run -it -v $(pwd):/opt/bats-dev bats:latest /opt/bats-dev/test

Copy link
Contributor

Choose a reason for hiding this comment

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

I take this back slightly; the /opt/bats-dev dir should be /opt/bats, i.e.:

docker run -it -v $(pwd):/opt/bats bats:latest /opt/bats/test

And I'm suddenly finding this command extremely useful. 🙂

wiki/usage.md Outdated
```bash
$ docker run -v $(pwd)/test:/test bats /test
$ docker run -it -v $(pwd):/opt/bats bats:latest /opt/bats/test
```
This has run the `test/` directory from the bats-core repository inside the bats Docker container.
Copy link
Contributor

Choose a reason for hiding this comment

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

This "has run" still reads funny.

wiki/usage.md Outdated
```
This has run the `test/` directory from the bats-core repository inside the bats Docker container.


Or for test files without any dependencies:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand now what you're saying... It would help to explain some more, something like: "For test suites that are intended to run in isolation from the project (i.e. no tests depend on project files outside of the test directory), you can mount the test directory in isolation and execute them like so:"

@sublimino
Copy link
Member Author

Thanks for the reviews on this @mbland

wiki/usage.md Outdated

For test suites that are intended to run in isolation from the project (i.e. tests do not depend on project files outside of the test directory), you can mount the test directory by iteself and execute the tests like so:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "iteself" => "itself"

Copy link
Member Author

Choose a reason for hiding this comment

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

D'oh

wiki/usage.md Outdated

Or for test files without any dependencies:
```bash
$ docker run -v $(pwd)/test:/test bats /test
Copy link
Contributor

Choose a reason for hiding this comment

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

Two nits, one substantial comment.

I'd prefer -v "$PWD:/opt/bats" (including double quotes). Though it doesn't matter in terms of performance, it seems folks aren't aware that in Bash, many times you can use $PWD where you would commonly use $(pwd), so I like to promote its use.

Should bats be bats:latest?

Finally, I don't think -it is necessary for any of these commands. If you agree, mind not only updating this document, but the .travis.yml command?

Copy link
Member Author

Choose a reason for hiding this comment

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

$PWD - good point!

bats and bats:latest are equivalent, but probably more obvious the include the tag. Will update.

-i is useful to kill hanging processes (otherwise has to be done via docker stop command), and -t to simulate a tty (often not used, but most similar to most test runs). Former important to a user, not a build, and latter probably the inverse. Everything's least-surprising to a new Docker use if both are used I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh...that makes perfect sense re: -it. Thanks for educating me!

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh all good 🙏

@sublimino
Copy link
Member Author

Further changes pushed @mbland

@mbland
Copy link
Contributor

mbland commented Jun 11, 2018

So I've approved, but will leave merging up to you, since it seemed you weren't sure you wanted to add this to the repo or just port it to the wiki.

One more thing up to you: Want to add -it to that last command, and maybe even the explanation you gave me?

@mbland
Copy link
Contributor

mbland commented Jun 11, 2018

Nice! Approval stands. Again I'll leave it up to you whether to merge or not.

@sublimino sublimino merged commit 6ce7237 into bats-core:master Jun 11, 2018
@ghost ghost removed the review label Jun 11, 2018
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.

Write up Docker usage guide
2 participants