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 script to start docker container with db for unit tests #3434

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ameowlia
Copy link
Member

I don't work on a machine that has a local DB. When I started working on readiness healthcheck stuff I spent 2+ hours just trying to get one setup. In the end, I made this script from a similar one in cf-networking-release. I don't promise that it works for every CAPI use case (it only works with postgres for example), but it works great for when a new person wants to run some tests and iterate quickly.

To use, run: ./scripts/docker-shell-with-started-db

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

I don't work on a machine that has a local DB. When I started working on
readiness healthcheck stuff I spent 2+ hours just trying to get one
setup. In the end, I made this script from a similar one in
cf-networking-release. I don't promise that it works for every CAPI use
case (it only works with postgres for example), but it works great for
when a new person wants to run some tests and iterate quickly.

To use, run: `./scripts/docker-shell-with-started-db`
@philippthun
Copy link
Member

Thanks @ameowlia for your PR. It's always good to lower the entry barrier for new contributors.

Why did you decide to run rake db:create (and also the tests) inside the container? I would prefer an even simpler setup, i.e. docker container with database and everything else done from the outside.

We also have a local setup with multiple containers that @FloThinksPi converted into a Codespace (see #2881). Did you had a chance to try out this setup?

@ameowlia
Copy link
Member Author

👋 Hi @philippthun, thanks for the response.

Why did you decide to run rake db:create (and also the tests) inside the container? I would prefer an even simpler setup, i.e. docker container with database and everything else done from the outside.

This is the pattern we follow for the runtime components. That way someone can run the tests without having anything but docker setup on their machine. Though I can understand your preference.

We also have a local setup with multiple containers that @FloThinksPi converted into a Codespace (see #2881). Did you had a chance to try out this setup?

Thank you for the pointer to this. I didn't see this before. I've never used codespaces before. I am curious to see if it works without an IDE since my team develops entirely in vim on gcp vms.

Feel free to close this issue if this testing patterns isn't one you want to endorse.

@FloThinksPi
Copy link
Member

FloThinksPi commented Sep 29, 2023

@ameowlia The setup we added work both as a github codespace and also localy by calling e.g. ./devenv.sh create on your machine. Prerequsits and more details are available in the Readme: https://github.com/cloudfoundry/cloud_controller_ng#predefined-development-environment

Happy to hear if this setup supports you working mode :)

jrussett and others added 2 commits October 19, 2023 20:32
Signed-off-by: Geoff Franks <gfranks@vmware.com>
Co-authored-by: Geoff Franks <gfranks@vmware.com>
@@ -116,6 +116,14 @@ keep it up to date, documenting the purpose of the various types of tests.

By default `rspec` will randomly pick between postgres and mysql.

#### Running the Units Tests in Docker

If you don't want to set up a up a test DB locally, you can run
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If you don't want to set up a up a test DB locally, you can run
If you don't want to set up a test DB locally, you can run

if [ "${db}" = "postgres" ]; then
launchDB="(/postgres-entrypoint.sh postgres &> /var/log/postgres-boot.log) &"
testConnection="psql -h localhost -U postgres -c '\conninfo'"
elif [ "${db}" = "mysql" ] || [ "${db}" = "mysql-5.6" ] || [ "${db}" = "mysql8" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

In scripts/docker-shell-with-started-db the db variable will be set to mysql if e.g. DB=mysql8; so the two ORs are not needed.

}

cd /cloud_controller_ng
export GOPATH=$PWD
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? We don't have Golang code...

#### Running the Units Tests in Docker

If you don't want to set up a up a test DB locally, you can run
`./scripts/start-db-in-docker.sh`. This script will start a docker container
Copy link
Member

Choose a reason for hiding this comment

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

You run scripts/docker-shell-with-started-db from the command line, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants