Skip to content

Commit

Permalink
Overhauling the integration test suite (#137)
Browse files Browse the repository at this point in the history
* fix: simplifying local testing stack

* feat: updating integration tests to remove cucumber

* fix: first integration test passing

* fix: refactoring helper methods and adding a new commented out test case while we work on the snapd client

* feat: replacing the snapd client with API calls to snapcraft.io

* feat: adding a simple mock server to support tests

* feat: finishing off initial voting tests

* chore: removing old test helper code

* chore: removing old cucumber based voting tests

* feat: adding authentication tests

* feat: finishing initial integration test suite rewrite

* feat: more reliable setup and teardown of tests in CI

* chore: updating docs

* chore: installing docker-compose in ci
  • Loading branch information
sminez authored Oct 16, 2024
1 parent 8518eac commit e746e13
Show file tree
Hide file tree
Showing 44 changed files with 1,746 additions and 2,131 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config protobuf-compiler
sudo apt-get install -y libssl-dev pkg-config protobuf-compiler docker-compose
- name: Check code formating
uses: mbrobbel/rustfmt-check@master
Expand All @@ -44,10 +44,7 @@ jobs:
ignore: RUSTSEC-2023-0071 # patch not available att

- name: Setup and Run Tests
run: |
cargo install cargo-make
cargo install dotenvy --features=cli
cargo make full-test
run: make ci-test

publish:
if: github.event_name == 'push'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vscode
.idea
/target
mock_server/target
.env
.env_test
.DS_STORE
Expand Down
95 changes: 45 additions & 50 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,91 +70,86 @@ Once merged to the main branch, `po` files and any documentation change will be

### Setup on Ubuntu

```shell
```bash
# Install the Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
source "$HOME/.cargo/env"

# Install build-time dependencies
sudo apt update
sudo apt install -y git gcc libssl-dev pkg-config protobuf-compiler
sudo apt-get update
sudo apt-get install -y git gcc libssl-dev pkg-config protobuf-compiler

# (Optional) Install Docker for running the OCI image
# Install Docker for running the OCI image and integration tests
sudo apt-get docker-compose
sudo usermod -aG docker $USER
newgrp docker

# Alternatively, if you wish to install docker using the script provided by
# Docker themselves:
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh

# For running the dotenv files
cargo install dotenvy --features=cli
```

### Building and running the binaries

To build and run the binary during development:

```shell
dotenvy -f .env_files/example.env docker compose up -d #or podman-compose up
# Build and run
dotenvy -f .env_files/example.env cargo run --release
```
### Building and running the server

To _just_ build the binary you can run `cargo build --release`. The result will be placed at
`./target/release/ratings`.
For local development there is a docker-compose file that can be used to run
the server alongside a local Postgres database for manual tesing and execution
of the integration test suite. The `Makefile` in the root of the repo has a
number of targets for running common actions within the project:

### About the testsuite
```bash
# To build the release artifact (located in ./target/release/ratings)
make build

The project includes a comprehensive testsuite made of unit and integration tests. All the tests must pass before the review is considered. If you have troubles with the testsuite, feel free to mention it on your PR description.
# To start the local stack:
make up

Currently (but to be changed) this test suite makes use of `cargo-make` and `docker` to coordinate tests.
# To stop the local stack
make down

To install these dependencies:
# To run only the unit tests
make test

```
# Install cargo-make
cargo install cargo-make
# To run only the integration tests (requires the local stack to be up)
make integration-test

# Install docker
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh
# To run all tests (requires the local stack to be up)
make test-all
```

Tests are located under the `tests/` folder and the coordination scripts are located in the `Makefile.toml` file.

These tests require a database to run against. The easiest way to set up the database, run the tests and clean up is via the following commands:

```
# Run the tests
cargo make full-test
### About the testsuite

# Clean up docker images and build artifacts
cargo make full-clean
```
The project includes a comprehensive testsuite made of unit and integration
tests. All the tests must pass before the review is considered. If you have
troubles with the testsuite, feel free to mention it on your PR description.

The test suite must pass before merging the PR to our main branch. Any new feature, change or fix must be covered by corresponding tests.
Also please note that the `category` suite will take *quite a while* to finish, so be patient with it or skip it by manually running the tests you need with `cargo test --test <your-tests>` if you're not touching the category feature.
Unit tests are located within the files containing the code they are testing.

Note that the above won't work if you use `podman` (unless you've put in effort to alias docker commands to `podman` and `podman-compose`),
alternatively you can use:
Integration tests located in `./tests/` and run against the local docker-compose
stack (see the [Building and running the server](#building-and-running-the-server)
section above for details).

```
dotenvy -f .env_files/test.env podman-compose up
dotenvy -f .env_files/test-server.env cargo run
dotenvy -f .env_files/test.env cargo test
```
The test suite must pass before merging the PR to our main branch. Any new
feature, change or fix must be covered by corresponding tests.

In separate tabs (or `tmux` sessions etc), so long as you have the Docker repositories added as a `podman` source.
For more information on writing Rust tests, the following likes are useful:
- <https://doc.rust-lang.org/book/ch11-01-writing-tests.html>
- <https://doc.rust-lang.org/rust-by-example/testing/unit_testing.html>

### Code style

This project follow the [rust style-guide](https://doc.rust-lang.org/1.0.0/style/README.html).

## Contributor License Agreement

It is required to sign the [Contributor License Agreement](https://ubuntu.com/legal/contributors) in order to contribute to this project.
It is required to sign the [Contributor License Agreement](https://ubuntu.com/legal/contributors)
in order to contribute to this project.

An automated test is executed on PRs to check if it has been accepted.

This project is covered by [THIS LICENSE](LICENSE).

## Getting Help

Join us in the [Ubuntu Community](https://discourse.ubuntu.com/c/desktop/8) and post your question there with a descriptive tag.
Join us in the [Ubuntu Community](https://discourse.ubuntu.com/c/desktop/8) and
post your question there with a descriptive tag.
Loading

0 comments on commit e746e13

Please sign in to comment.