Skip to content

Commit

Permalink
Merge pull request #83 from yashkohli88/yk/notices-tests
Browse files Browse the repository at this point in the history
Expanded Integration Test suite with New Test Cases for Notices API
  • Loading branch information
qtomlinson authored Jul 24, 2024
2 parents 9868ee7 + 6ed7757 commit 2b1c2cd
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
59 changes: 59 additions & 0 deletions tools/integration/test/integration/e2e-test-service/noticeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

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

describe('Validate notice files between dev and prod', function () {
this.timeout(definition.timeout)

//Rest a bit to avoid overloading the servers
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2)))

before(() => {
loadFixtures().forEach(([coordinatesString, notice]) => {
nock(prodApiBaseUrl, { allowUnmocked: true })
.post('/notices', { coordinates: [coordinatesString] })
.reply(200, notice)
})
})

components.forEach(coordinates => {
it(`should return the same notice as prod for ${coordinates}`, () => fetchAndCompareNotices(coordinates))
})
})

async function fetchAndCompareNotices(coordinates) {
const [computedNotice, expectedNotice] = await Promise.all(
[
callFetch(
`${devApiBaseUrl}/notices`,
buildPostOpts({
coordinates: [coordinates]
})
),
callFetch(
`${prodApiBaseUrl}/notices`,
buildPostOpts({
coordinates: [coordinates]
})
)
].map(p => p.then(r => r.json()))
)
deepStrictEqual(computedNotice, expectedNotice)
}

function loadFixtures() {
const location = 'test/integration/fixtures/notices'
return fs
.readdirSync(location)
.filter(f => f.endsWith('.json'))
.map(jsonFile => {
const notice = JSON.parse(fs.readFileSync(`${location}/${jsonFile}`))
const coordinatesString = jsonFile.replaceAll('-', '/').replaceAll('///', '/-/').replace('.json', '')
return [coordinatesString, notice]
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"content": "** ratatui; version 0.26.0 -- https://ratatui.rs\nCopyright (c) 2016-2022 Florian Dehau\nCopyright (c) 2023 The Ratatui Developers\n\nThe MIT License (MIT)\n\nCopyright (c) 2016-2022 Florian Dehau\nCopyright (c) 2023 The Ratatui Developers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"summary": {
"total": 1,
"warnings": {
"noDefinition": [],
"noLicense": [],
"noCopyright": []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"content": "** sdbus; version 0.12.0 -- \nCopyright (C) 2022 igo95862\nCopyright (C) 2023 igo95862\nCopyright (C) 2024 igo95862\nCopyright (c) 2022 igo95862\nCopyright (c) 2023 igo95862\nCopyright (c) 2024 igo95862\nCopyright (C) 2020-2022 igo95862\nCopyright (C) 2020-2023 igo95862\nCopyright (C) 2020-2024 igo95862\nCopyright (c) 2020-2022 igo95862\nCopyright (c) 2020-2023 igo95862\nCopyright (c) 2020-2024 igo95862\nCopyright (C) 2020, 2021 igo95862\nCopyright (c) 2020, 2021 igo95862\ncopyrighted by the Free Software Foundation\nCopyright (c) 1989, 1991 Free Software Foundation, Inc.\nCopyright (c) 1991, 1999 Free Software Foundation, Inc.\n\nGPL-2.0 AND LGPL-2.0-or-later AND LGPL-2.1-or-later",
"summary": {
"total": 1,
"warnings": {
"noDefinition": [],
"noLicense": [],
"noCopyright": []
}
}
}
3 changes: 2 additions & 1 deletion tools/integration/test/integration/testConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const components = [
'composer/packagist/symfony/polyfill-mbstring/v1.28.0',
'pod/cocoapods/-/SoftButton/0.1.0', // Dev and prod have different file counts. See https://github.com/clearlydefined/crawler/issues/529
'deb/debian/-/mini-httpd/1.30-0.2_arm64',
'debsrc/debian/-/mini-httpd/1.30-0.2'
'debsrc/debian/-/mini-httpd/1.30-0.2',
'pod/cocoapods/-/xcbeautify/0.9.1'
// 'sourcearchive/mavencentral/org.apache.httpcomponents/httpcore/4.1' // Dev and prod have different license and scores. See https://github.com/clearlydefined/crawler/issues/533
]

Expand Down

0 comments on commit 2b1c2cd

Please sign in to comment.