diff --git a/apps/cli-e2e/README.md b/apps/cli-e2e/README.md new file mode 100644 index 00000000..b66ae09c --- /dev/null +++ b/apps/cli-e2e/README.md @@ -0,0 +1,5 @@ +# E2E Test for CLI + +**Currently we don't do E2E testing on the cli, but rather unit testing and E2E testing in each module separately.** + +**So this package is used as a placeholder in the project.** diff --git a/apps/cli-e2e/assets/apisix/apisix-config.yaml b/apps/cli-e2e/assets/apisix/apisix-config.yaml deleted file mode 100644 index 7cd067c7..00000000 --- a/apps/cli-e2e/assets/apisix/apisix-config.yaml +++ /dev/null @@ -1,9 +0,0 @@ -deployment: - admin: - allow_admin: - - 0.0.0.0/0 - etcd: - host: - - "http://etcd:2379" - prefix: "/apisix" - timeout: 30 diff --git a/apps/cli-e2e/assets/apisix/docker-compose.yaml b/apps/cli-e2e/assets/apisix/docker-compose.yaml deleted file mode 100644 index 10c175ac..00000000 --- a/apps/cli-e2e/assets/apisix/docker-compose.yaml +++ /dev/null @@ -1,19 +0,0 @@ -version: '3' -services: - etcd: - image: bitnami/etcd:3.5.11 - environment: - ALLOW_NONE_AUTHENTICATION: 'yes' - ETCD_ADVERTISE_CLIENT_URLS: 'http://etcd:2379' - ETCD_LISTEN_CLIENT_URLS: 'http://0.0.0.0:2379' - ports: - - '2379:2379/tcp' - apisix: - image: apache/apisix:3.8.0-debian - depends_on: - - etcd - volumes: - - ./apisix-config.yaml:/usr/local/apisix/conf/config.yaml:ro - ports: - - '9080:9080/tcp' - - '9180:9180/tcp' diff --git a/apps/cli-e2e/jest.config.ts b/apps/cli-e2e/jest.config.ts index 919a039b..c7474ce8 100644 --- a/apps/cli-e2e/jest.config.ts +++ b/apps/cli-e2e/jest.config.ts @@ -4,7 +4,6 @@ export default { preset: '../../jest.preset.js', globalSetup: '/src/support/global-setup.ts', globalTeardown: '/src/support/global-teardown.ts', - setupFiles: ['/src/support/test-setup.ts'], testEnvironment: 'node', transform: { '^.+\\.[tj]s$': [ diff --git a/apps/cli-e2e/src/apisix/ping.spec.ts b/apps/cli-e2e/src/apisix/ping.spec.ts deleted file mode 100644 index 85577b4a..00000000 --- a/apps/cli-e2e/src/apisix/ping.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { execSync } from 'node:child_process'; - -describe('Ping command', () => { - it('Ensure ping command is exist', async () => { - const out = execSync(`./adc help ping`).toString('utf8'); - expect(out).toContain('Usage: adc ping [options]'); - }); - - it('Use ping command (with correct token)', () => { - const out = execSync( - './adc ping --token edd1c9f034335f136f87ad84b625c8f1', - ).toString('utf8'); - expect(out).toContain('Connected to backend successfully!'); - }); - - it('Use ping command (with incorrect token)', () => { - try { - execSync('./adc ping --token incorrent-token'); - } catch (err) { - expect(err.output.toString('utf8')).toContain( - 'Failed to ping backend, AxiosError: Request failed with status code 401', - ); - } - }); - - it('Use ping command (with incorrect server address)', () => { - try { - execSync('./adc ping --token token --server http://127.0.0.1:9999'); - } catch (err) { - expect(err.output.toString('utf8')).toContain( - 'Failed to ping backend, Error: connect ECONNREFUSED 127.0.0.1:9999', - ); - } - }); -}); diff --git a/apps/cli-e2e/src/support/global-setup.ts b/apps/cli-e2e/src/support/global-setup.ts index c1f51444..bab0a073 100644 --- a/apps/cli-e2e/src/support/global-setup.ts +++ b/apps/cli-e2e/src/support/global-setup.ts @@ -1,10 +1,3 @@ -/* eslint-disable */ -var __TEARDOWN_MESSAGE__: string; - -module.exports = async function () { - // Start services that that the app needs to run (e.g. database, docker-compose, etc.). - console.log('\nSetting up...\n'); - - // Hint: Use `globalThis` to pass variables to global teardown. - globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n'; +export default () => { + /* */ }; diff --git a/apps/cli-e2e/src/support/global-teardown.ts b/apps/cli-e2e/src/support/global-teardown.ts index 32ea345c..bab0a073 100644 --- a/apps/cli-e2e/src/support/global-teardown.ts +++ b/apps/cli-e2e/src/support/global-teardown.ts @@ -1,7 +1,3 @@ -/* eslint-disable */ - -module.exports = async function () { - // Put clean up logic here (e.g. stopping services, docker-compose, etc.). - // Hint: `globalThis` is shared between setup and teardown. - console.log(globalThis.__TEARDOWN_MESSAGE__); +export default () => { + /* */ }; diff --git a/apps/cli-e2e/src/support/test-setup.ts b/apps/cli-e2e/src/support/test-setup.ts deleted file mode 100644 index a113e6ef..00000000 --- a/apps/cli-e2e/src/support/test-setup.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable */ -import axios from 'axios'; -import _ from 'lodash'; -import { parse, stringify } from 'qs'; - -module.exports = async function () { - // Configure axios for tests to use. - // const host = process.env.HOST ?? 'localhost'; - // const port = process.env.PORT ?? '3000'; - axios.defaults.paramsSerializer = { - encode: (params) => parse(params), - serialize: (params) => stringify(params), - }; - axios.defaults.baseURL = process.env.API7EE_SERVER_URL; - axios.interceptors.response.use( - (response) => response, - (error) => { - console.log('error: ', error); - - if (!error?.request) return; - - const picked = _.pick(error.request, [ - 'outputData', - 'writable', - 'destroyed', - 'chunkedEncoding', - 'shouldKeepAlive', - 'maxRequestsOnConnectionReached', - 'useChunkedEncodingByDefault', - 'sendDate', - 'finished', - 'method', - 'maxHeaderSize', - 'path', - 'aborted', - 'timeoutCb', - 'upgradeOrConnect', - 'host', - 'config', - '_header', - '_keepAliveTimeout', - ]); - error.request = picked; - if (error.response?.request) { - error.response.request = picked; - } - return error; - }, - ); -};