Skip to content

Commit

Permalink
Reorganize fixtures for autoloading
Browse files Browse the repository at this point in the history
Group fixtures by endpoints.  This ensures that the json response format is consistent within the folder, allowing for coordinates parsing.
  • Loading branch information
qtomlinson committed Apr 24, 2024
1 parent dabfc13 commit ac2f7a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions tools/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
29 changes: 22 additions & 7 deletions tools/integration/test/e2e-test-service/definitionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down Expand Up @@ -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]
})
}
6 changes: 0 additions & 6 deletions tools/integration/test/testConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit ac2f7a8

Please sign in to comment.