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 unit and E2E tests #479

Merged
merged 50 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2bb6926
set up test environment
AgnesToulet Nov 7, 2023
7cbfe4b
fix and clean up tests
AgnesToulet Nov 7, 2023
48a15a5
update Drone config to run tests
AgnesToulet Nov 7, 2023
dd9087b
clean up docker-compose file
AgnesToulet Nov 7, 2023
32547a7
fix Grafana setup step
AgnesToulet Nov 7, 2023
fbe8966
init yarn in test step
AgnesToulet Nov 7, 2023
9d726eb
Update common.star
AgnesToulet Nov 7, 2023
dd667fc
Update .drone.yml
AgnesToulet Nov 7, 2023
b5a6072
Update browser.test.ts
AgnesToulet Nov 7, 2023
34bf09f
add volumes for puppeteer cache
AgnesToulet Nov 10, 2023
866529e
Merge branch 'master' into add-tests
AgnesToulet Nov 10, 2023
97fe6e2
fix after merge
AgnesToulet Nov 10, 2023
b5feb30
install browser in drone workspace
AgnesToulet Nov 10, 2023
307a00c
try to fix workspace
AgnesToulet Nov 10, 2023
730f01d
test other image to run tests
AgnesToulet Nov 10, 2023
2413ae5
Update .drone.yml
AgnesToulet Nov 10, 2023
3b759d1
trying things
AgnesToulet Nov 10, 2023
4377a05
Update ci image
AgnesToulet Nov 13, 2023
24f8a8d
fix test endpoint
AgnesToulet Nov 13, 2023
d180f9f
add debug logs
AgnesToulet Nov 13, 2023
9ca3d22
fix provisioning file path
AgnesToulet Nov 13, 2023
b007c61
Update http-server.integration.test.ts
AgnesToulet Nov 13, 2023
bed8de4
fix volumes
AgnesToulet Nov 13, 2023
06a8ded
update provisioning
AgnesToulet Nov 13, 2023
c43d81b
fix dashboards provisioning path
AgnesToulet Nov 13, 2023
e738aea
remove debug logs
AgnesToulet Nov 13, 2023
6cd00f7
add image log
AgnesToulet Nov 14, 2023
5b9fb28
tmp comment out tests
AgnesToulet Nov 14, 2023
ebaaca5
Update http-server.integration.test.ts
AgnesToulet Nov 14, 2023
6e17d49
Update http-server.integration.test.ts
AgnesToulet Nov 14, 2023
51fe72b
test with deviceScaleFactor
AgnesToulet Nov 14, 2023
9bb9343
Update http-server.integration.test.ts
AgnesToulet Nov 14, 2023
92bff43
display styles to compare CI vs local
AgnesToulet Nov 14, 2023
ac20d38
Update browser.ts
AgnesToulet Nov 14, 2023
091b7b7
Use pixelmatch to compare test images + clean up
AgnesToulet Nov 17, 2023
c5a2753
remove failing test + clean up provisioning files
AgnesToulet Nov 17, 2023
e66c900
switch image to grafana-enterprise
AgnesToulet Nov 17, 2023
556cbd3
update test image
AgnesToulet Nov 23, 2023
6ffa5f4
Update README.md
AgnesToulet Nov 23, 2023
5d38837
fix docker-compose path
AgnesToulet Jan 2, 2024
dcd3268
Merge branch 'master' into add-tests
AgnesToulet Jan 8, 2024
45abb29
Add instructions to run on Drone-like env
AgnesToulet Jan 16, 2024
4b7d4c0
update golden files
AgnesToulet Jan 16, 2024
b8b8a2f
remove broken test
AgnesToulet Jan 16, 2024
54e3607
remove slow.png
AgnesToulet Jan 16, 2024
8a822fa
move reading env settings
AgnesToulet Jan 16, 2024
20997f9
update yarn-test to embed running Grafana Docker
AgnesToulet Jan 16, 2024
e812ca8
Update Drone Docker and instructions
AgnesToulet Jan 16, 2024
3987c2c
Merge branch 'master' into add-tests
AgnesToulet Jan 29, 2024
032210a
hide logs on success
AgnesToulet Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 81 additions & 16 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ node:
platform:
arch: amd64
os: linux
services: []
services:
- environment:
GF_FEATURE_TOGGLES_ENABLE: renderAuthJWT
GF_PATHS_PROVISIONING: /drone/src/scripts/drone/provisioning
image: grafana/grafana-enterprise:latest
name: grafana
steps:
- commands:
- mkdir -p bin
Expand All @@ -24,6 +29,8 @@ steps:
- yarn install --frozen-lockfile --no-progress
depends_on:
- grabpl
environment:
PUPPETEER_CACHE_DIR: /drone/src/cache
image: grafana/grafana-plugin-ci:1.9.0
name: yarn-install
- commands:
Expand All @@ -33,6 +40,20 @@ steps:
- yarn-install
image: grafana/grafana-plugin-ci:1.9.0
name: yarn-build
- commands:
- dockerize -wait http://grafana:3000 -timeout 120s
image: jwilder/dockerize:0.6.1
name: wait-for-grafana
- commands:
- yarn test
depends_on:
- wait-for-grafana
- yarn-build
environment:
CI: "true"
PUPPETEER_CACHE_DIR: /drone/src/cache
image: grafana/docker-puppeteer:pre-node-20
name: yarn-test
- commands:
- . ~/.init-nvm.sh
- echo "Starting veracode scan..."
Expand All @@ -55,7 +76,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-linux-x64-glibc || true
- ./scripts/archive_target.sh linux-x64-glibc
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -67,7 +88,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-darwin-x64-unknown || true
- ./scripts/archive_target.sh darwin-x64-unknown
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -79,7 +100,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-win32-x64-unknown || true
- ./scripts/archive_target.sh win32-x64-unknown
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -92,7 +113,7 @@ steps:
true
- ./scripts/archive_target.sh linux-x64-glibc plugin-linux-x64-glibc-no-chromium
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -119,7 +140,12 @@ node:
platform:
arch: amd64
os: linux
services: []
services:
- environment:
GF_FEATURE_TOGGLES_ENABLE: renderAuthJWT
GF_PATHS_PROVISIONING: /drone/src/scripts/drone/provisioning
image: grafana/grafana-enterprise:latest
name: grafana
steps:
- commands:
- mkdir -p bin
Expand All @@ -132,6 +158,8 @@ steps:
- yarn install --frozen-lockfile --no-progress
depends_on:
- grabpl
environment:
PUPPETEER_CACHE_DIR: /drone/src/cache
image: grafana/grafana-plugin-ci:1.9.0
name: yarn-install
- commands:
Expand All @@ -141,6 +169,20 @@ steps:
- yarn-install
image: grafana/grafana-plugin-ci:1.9.0
name: yarn-build
- commands:
- dockerize -wait http://grafana:3000 -timeout 120s
image: jwilder/dockerize:0.6.1
name: wait-for-grafana
- commands:
- yarn test
depends_on:
- wait-for-grafana
- yarn-build
environment:
CI: "true"
PUPPETEER_CACHE_DIR: /drone/src/cache
image: grafana/docker-puppeteer:pre-node-20
name: yarn-test
- commands:
- . ~/.init-nvm.sh
- echo "Starting veracode scan..."
Expand All @@ -163,7 +205,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-linux-x64-glibc
- ./scripts/archive_target.sh linux-x64-glibc
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -175,7 +217,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-darwin-x64-unknown
- ./scripts/archive_target.sh darwin-x64-unknown
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -187,7 +229,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-win32-x64-unknown
- ./scripts/archive_target.sh win32-x64-unknown
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -199,14 +241,16 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-linux-x64-glibc-no-chromium
- ./scripts/archive_target.sh linux-x64-glibc plugin-linux-x64-glibc-no-chromium
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
image: grafana/grafana-plugin-ci:1.9.0
name: package-linux-x64-glibc-no-chromium
- commands:
- ./scripts/build_push_docker.sh master
depends_on:
- yarn-test
environment:
DOCKER_PASS:
from_secret: docker_pass
Expand Down Expand Up @@ -241,7 +285,12 @@ node:
platform:
arch: amd64
os: linux
services: []
services:
- environment:
GF_FEATURE_TOGGLES_ENABLE: renderAuthJWT
GF_PATHS_PROVISIONING: /drone/src/scripts/drone/provisioning
image: grafana/grafana-enterprise:latest
name: grafana
steps:
- commands:
- mkdir -p bin
Expand All @@ -254,6 +303,8 @@ steps:
- yarn install --frozen-lockfile --no-progress
depends_on:
- grabpl
environment:
PUPPETEER_CACHE_DIR: /drone/src/cache
image: grafana/grafana-plugin-ci:1.9.0
name: yarn-install
- commands:
Expand All @@ -263,6 +314,20 @@ steps:
- yarn-install
image: grafana/grafana-plugin-ci:1.9.0
name: yarn-build
- commands:
- dockerize -wait http://grafana:3000 -timeout 120s
image: jwilder/dockerize:0.6.1
name: wait-for-grafana
- commands:
- yarn test
depends_on:
- wait-for-grafana
- yarn-build
environment:
CI: "true"
PUPPETEER_CACHE_DIR: /drone/src/cache
image: grafana/docker-puppeteer:pre-node-20
name: yarn-test
- commands:
- . ~/.init-nvm.sh
- echo "Starting veracode scan..."
Expand All @@ -285,7 +350,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-linux-x64-glibc
- ./scripts/archive_target.sh linux-x64-glibc
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -297,7 +362,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-darwin-x64-unknown
- ./scripts/archive_target.sh darwin-x64-unknown
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -309,7 +374,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-win32-x64-unknown
- ./scripts/archive_target.sh win32-x64-unknown
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand All @@ -321,7 +386,7 @@ steps:
- bin/grabpl build-plugin-manifest ./dist/plugin-linux-x64-glibc-no-chromium
- ./scripts/archive_target.sh linux-x64-glibc plugin-linux-x64-glibc-no-chromium
depends_on:
- yarn-build
- yarn-test
environment:
GRAFANA_API_KEY:
from_secret: grafana_api_key
Expand Down Expand Up @@ -414,6 +479,6 @@ kind: secret
name: srcclr_api_token
---
kind: signature
hmac: eeb3dd651cc32e9e32188e7f904e97131911d9699c7610c4b33a19098c257d9f
hmac: f6cb2de5719e26d46b642bb10f322f1b269310d013408b72a0d72b1c05d4ebea

...
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ dist/**/*
# Ignore output from coverage report
coverage

scripts/tmp
scripts/tmp

tests/testdata/diff_*

cache
81 changes: 61 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ The following example shows how you can run Grafana and the remote HTTP renderin

1. Create a `docker-compose.yml` with the following content:

```yaml
version: '2'

services:
grafana:
image: grafana/grafana:latest
ports:
- '3000:3000'
environment:
GF_RENDERING_SERVER_URL: http://renderer:8081/render
GF_RENDERING_CALLBACK_URL: http://grafana:3000/
GF_LOG_FILTERS: rendering:debug
renderer:
image: grafana/grafana-image-renderer:latest
ports:
- 8081
```
```yaml
version: '2'

services:
grafana:
image: grafana/grafana:latest
ports:
- '3000:3000'
environment:
GF_RENDERING_SERVER_URL: http://renderer:8081/render
GF_RENDERING_CALLBACK_URL: http://grafana:3000/
GF_LOG_FILTERS: rendering:debug
renderer:
image: grafana/grafana-image-renderer:latest
ports:
- 8081
```

1. Next, run docker compose.

```bash
docker-compose up
```
```bash
docker-compose up
```

### Run as standalone Node.js application

Expand Down Expand Up @@ -122,3 +122,44 @@ For available configuration settings, please refer to [Grafana Image Rendering d

For troubleshooting help, refer to
[Grafana Image Rendering troubleshooting documentation](https://grafana.com/docs/grafana/latest/image-rendering/troubleshooting/).

## Testing

In order to run the image-renderer automated test suites, you need to run the following command from the root folder:

```
yarn test
```

This will launch a Grafana instance in Docker and, then, run the test suites.

_Notes:_

If there are some expected changes in the reference image files (located in `/tests/testdata`), run `yarn test-update` and push the updated references.

If the tests are failing and you want to see the difference between the image you get and the reference image, run `yarn test-diff`. This will generate images (called `diff_<test case>.png`) containing the differences in the `/tests/testdata` folder.

### Fixing Drone issues

If tests are successful in your local environement but fail in Drone. You can follow these steps to run the tests in an environment similar to the Drone pipeline. This will mount your local files of the `grafana-image-renderer` repo in the Docker image so any change that happens in the Docker image will be available in your local environment. This allows you to run `yarn test-diff` and `yarn test-update` in Docker and see the results locally.

1. Run the Drone environment in Docker:

```
cd ./devenv/docker/drone
docker-compose up
```

2. Open a terminal within the `drone-docker-puppeteer` container and run the following commands:

```
cd /drone/src
PUPPETEER_CACHE_DIR=/drone/src/cache yarn install --frozen-lockfile --no-progress
PUPPETEER_CACHE_DIR=/drone/src/cache CI=true yarn test-ci
```

_Notes:_
The tests might take longer in the Docker container. If you run into timeout issues, you can run the test command with the `--testTimeout option`:
```
PUPPETEER_CACHE_DIR=/drone/src/cache CI=true yarn test-ci --testTimeout=10000
```
20 changes: 20 additions & 0 deletions devenv/docker/drone/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '2'

services:
docker-puppeteer:
image: grafana/docker-puppeteer:pre-node-20
volumes:
- "../../..:/drone/src"
stdin_open: true # docker run -i
tty: true # docker run -t
entrypoint: bash
grafana:
image: grafana/grafana-enterprise:latest
ports:
- 3000:3000
environment:
GF_FEATURE_TOGGLES_ENABLE: renderAuthJWT
volumes:
- ../test/dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml
- ../../../scripts/drone/provisioning/dashboards:/usr/share/grafana/dashboards
- ../../../scripts/drone/provisioning/datasources/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
1 change: 1 addition & 0 deletions devenv/docker/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This Docker environment is used to run E2E tests for the image renderer locally.
11 changes: 11 additions & 0 deletions devenv/docker/test/dashboards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'Tests'
folder: 'tests'
folderUid: ''
type: file
allowUiUpdates: false
updateIntervalSeconds: 60
options:
path: dashboards
Loading
Loading