Skip to content

Commit

Permalink
Fix formatting in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qtomlinson committed Nov 18, 2024
1 parent 05dd832 commit a83fe72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
2 changes: 2 additions & 0 deletions test/providers/store/abstractFileStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ describe('getLatestToolVersions', () => {
'maven/mavencentral/org.apache.httpcomponents/httpcore/revision/4.4.16/tool/scancode/32.3.0.json'
])
})

it('should get latest tool versions and ignore un-versioned data', () => {
const latest = AbstractFileStore.getLatestToolPaths([
'npm/npmjs/-/co/revision/4.6.0/tool/clearlydefined/1.json',
Expand All @@ -230,6 +231,7 @@ describe('getLatestToolVersions', () => {
'npm/npmjs/-/co/revision/4.6.0/tool/scancode/2.9.2.json'
])
})

it('should get latest tool versions and ignore invalid semver', () => {
const latest = AbstractFileStore.getLatestToolPaths([
'npm/npmjs/-/debug/revision/3.1.0/tool/clearlydefined/1.5.0.json',
Expand Down
37 changes: 13 additions & 24 deletions test/providers/store/azblobHarvest.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('azblob Harvest store', () => {
'maven/mavencentral/org.apache.httpcomponents/httpcore/revision/4.4.16/tool/scancode/32.3.0.json'
])
})

it('retrieves latest entries', async () => {
const azblobStore = createAzBlobStore(
createEntries([
Expand All @@ -209,16 +210,13 @@ describe('azblob Harvest store', () => {
revision: '4.4.16'
})

const tools = Object.getOwnPropertyNames(result)
expect(tools.length).to.eq(4)
const clearlydefinedVersions = Object.getOwnPropertyNames(result.clearlydefined)
expect(clearlydefinedVersions).to.deep.eq(['1.5.0'])
const scancodeVersions = Object.getOwnPropertyNames(result.scancode)
expect(scancodeVersions).to.deep.eq(['32.3.0'])
const licenseeVersions = Object.getOwnPropertyNames(result.licensee)
expect(licenseeVersions).to.deep.eq(['9.18.1'])
const reuseVersions = Object.getOwnPropertyNames(result.reuse)
expect(reuseVersions).to.deep.eq(['3.2.2'])
const exptected = {
clearlydefined: { '1.5.0': {} },
licensee: { '9.18.1': {} },
reuse: { '3.2.2': {} },
scancode: { '32.3.0': {} }
}
expect(result).to.deep.equal(exptected)
})

it('retrieves latest entries ignoring unversioned result', async () => {
Expand All @@ -240,15 +238,11 @@ describe('azblob Harvest store', () => {
name: 'co',
revision: '4.6.0'
})
const tools = Object.getOwnPropertyNames(result)
expect(tools.length).to.eq(2)
const clearlydefinedVersions = Object.getOwnPropertyNames(result.clearlydefined)
expect(clearlydefinedVersions).to.deep.eq(['1'])
const scancodeVersions = Object.getOwnPropertyNames(result.scancode)
expect(scancodeVersions).to.deep.eq(['2.9.2'])
const exptected = { clearlydefined: { 1: {} }, scancode: { '2.9.2': {} } }
expect(result).to.deep.equal(exptected)
})

it('should fall back to getAll when there is no latest', async () => {
it('should fall back to getAll when there is error', async () => {
const azblobStore = createAzBlobStore(
createEntries([
'npm/npmjs/-/co/revision/4.6.0/tool/clearlydefined/1.json',
Expand All @@ -266,13 +260,8 @@ describe('azblob Harvest store', () => {
name: 'co',
revision: '4.6.0'
})
const tools = Object.getOwnPropertyNames(result)
expect(tools.length).to.eq(2)
const clearlydefinedVersions = Object.getOwnPropertyNames(result.clearlydefined)
expect(clearlydefinedVersions).to.deep.eq(['1'])
const scancodeVersions = Object.getOwnPropertyNames(result.scancode)
expect(scancodeVersions).to.deep.eq(['2.2.1', '2.9.1', '2.9.0b1'])
expect(azblobStore.logger.error.calledOnce).to.be.true
const exptected = { clearlydefined: { 1: {} }, scancode: { '2.2.1': {}, '2.9.1': {}, '2.9.0b1': {} } }
expect(result).to.deep.equal(exptected)
})
})
})
Expand Down
42 changes: 21 additions & 21 deletions test/providers/store/fileHarvest.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('FileHarvestStore list tool results', () => {
})
})

describe('getLatestFiles', () => {
describe('getAll and getAllLatest', () => {
const allFiles = [
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/clearlydefined/1.3.1.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/clearlydefined/1.4.1.json',
Expand All @@ -96,26 +96,6 @@ describe('getLatestFiles', () => {
fileStore = createFileHarvestStore()
})

it('should get latest files', () => {
const result = fileStore._getLatestFiles(allFiles)
expect(result.length).to.eq(4)
expect(Array.from(result)).to.equalInAnyOrder([
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/clearlydefined/1.4.1.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/licensee/9.18.1.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/reuse/3.2.2.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/scancode/32.3.0.json'
])
})

it('should handle error', () => {
fileStore._getLatestToolVersions = sinon.stub().throws(new Error('test error'))
fileStore.logger.error = sinon.stub()
const result = fileStore._getLatestFiles(allFiles)
expect(fileStore.logger.error.calledOnce).to.be.true
expect(result.length).to.eq(allFiles.length)
expect(Array.from(result)).to.equalInAnyOrder(allFiles)
})

it('should return all harvest results', async () => {
const coordinates = EntityCoordinates.fromString('npm/npmjs/-/debug/3.1.0')
const result = await fileStore.getAll(coordinates)
Expand Down Expand Up @@ -149,6 +129,26 @@ describe('getLatestFiles', () => {
const fossologyVersions = Object.getOwnPropertyNames(result.fossology)
expect(fossologyVersions).to.equalInAnyOrder(['3.6.0'])
})

it('should get latest files', () => {
const result = fileStore._getLatestFiles(allFiles)
expect(result.length).to.eq(4)
expect(Array.from(result)).to.equalInAnyOrder([
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/clearlydefined/1.4.1.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/licensee/9.18.1.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/reuse/3.2.2.json',
'/tmp/harvested_data/pypi/pypi/-/platformdirs/revision/4.2.0/tool/scancode/32.3.0.json'
])
})

it('should handle error', () => {
fileStore._getLatestToolVersions = sinon.stub().throws(new Error('test error'))
fileStore.logger.error = sinon.stub()
const result = fileStore._getLatestFiles(allFiles)
expect(fileStore.logger.error.calledOnce).to.be.true
expect(result.length).to.eq(allFiles.length)
expect(Array.from(result)).to.equalInAnyOrder(allFiles)
})
})

function createFileHarvestStore() {
Expand Down

0 comments on commit a83fe72

Please sign in to comment.