grafana / plugin-tools

Create Grafana plugins with ease.
https://grafana.com/developers/plugin-tools/
Apache License 2.0
55 stars 27 forks source link

Plugin E2E: Allow overriding grafanaAPICredentials #930

Closed sunker closed 1 month ago

sunker commented 1 month ago

What this PR does / why we need it:

In a few places in the code, plugin-e2e uses the Grafana API to administrate users, data sources etc. Before this PR, the Grafana API was always called on behalf of the admin:admin user (the default server admin account) as it has all the necessary permissions. This is working fine in most cases, but in the test environment for the SLO app, this account doesn't exist so they're getting 401 errors when setting up users (more details on how to create users here).

With this PR, the Grafana API is still called on behalf of the admin:admin user by default. However, consumers now have the option to override this user by providing a grafanaAPIUser in the playwright config. grafanaAPIUser is a Playwright option, meaning it can be defined on a global level and on a project level. Also, when specifying the user to use when running the e2e test (not the same thing as the grafanaAPIUser), it's now possible to set skipCreateUser prop. This gives the consumer the option to not create the user in the database.

This is an example where one user is being used when calling the Grafana API and another one is being used when running the e2e tests.

export default defineConfig({
    ...
 testDir: './tests',
   use: {
     baseURL: 'http://localhost:3000',
     grafanaAPIUser: {
       user: 'server-admin',
       password: 'server-admin',
     },
    },
    projects: [
    {
      name: 'auth',
      testDir: pluginE2eAuth,
      testMatch: [/.*\.js/],
      use: {
        user: {
          user: 'slo',
          password: 'slo',
          skipCreateUser: true, // this user already exist in the db, so no need to create it during test setup
        },
      },
    },
    {
      name: 'run-tests',
      use: {
        ...devices['Desktop Chrome'],
        storageState: 'playwright/.auth/slo.json',
      },
      dependencies: ['auth'],
    }
  ],
});

Which issue(s) this PR fixes:

Fixes #934

Special notes for your reviewer:

📦 Published PR as canary version: Canary Versions
:sparkles: Test out this PR locally via: ```bash npm install @grafana/plugin-e2e@1.3.0-canary.930.a85b4bb.0 # or yarn add @grafana/plugin-e2e@1.3.0-canary.930.a85b4bb.0 ```
github-actions[bot] commented 1 month ago

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new minor release. NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

grafana-plugins-platform-bot[bot] commented 1 month ago

:rocket: PR was released in @grafana/plugin-e2e@1.3.0 :rocket: