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 mongo integration tests #580

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Database integration tests"

on:
push:
pull_request:
branches: [ main ]

jobs:
mongodb-integration-test:
name: MongoDB integration test
runs-on: ubuntu-latest
services:
mysql:
image: mongo:4.2.2
ports:
- "27017:27017"
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ^1.20

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Run MongoDB integration test
run: |
make integration-test

68 changes: 68 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,74 @@ Please note we have a code of conduct, please follow it in all your interactions
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
do not have permission to do that, you may request the second reviewer to merge it for you.

## Testing

### Adding new integration tests

Integration tests play a crucial role in validating the correct integration of our codebase with its dependencies. To ensure the effectiveness of our testing suite, we encourage contributors to adhere to the following guidelines when adding new integration tests:

1. **Identification in Test Names:**
- All new integration tests should be clearly identifiable by having the word `Integration` in their names. For example:
```go
func TestMongoIntegration(t *testing.T) {
// Test implementation
}
```

2. **Short Test Skip:**
- Each integration test should begin with a specific check to skip the test if it is being run in short mode, for example:
```go
func TestMongoIntegration(t *testing.T) {
if testing.Short() {
t.Skip()
}
// Test implementation
}
```
```go
var _ = Describe("Some test", func() {
BeforeEach(func() {
if testing.Short() {
Skip("Integration tests don't run with 'short' flag")
}
// Test implementation
})
})
```



3. **Conditional Execution with Makefile:**
- Integration tests are designed to be executed explicitly. To run integration tests, use the Makefile target `integration-test`. This ensures that these tests are separate from unit tests and are run independently when needed. Unit tests are executed with the `-short` tag.
```bash
make integration-test
```

By following these guidelines, you contribute to a testing environment that accurately assesses the integration of our project with its dependencies. This separation of unit and integration tests allows for efficient testing and ensures that integration tests are only run when explicitly triggered, promoting a focused and effective testing strategy.

### Running Database Integration Tests Locally

To execute the database integration tests locally, follow these steps:

1. Start the Docker containers configured in the `docker-compose-integration-test.yml` file located in the `deployments` directory:

```bash
$ make integration-test-compose-up
```

This command initializes the required environment for running the integration tests.

2. Run the tests using the following command:

```bash
$ make integration-test
```

This Makefile target executes the database integration tests.

Ensure that you have Docker installed on your machine before running the tests.


## Code of Conduct

### Our Pledge
Expand Down
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,26 @@ run-client-linux-json: build-client-linux

## Performs all unit tests using ginkgo
test:
cd api && $(GO) test -coverprofile=c.out ./...
cd api && $(GO) test -coverprofile=c.out ./... -short
cd api && $(GO) tool cover -func=c.out
cd api && $(GO) tool cover -html=c.out -o coverage.html
cd client && $(GO) test -coverprofile=d.out ./...
cd client && $(GO) test -coverprofile=d.out ./... -short
cd client && $(GO) tool cover -func=d.out
cd cli && $(GO) test -coverprofile=e.out ./...
cd cli && $(GO) test -coverprofile=e.out ./... -short
cd cli && $(GO) tool cover -func=e.out

## Composes huskyCI integration test environment using docker-compose
integration-test-compose-up:
docker-compose -f deployments/docker-compose-integration-test.yml down -v
docker-compose -f deployments/docker-compose-integration-test.yml up -d --build --force-recreate

## Composes down the integration test docker compose
integration-test-compose-down:
docker-compose -f deployments/docker-compose-integration-test.yml down -v

## Run all integration tests. The tests must contain the 'Integration' on his name
integration-test:
cd api && $(GO) test -race ./... -run Integration

## Builds and push securityTest containers with the latest tags
update-containers: build-containers push-containers