Skip to content

Commit f853570

Browse files
committed
Add e2e tests for older and new grafana versions
1 parent 7b190bc commit f853570

File tree

3 files changed

+70
-55
lines changed

3 files changed

+70
-55
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
grafana: ['9.5.0', '11.6.1']
1418
steps:
1519
- uses: actions/checkout@v4
1620

@@ -43,31 +47,17 @@ jobs:
4347
version: latest
4448
args: buildAll
4549

46-
- name: Setup services (Trino, Grafana, PostgreSQL, Keycloak)
50+
- name: Setup services (Trino, Grafana, Keycloak)
4751
run: |
4852
docker network create trino
4953
50-
echo "Starting PostgreSQL..."
51-
docker run --rm --detach \
52-
--name postgres \
53-
--net trino \
54-
--env POSTGRES_USER=keycloak \
55-
--env POSTGRES_PASSWORD=keycloak \
56-
--env POSTGRES_DB=keycloak \
57-
postgres:17.4
58-
5954
echo "Starting Keycloak..."
6055
docker run --rm --detach \
6156
--name keycloak \
6257
--net trino \
6358
--publish 18080:8080 \
6459
--env KC_BOOTSTRAP_ADMIN_USERNAME=admin \
6560
--env KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
66-
--env KC_DB=postgres \
67-
--env KC_DB_URL_HOST=postgres \
68-
--env KC_DB_URL_DATABASE=keycloak \
69-
--env KC_DB_USERNAME=keycloak \
70-
--env KC_DB_PASSWORD=keycloak \
7161
--volume "$(pwd)/test-data/test-keycloak-realm.json:/opt/keycloak/data/import/realm.json" \
7262
quay.io/keycloak/keycloak:26.1.4 \
7363
start-dev --import-realm
@@ -96,10 +86,32 @@ jobs:
9686
--publish 3000:3000 \
9787
--volume "$(pwd):/var/lib/grafana/plugins/trino" \
9888
--env "GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=trino-datasource" \
99-
grafana/grafana:11.4.0
89+
grafana/grafana:${{ matrix.grafana }}
10090
10191
- name: End to end test
10292
run: |
10393
npx tsc -p tsconfig.json --noEmit
10494
npx playwright install
10595
npx playwright test
96+
97+
- uses: actions/upload-artifact@v4
98+
if: ${{ !cancelled() }}
99+
with:
100+
name: playwright-report-${{ matrix.grafana }}
101+
path: playwright-report/
102+
retention-days: 5
103+
104+
- name: Dump logs
105+
if: always()
106+
run: |
107+
echo "::group::Trino logs"
108+
docker logs trino
109+
echo "::endgroup::"
110+
111+
echo "::group::Keycloak logs"
112+
docker logs keycloak
113+
echo "::endgroup::"
114+
115+
echo "::group::Grafana logs"
116+
docker logs grafana
117+
echo "::endgroup::"

src/e2e.test.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,69 @@
11
import { test, expect, Page } from '@playwright/test';
22

33
const GRAFANA_CLIENT = 'grafana-client';
4-
const EXPORT_DATA = 'Explore data';
4+
const EXPLORE_DATA = 'Explore';
55

66
async function login(page: Page) {
77
await page.goto('http://localhost:3000/login');
8-
await page.getByTestId('data-testid Username input field').fill('admin');
9-
await page.getByTestId('data-testid Password input field').fill('admin');
10-
await page.getByTestId('data-testid Login button').click();
11-
await page.getByTestId('data-testid Skip change password button').click();
8+
await page.getByPlaceholder('email or username').fill('admin');
9+
await page.getByPlaceholder('password').fill('admin');
10+
await page.getByRole('button', { name: 'Login button' }).or(page.getByRole('button', { name: 'Log in' })).click();
11+
await page.getByRole('button', { name: /skip/i }).click();
1212
}
1313

1414
async function goToTrinoSettings(page: Page) {
15-
await page.getByTestId('data-testid Toggle menu').click();
16-
await page.getByRole('link', {name: 'Connections'}).click();
17-
await page.getByRole('link', {name: 'Trino'}).click();
18-
await page.locator('.css-1yhi3xa').click();
19-
await page.getByRole('button', {name: 'Add new data source'}).click();
15+
await page.getByRole('button', { name: /toggle menu|open menu/i }).click();
16+
await page.getByText('Connections').click();
17+
await page.getByText(/add.*connection|connect data/i).first().click();
18+
await page.getByText('Trino').click();
19+
await page.getByRole('button', { name: /add new data source|create.*trino.*data source/i }).click();
2020
}
2121

2222
async function setupDataSourceWithAccessToken(page: Page) {
23-
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
24-
await page.locator('div').filter({hasText: /^Impersonate logged in user$/}).getByLabel('Toggle switch').click();
23+
await page.getByPlaceholder('http://localhost:8080').fill('http://trino:8080');
24+
await page.locator('label[for="trino-settings-enable-impersonation"][aria-label="Toggle switch"], label[for="trino-settings-enable-impersonation"]:has(svg)').first().click();
2525
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
26-
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
26+
await page.getByRole('button', { name: /save.*test/i }).click();
2727
}
2828

2929
async function setupDataSourceWithClientCredentials(page: Page, clientId: string) {
30-
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
30+
await page.getByPlaceholder('http://localhost:8080').fill('http://trino:8080');
3131
await page.locator('div').filter({hasText: /^Token URL$/}).locator('input').fill('http://keycloak:8080/realms/trino-realm/protocol/openid-connect/token');
3232
await page.locator('div').filter({hasText: /^Client id$/}).locator('input').fill(clientId);
3333
await page.locator('div').filter({hasText: /^Client secret$/}).locator('input[type="password"]').fill('grafana-secret');
3434
await page.locator('div').filter({hasText: /^Impersonation user$/}).locator('input').fill('service-account-grafana-client');
35-
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
35+
await page.getByRole('button', { name: /save.*test/i }).click();
36+
}
37+
38+
async function runQueryAndCheckResults(page: Page) {
39+
await page.getByText(EXPLORE_DATA).click();
40+
await page.locator('textarea[aria-label*="Editor content"]').click();
41+
await page.getByTestId('data-testid TimePicker Open Button').click();
42+
const timeInputs = page.locator('input[value*="now"], input[value*="00:00:00"]');
43+
await timeInputs.first().fill('1995-01-01');
44+
await timeInputs.last().fill('1995-12-31');
45+
await page.getByTestId('data-testid TimePicker submit button').click();
46+
await page.locator('[role="combobox"][aria-label="Format as"]').click();
47+
await page.locator('[id^="react-select"][id$="option-1"]').waitFor();
48+
await page.locator('[id^="react-select"][id$="option-1"]').click();
49+
await expect(page.locator('[role="table"][aria-label="Explore Table"]').getByText(/1995-01-\d+/).first()).toBeVisible();
3650
}
3751

3852
async function setupDataSourceWithClientTags(page: Page, clientTags: string) {
39-
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
40-
await page.locator('div').filter({hasText: /^Impersonate logged in user$/}).getByLabel('Toggle switch').click();
53+
await page.getByPlaceholder('http://localhost:8080').fill('http://trino:8080');
54+
await page.locator('label[for="trino-settings-enable-impersonation"][aria-label="Toggle switch"], label[for="trino-settings-enable-impersonation"]:has(svg)').first().click();
4155
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
4256
await page.locator('div').filter({hasText: /^Client Tags$/}).locator('input').fill(clientTags);
43-
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
57+
await page.getByRole('button', { name: /save.*test/i }).click();
4458
}
4559

46-
async function runQueryAndCheckResults(page: Page) {
47-
await page.getByLabel(EXPORT_DATA).click();
48-
await page.getByTestId('data-testid TimePicker Open Button').click();
49-
await page.getByTestId('data-testid Time Range from field').fill('1995-01-01');
50-
await page.getByTestId('data-testid Time Range to field').fill('1995-12-31');
51-
await page.getByTestId('data-testid TimePicker submit button').click();
52-
await page.locator('div').filter({hasText: /^Format asChoose$/}).locator('svg').click();
53-
await page.getByRole('option', {name: 'Table'}).click();
54-
await page.getByTestId('data-testid Code editor container').click();
55-
await page.getByTestId('data-testid RefreshPicker run button').click();
56-
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:005703857F.*/);
57-
}
60+
test('test client credentials flow with wrong credentials', async ({ page }) => {
61+
await login(page);
62+
await goToTrinoSettings(page);
63+
await setupDataSourceWithClientCredentials(page, "some-wrong-client");
64+
await expect(page.getByTestId('data-testid Alert error')).toBeVisible();
65+
await expect(page.getByTestId('data-testid Alert error')).toContainText('Bad Request');
66+
});
5867

5968
test('test with access token', async ({ page }) => {
6069
await login(page);
@@ -70,19 +79,13 @@ test('test client credentials flow', async ({ page }) => {
7079
await runQueryAndCheckResults(page);
7180
});
7281

73-
test('test client credentials flow with wrong credentials', async ({ page }) => {
74-
await login(page);
75-
await goToTrinoSettings(page);
76-
await setupDataSourceWithClientCredentials(page, "some-wrong-client");
77-
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
78-
});
79-
8082
test('test client credentials flow with configured access token', async ({ page }) => {
8183
await login(page);
8284
await goToTrinoSettings(page);
8385
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
8486
await setupDataSourceWithClientCredentials(page, GRAFANA_CLIENT);
85-
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
87+
await expect(page.getByTestId('data-testid Alert error')).toBeVisible();
88+
await expect(page.getByTestId('data-testid Alert error')).toContainText('Internal Server Error');
8689
});
8790

8891
test('test with client tags', async ({ page }) => {

src/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"updated": "%TODAY%"
5252
},
5353
"dependencies": {
54-
"grafanaDependency": ">=8.3.0",
54+
"grafanaDependency": ">=9.5.0",
5555
"plugins": []
5656
}
5757
}

0 commit comments

Comments
 (0)