From ac2f7a8745f161a5151f02c2fc8ae8eb25d137ba Mon Sep 17 00:00:00 2001 From: Qing Tomlinson Date: Tue, 23 Apr 2024 15:20:29 -0700 Subject: [PATCH] Reorganize fixtures for autoloading Group fixtures by endpoints. This ensures that the json response format is consistent within the folder, allowing for coordinates parsing. --- tools/integration/README.md | 1 + .../test/e2e-test-service/definitionTest.js | 29 ++++++++++++++----- .../pod-cocoapods---softbutton-0.1.0.json} | 0 tools/integration/test/testConfig.js | 6 ---- 4 files changed, 23 insertions(+), 13 deletions(-) rename tools/integration/test/fixtures/{softbutton-0.1.0.json => definitions/pod-cocoapods---softbutton-0.1.0.json} (100%) diff --git a/tools/integration/README.md b/tools/integration/README.md index 69625c9..a8b1c3e 100644 --- a/tools/integration/README.md +++ b/tools/integration/README.md @@ -17,5 +17,6 @@ - Mock responses when the production system does not have the response or needs an override, - Current harvest schema versions. This is for polling harvest results to check whether the harvest is complete. When scan tool versions are updated, this needs to be updated as well. +1. Test fixtures are grouped by endpoints at [./test/fixtures](./test/fixtures). 1. The classes used in the integration tests are located at ./lib. Tests for those tooling classes are located at ./test/lib. Run `npm test` to test the tooling classes. 1. Sample API test calls to the production deployment can be found at ./api-test. The [Insomnia collection](./api-test/clearlydefined_prod_api_test_insomnia_collection.json) is organized by endpoints (definitions, harvest, and notices). Refer to the [Swagger UI](https://api.clearlydefined.io/api-docs/#/) for detailed documentation. The `Ping/health check` can be used as the first check to see if the service is up and running. diff --git a/tools/integration/test/e2e-test-service/definitionTest.js b/tools/integration/test/e2e-test-service/definitionTest.js index 57f2b8a..93c43a6 100644 --- a/tools/integration/test/e2e-test-service/definitionTest.js +++ b/tools/integration/test/e2e-test-service/definitionTest.js @@ -4,22 +4,23 @@ const { omit, isEqual } = require('lodash') const { deepStrictEqual, strictEqual } = require('assert') const { callFetch, buildPostOpts } = require('../../lib/fetch') -const { devApiBaseUrl, prodApiBaseUrl, expectedResponses, components, definition } = require('../testConfig') +const { devApiBaseUrl, prodApiBaseUrl, components, definition } = require('../testConfig') const nock = require('nock') +const fs = require('fs') describe('Validation definitions between dev and prod', function () { this.timeout(definition.timeout) - before(() => { - expectedResponses.forEach(({ url, response }) => - nock(prodApiBaseUrl, { allowUnmocked: true }).get(url).reply(200, response) - ) - }) - //Rest a bit to avoid overloading the servers afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) describe('Validation between dev and prod', function () { + before(() => { + loadFixtures().forEach(([url, definition]) => + nock(prodApiBaseUrl, { allowUnmocked: true }).get(url).reply(200, definition) + ) + }) + components.forEach(coordinates => { it(`should return the same definition as prod for ${coordinates}`, () => fetchAndCompareDefinition(coordinates)) }) @@ -120,3 +121,17 @@ async function findDefinition(coordinates) { ).then(r => r.json()) return response.data.find(d => d.coordinates.revision === revision) } + +function loadFixtures() { + const location = 'test/fixtures/definitions' + return fs + .readdirSync(location) + .filter(f => f.endsWith('.json')) + .map(jsonFile => JSON.parse(fs.readFileSync(`${location}/${jsonFile}`))) + .map(definition => { + const { coordinates } = definition + const namespace = coordinates.namespace || '-' + const coordinatesString = `${coordinates.type}/${coordinates.provider}/${namespace}/${coordinates.name}/${coordinates.revision}` + return [`/definitions/${coordinatesString}`, definition] + }) +} diff --git a/tools/integration/test/fixtures/softbutton-0.1.0.json b/tools/integration/test/fixtures/definitions/pod-cocoapods---softbutton-0.1.0.json similarity index 100% rename from tools/integration/test/fixtures/softbutton-0.1.0.json rename to tools/integration/test/fixtures/definitions/pod-cocoapods---softbutton-0.1.0.json diff --git a/tools/integration/test/testConfig.js b/tools/integration/test/testConfig.js index 9721659..d720645 100644 --- a/tools/integration/test/testConfig.js +++ b/tools/integration/test/testConfig.js @@ -35,15 +35,9 @@ const components = [ // 'sourcearchive/mavencentral/org.apache.httpcomponents/httpcore/4.1' // Dev and prod have different license and scores. See https://github.com/clearlydefined/crawler/issues/533 ] -//When production response is not available or needs to be corrected, stub response from production service for testing -const expectedResponses = [ - { url: '/definitions/pod/cocoapods/-/SoftButton/0.1.0', response: require('./fixtures/softbutton-0.1.0.json') } -] - module.exports = { devApiBaseUrl, prodApiBaseUrl, - expectedResponses, components, harvest: { poll: { interval: pollingInterval, maxTime: pollingMaxTime },