Skip to content

Commit

Permalink
Separate integration test from tool test and update Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
qtomlinson committed Apr 29, 2024
1 parent ac2f7a8 commit 15b78d4
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
19 changes: 9 additions & 10 deletions tools/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +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. 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.
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,7 +3,7 @@

const { omit, isEqual } = require('lodash')
const { deepStrictEqual, strictEqual } = require('assert')
const { callFetch, buildPostOpts } = require('../../lib/fetch')
const { callFetch, buildPostOpts } = require('../../../lib/fetch')
const { devApiBaseUrl, prodApiBaseUrl, components, definition } = require('../testConfig')
const nock = require('nock')
const fs = require('fs')
Expand Down Expand Up @@ -123,7 +123,7 @@ async function findDefinition(coordinates) {
}

function loadFixtures() {
const location = 'test/fixtures/definitions'
const location = 'test/integration/fixtures/definitions'
return fs
.readdirSync(location)
.filter(f => f.endsWith('.json'))
Expand Down
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
File renamed without changes.
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

0 comments on commit 15b78d4

Please sign in to comment.