Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize fixtures for autoloading #73

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tools/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

## Resources

1. Integration tests are located at ./test to support the integration-test.yml GitHub Action.
1. To execute integration tests, you can use the integration-test.yml GitHub Action. When running on the main branch, all tests committed to that branch will be executed. By default, the integration test suite compares the results from development with the production deployment. You can find the integration test suite at [./test/integration](./test/integration), and you can configure the development and production deployment in [./test/integration/testConfig.js](./test/integration/testConfig.js).
1. npm scripts triggered in the GitHub Action include:

- e2e-test-harvest: re-triggers harvest for the components in testConfig.js
- e2e-test-service: runs the tests in [./test/e2e-test-service](./test/e2e-test-service) folder.
- e2e-test-harvest: re-triggers and verifies the completion of the harvest for the components specified in [./test/integration/testConfig.js](./test/integration/testConfig.js)
- e2e-test-service: runs the suite of tests in [./test/integration/e2e-test-service](./test/integration/e2e-test-service) folder. These tests are organized based on the endpoints documented in [Swagger UI](https://api.clearlydefined.io/api-docs/#/).

1. The test configuration is located at [./test/testConfig.js](./test/testConfig.js).
1. The test configuration is located at [./test/integration/testConfig.js](./test/integration/testConfig.js).

It contains:

- Components to be harvested,
- Base URLs to the development and production systems, polling interval, and timeout,
- 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.
- Base URLs for the development and production systems, along with polling interval and timeout settings,
- Current harvest schema versions. This is for polling harvest results to check whether the harvest is complete. When scan tool versions are updated, these need to be updated as well.

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.
1. Test fixtures are grouped by endpoints at [./test/integration/fixtures](./test/integration/fixtures). You can use these fixtures to override responses from the production system when necessary.
1. The classes used in the integration tests are located at [./lib](./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](./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.
6 changes: 3 additions & 3 deletions tools/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Integration tests and related tools for ClearlyDefined",
"scripts": {
"test": "npm run mocha && npm run lint",
"e2e-test-harvest": "mocha test/harvestTest.js",
"e2e-test-service": "mocha --exit \"test/e2e-test-service/**/*.js\"",
"e2e-test-harvest": "mocha test/integration/harvestTest.js",
"e2e-test-service": "mocha --exit \"test/integration/e2e-test-service/**/*.js\"",
"mocha": "mocha --exit \"test/lib/**/*.js\"",
"lint": "npm run prettier:check && npm run eslint",
"lint:fix": "npm run prettier:write && npm run eslint:fix",
Expand All @@ -26,4 +26,4 @@
"prettier": "^3.2.5",
"sinon": "^17.0.1"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const { callFetch } = require('../../lib/fetch')
const { callFetch } = require('../../../lib/fetch')
const { devApiBaseUrl, prodApiBaseUrl, components, definition } = require('../testConfig')
const { strictEqual } = require('assert')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT

const { deepStrictEqual, strictEqual, ok } = require('assert')
const { callFetch, buildPostOpts } = require('../../lib/fetch')
const { callFetch, buildPostOpts } = require('../../../lib/fetch')
const { devApiBaseUrl, components, definition } = require('../testConfig')

describe('Validate curation', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

const { omit, isEqual, pick } = require('lodash')
const { deepStrictEqual, strictEqual } = require('assert')
const { callFetch, buildPostOpts } = require('../../lib/fetch')
const { devApiBaseUrl, prodApiBaseUrl, expectedResponses, components, definition } = require('../testConfig')
const { callFetch, buildPostOpts } = require('../../../lib/fetch')
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 @@ -122,3 +123,17 @@ async function findDefinition(coordinates) {
).then(r => r.json())
return response.data.find(d => d.coordinates.revision === revision)
}

function loadFixtures() {
const location = 'test/integration/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]
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: MIT

const { components, devApiBaseUrl, harvest } = require('./testConfig')
const Poller = require('../lib/poller')
const Harvester = require('../lib/harvester')
const Poller = require('../../lib/poller')
const Harvester = require('../../lib/harvester')
const { strictEqual } = require('assert')

describe('Tests for harvesting different components', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,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') },
{
url: '/definitions/conda/conda-forge/linux-aarch64/numpy/1.16.6-py36hdc1b780_0',
response: require('./fixtures/numpy-1.16.6.json')
}
]

module.exports = {
devApiBaseUrl,
prodApiBaseUrl,
expectedResponses,
components,
harvest: {
poll: { interval: pollingInterval, maxTime: pollingMaxTime },
Expand Down
5 changes: 3 additions & 2 deletions tools/integration/test/lib/harvesterTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
const { strictEqual, ok, deepStrictEqual } = require('assert')
const Poller = require('../../lib/poller')
const Harvester = require('../../lib/harvester')
const { devApiBaseUrl, harvestToolVersions } = require('../testConfig')
const sinon = require('sinon')

const devApiBaseUrl = 'localhost:4000'

describe('Tests for Harvester', function () {
const coordinates = 'nuget/nuget/-/NuGet.Protocol/6.7.1'

let harvester
let fetchStub
beforeEach(function () {
fetchStub = sinon.stub()
harvester = new Harvester(devApiBaseUrl, harvestToolVersions, fetchStub)
harvester = new Harvester(devApiBaseUrl, undefined, fetchStub)
})

describe('Verify api calls in harvest and fetchHarvestResult', function () {
Expand Down