Skip to content

Commit

Permalink
tests(api): Add support for E2E test runs against Kong OSS 🚀 [KAG-3203]…
Browse files Browse the repository at this point in the history
… (#10470)

* tests(api): add support for test runs against kong oss

* tests(api):fix router tests for konnect
  • Loading branch information
Hayk-S authored Oct 22, 2024
1 parent 0856925 commit c5d2371
Show file tree
Hide file tree
Showing 33 changed files with 208 additions and 145 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/gateway-api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ on:
required: false
type: boolean
default: false
is_kong_oss:
description: 'Run tests for Kong OSS'
required: false
type: boolean
default: false

workflow_call:
inputs:
Expand All @@ -53,6 +58,11 @@ on:
required: false
type: boolean
default: false
is_kong_oss:
description: 'Run tests for Kong OSS'
required: false
type: boolean
default: false

env:
GW_IMAGE: ${{ inputs.control_plane_image || 'kong/kong-gateway-internal:nightly-ubuntu' }}
Expand All @@ -75,6 +85,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_API_AWS_SECRET_ACCESS_KEY }}
VERBOSE_RESPONSE_LOGS: ${{ inputs.enable_verbose_response_logging }}
RUN_SPEC: ${{ inputs.target_test || 'all' }}
IS_KONG_OSS: ${{ inputs.is_kong_oss || 'false' }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -118,33 +129,41 @@ jobs:
if ${{ contains(env.GW_IMAGE, 'fips') }}; then FIPS_MODE=on; else FIPS_MODE=off; fi;
echo "FIPS_MODE=$FIPS_MODE" >> $GITHUB_ENV
if [[ $RUN_SPEC == "smoke" || $RUN_SPEC == "custom-plugins" || $RUN_SPEC == 'all' ]]; then
if [[ $IS_KONG_OSS == "true" ]]; then
RUN_SPEC="oss"
fi
if [[ $RUN_SPEC == "smoke" || $RUN_SPEC == "custom-plugins" || $RUN_SPEC == 'all' || $RUN_SPEC == 'oss' ]]; then
CUSTOM_PLUGIN=true
else
CUSTOM_PLUGIN=false
fi
echo "CUSTOM_PLUGIN_VAR=$CUSTOM_PLUGIN" >> $GITHUB_ENV
echo "CUSTOM_PLUGIN is $CUSTOM_PLUGIN"
echo "RUN_SPEC=$RUN_SPEC" >> $GITHUB_ENV
echo "RUN_SPEC" is $RUN_SPEC
- name: Start Gateway
run: cd gateway-docker-compose-generator && make generate && cat docker-compose.yml && make start_ci
env:
EE_LICENSE: false
GW_ENTERPRISE: ${{ env.IS_KONG_OSS == 'false' && true || false }}
PKI: true
INFLUXDB: true
INFLUXDB: ${{ env.IS_KONG_OSS == 'false' && true || false }}
REDIS_MODE: standalone
SWAGGER: true
GW_HOST: localhost
HCV: true
HCV: ${{ env.IS_KONG_OSS == 'false' && true || false }}
JAEGER: true
CUSTOM_CONFIG_ALL: "RLA_REDISU: redisuser; RLA_REDISP: redispassword; AWS_REGION: us-east-2; AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}; AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}; GCP_SERVICE_ACCOUNT: '${{ secrets.TEST_API_GCP_SERVICE_ACCOUNT }}'"
KEYCLOAK: true
STATUS_LISTEN: true
PROMETHEUS: true
WASM: true
AZURE_VAULT: true
APP_D: true
APP_D: ${{ env.IS_KONG_OSS == 'false' && true || false }}
AZURE_TENANT_ID: ${{ secrets.TEST_API_AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.TEST_API_AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.TEST_API_AZURE_CLIENT_SECRET }}
Expand Down Expand Up @@ -179,6 +198,8 @@ jobs:
npm run test-smoke;
elif [[ $RUN_SPEC == 'non-smoke' ]]; then
npm run test-non-smoke;
elif [[ $RUN_SPEC == 'oss' ]]; then
npm run test-oss;
else
TEST_APP=gateway npm run test-spec --spec=$RUN_SPEC;
fi
Expand Down
5 changes: 4 additions & 1 deletion spec-ee/kong-api-tests/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ KONNECT_USER_PASSWORD=
APPD_PASSWORD=

# Konnect data plane docker image, default is kong/kong-gateway-dev:nightly-ubuntu
KONNECT_DP_IMAGE='kong/kong-gateway-dev:nightly-ubuntu'
KONNECT_DP_IMAGE='kong/kong-gateway-dev:nightly-ubuntu'

# Whether gateway runs in oss mode or not
IS_KONG_OSS=false
8 changes: 8 additions & 0 deletions spec-ee/kong-api-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ The default Gateway mode is `classic`. If you want to run tests against `hybrid`
GW_MODE=hybrid
```

If you want to run tests against **Kong OSS**, make sure to set `IS_KONG_OSS=true` in your `.env` file or in the GH workflow that you trigger.

### Verbose Response Logging

`export VERBOSE_RESPONSE_LOGS=false` to disable response logging (default is `true`).
Expand All @@ -134,6 +136,12 @@ npm run test-spec --spec=service
npm run test-smoke
```

- Kong OSS tests

```bash
npm run test-oss
```

- Release package tests

Make sure to have `KONG_VERSION` and `KONG_PACKAGE` variables set in your environment.\
Expand Down
3 changes: 2 additions & 1 deletion spec-ee/kong-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"test-smoke": "TEST_APP=gateway mocha -g @smoke --recursive",
"test-non-smoke": "TEST_APP=gateway mocha --invert -g @smoke --recursive",
"test-koko": "TEST_APP=koko TEST_ENV=dev mocha -g @koko --recursive",
"test-gke": "TEST_APP=gateway mocha -g @gke --recursive"
"test-gke": "TEST_APP=gateway mocha -g @gke --recursive",
"test-oss": "TEST_APP=gateway mocha -g @oss --recursive"
},
"dependencies": {
"@kong/kauth-test-utils": "^0.0.23",
Expand Down
8 changes: 8 additions & 0 deletions spec-ee/kong-api-tests/support/config/gateway-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ export const isGwHybrid = (): boolean => {
return getGatewayMode() === 'hybrid' ? true : false;
};

/**
* Check if current gateway mode is OSS
* @returns {boolean} - true if gateway runs in oss mode
*/
export const isKongOSS = (): boolean => {
return process.env.IS_KONG_OSS === 'true' ? true : false;
};

/**
* Check if gateway is installed natively (package tests)
* @returns {boolean} - true if gateway is installed using a package
Expand Down
1 change: 1 addition & 0 deletions spec-ee/kong-api-tests/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
isLocalDatabase,
vars,
isGwNative,
isKongOSS,
getKongContainerName,
getKongVersion,
getDataPlaneDockerImage,
Expand Down
8 changes: 4 additions & 4 deletions spec-ee/kong-api-tests/support/utilities/entities-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { logResponse } from './logging';
import { randomString, wait } from './random';
import { retryRequest } from './retry-axios';
import { getNegative } from './negative-axios';
import { isKongOSS } from '@support';

export const getUrl = (endpoint: string, workspaceNameOrId?: string) => {
let basePath = getBasePath({
Expand Down Expand Up @@ -615,11 +616,10 @@ export const createPlugin = async (
workspace?: string
) => {

// In Koko we don't set 'default' workspace name in URL
if (isGateway()) {
workspace = workspace ? workspace : 'default'
} else if (isKoko()) {
if(isKoko() || isKongOSS()) {
workspace = ''
} else if (isGateway()){
workspace = workspace ? workspace : 'default'
}

const endpoint = `${workspace}/plugins`;
Expand Down
8 changes: 5 additions & 3 deletions spec-ee/kong-api-tests/test/gateway/_hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clearAllKongResources, createRedisClient, gatewayAuthHeader, isCI, waitForConfigRebuild } from '@support';
import { clearAllKongResources, createRedisClient, gatewayAuthHeader, isCI, isKongOSS, waitForConfigRebuild } from '@support';
import {
postGatewayEeLicense,
deleteGatewayEeLicense,
Expand All @@ -12,7 +12,8 @@ export const mochaHooks: Mocha.RootHookObject = {
const { authHeaderKey, authHeaderValue } = gatewayAuthHeader();
axios.defaults.headers[authHeaderKey] = authHeaderValue;
createRedisClient();
if (isCI()) {

if (isCI() && !isKongOSS()) {
// Gateway for API tests starts without EE_LICENSE in CI, hence, we post license at the beginning of all tests to allow us test the functionality of license endpoint
await postGatewayEeLicense();
// Wait for the license propagation to complete before release to the test
Expand All @@ -29,7 +30,8 @@ export const mochaHooks: Mocha.RootHookObject = {

afterAll: async function (this: Mocha.Context) {
// Gateway for API tests starts without EE_LICENSE in CI, hence, we delete license at the end of all tests to allow test rerun from clean state
if (isCI()) {
// Skipping this step for OSS tests
if (isCI() && !isKongOSS()) {
await deleteGatewayEeLicense();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
isGateway,
} from '@support';

describe('@gke: Gateway Admin API: Key-Sets For jwe-decrypt plugin', function () {
describe('@gke @oss: Gateway Admin API: Key-Sets For jwe-decrypt plugin', function () {
const url = `${getBasePath({
environment: isGateway() ? Environment.gateway.admin : undefined,
})}/key-sets`;
Expand Down
2 changes: 1 addition & 1 deletion spec-ee/kong-api-tests/test/gateway/admin-api/keys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('@gke: Gateway Admin API: Keys For jwe-decrypt plugin', function () {
expect(
resp.data.fields.pem,
'Should indicate public key field is missing'
).to.match(/could not load public key.+/);
).to.match(/could not load public key/);
});

it('should not create keys if private key field violates schema', async function () {
Expand Down
Loading

0 comments on commit c5d2371

Please sign in to comment.