Skip to content

Commit c1d1bd5

Browse files
committed
issue #6 - add integration-test workflow + readme
1 parent 1ffb277 commit c1d1bd5

File tree

5 files changed

+116
-12
lines changed

5 files changed

+116
-12
lines changed

.github/workflows/exampleAll.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
name: action-mongo-tools-exampleAll
33

44
on:
5-
push:
6-
branches: [ main ]
7-
pull_request:
8-
workflow_dispatch:
5+
workflow_dispatch: # allow manual trigger only for example
96

107
jobs:
118
mongo-tools-example-steps:

.github/workflows/exampleMongoShellOnly.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
name: action-mongo-tools-exampleMongoShellOnly
33

44
on:
5-
push:
6-
branches: [ main ]
7-
pull_request:
8-
workflow_dispatch:
5+
workflow_dispatch: # allow manual trigger only for example
96

107
jobs:
118
mongo-tools-example-steps:

.github/workflows/exampleMongoToolsOnly.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
name: action-mongo-tools-exampleMongoToolsOnly
33

44
on:
5-
push:
6-
branches: [ main ]
7-
pull_request:
8-
workflow_dispatch:
5+
workflow_dispatch: # allow manual trigger only for example
96

107
jobs:
118
mongo-tools-example-steps:
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Integration Tests
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch: # allow manual trigger
6+
7+
jobs:
8+
test-action:
9+
runs-on: ubuntu-latest
10+
11+
services:
12+
mongodb:
13+
image: mongo
14+
ports:
15+
- 27017:27017
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
# Test local action
21+
- name: Test local action
22+
uses: ./
23+
24+
- name: Verify installation
25+
run: |
26+
# mongo-tools
27+
mongodump --version
28+
mongorestore --version
29+
30+
# mongo-shell
31+
mongosh --version
32+
33+
- name: Functional test
34+
run: |
35+
echo "💥 Create test user"
36+
mongosh admin --eval 'db.createUser({user:"testuser",pwd:"testpass",roles:[{role:"readWrite",db:"testdb"}]});'
37+
38+
echo "💥 Create testdb with testcollection and one doc"
39+
mongosh testdb --quiet --eval 'db.testcollection.insertOne({test: "data"});'
40+
41+
echo "💥 mongodump"
42+
mongodump --db testdb --out ./dump
43+
44+
echo "🔎 check dump exists"
45+
if [ ! -d "./dump/testdb" ]; then
46+
echo "Dump failed"
47+
exit 1
48+
fi
49+
50+
echo "💥 Drop db"
51+
mongosh testdb --eval 'db.dropDatabase();'
52+
53+
echo "💥 Restore it"
54+
mongorestore ./dump
55+
56+
echo "🔎 check restored data"
57+
COUNT=$(mongosh testdb --quiet --eval 'db.testcollection.countDocuments()')
58+
if [ "$COUNT" != "1" ]; then
59+
echo "Restore verification failed - count:$COUNT"
60+
exit 1
61+
fi
62+
echo "✅ This is fine 😁"

TESTING.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Testing the Action
2+
3+
This document describes how to test the action both locally and through GitHub.
4+
5+
## Local Testing
6+
7+
To test the action locally, you'll need:
8+
9+
- [Act](https://github.com/nektos/act) - A tool for running GitHub Actions locally
10+
- Docker installed on your machine
11+
12+
### Installation
13+
14+
- Install Act following the instructions at https://github.com/nektos/act#installation
15+
16+
### Running Tests
17+
18+
- From the root of the repository, run:
19+
```bash
20+
# show workflow events
21+
act list
22+
# or `gh act list` if act is installed as gh client extension
23+
# dry run pull request event
24+
act -n pull_request
25+
# run pull request event
26+
act pull_request
27+
```
28+
29+
This will execute the integration test workflow locally using Act.
30+
31+
## GitHub Testing
32+
33+
The integration tests will automatically run on:
34+
- Every Pull Request
35+
- Manual trigger through the GitHub Actions interface
36+
37+
The workflow will:
38+
1. Install the action from the local repository
39+
2. Verify that all MongoDB tools are correctly installed
40+
3. Perform a functional test including:
41+
- Creating a test user
42+
- Creating test data
43+
- Testing mongodump
44+
- Testing mongorestore
45+
- Verifying data integrity
46+
47+
## Notes
48+
49+
- The local tests using Act might behave slightly differently from GitHub Actions due to environment differences
50+
- Make sure you have enough disk space for Docker images when testing locally
51+
- The integration tests require Docker to be running locally

0 commit comments

Comments
 (0)