-
Notifications
You must be signed in to change notification settings - Fork 0
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
Updated testcases related to Origins API #2
base: main
Are you sure you want to change the base?
Changes from 2 commits
37ddc9b
ac4ff44
f14fdb5
a99f7cd
df1c517
b5defbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
const assert = require('assert') | ||
const { callFetch } = require('../../../lib/fetch') | ||
const { devApiBaseUrl, prodApiBaseUrl, getComponents, definition } = require('../testConfig') | ||
|
||
const ORIGIN_EXCLUSION_LIST = ['go/golang', 'debsrc/debian', 'maven/mavengoogle'] | ||
const ORIGIN_REVISIONS_EXCLUSION_LIST = ['debsrc/debian'] | ||
|
||
const MAVEN_COMPONENT_GROUP_ID = 'maven/mavencentral/org.apache.httpcomponents' | ||
const MAVEN_COMPONENT_PARTIAL_GROUP_ID = 'maven/mavencentral/org.apache.httpcompon' | ||
const GRADLE_COMPONENT_ENDPOINT = 'gradleplugin/io.github.lognet.grpc-spring-boot' | ||
|
||
;(async function validateOriginsApi() { | ||
const components = await getComponents() | ||
|
||
describe('Validate Origins API Between Dev and Prod', function () { | ||
this.timeout(definition.timeout) | ||
|
||
afterEach(() => new Promise(resolve => setTimeout(resolve, definition.timeout / 2))) | ||
|
||
components.filter(isOriginAllowed).forEach(component => { | ||
it(`Validates Origins API response for ${component}`, () => compareOrigins(component)) | ||
}) | ||
|
||
components.filter(isOriginWithRevisionsAllowed).forEach(component => { | ||
it(`Validates Origins API response with revisions for ${component}`, () => compareOriginsWithRevisions(component)) | ||
}) | ||
|
||
it('Validates Origins API response for a Maven component with only a group ID', () => | ||
compareOrigins(MAVEN_COMPONENT_GROUP_ID)) | ||
|
||
it('Validates Origins API response for a Maven component with a partial group ID for suggestion checks', () => | ||
compareOrigins(MAVEN_COMPONENT_PARTIAL_GROUP_ID)) | ||
|
||
it('Validates Origins API response for a Gradle plugin component', () => | ||
compareEndpoints(GRADLE_COMPONENT_ENDPOINT)) | ||
|
||
it('Validates Origins API with revisions response for a Gradle plugin component', () => | ||
compareEndpoints(`${GRADLE_COMPONENT_ENDPOINT}/revisions`)) | ||
}) | ||
})() | ||
|
||
function extractIds(response) { | ||
return response.map(item => item.id) | ||
} | ||
|
||
function assertResponsesMatch(actual, expected) { | ||
const sortedActualIds = extractIds(actual).sort() | ||
const sortedExpectedIds = extractIds(expected).sort() | ||
|
||
assert.deepStrictEqual(sortedActualIds, sortedExpectedIds) | ||
} | ||
|
||
function isCoordinateAllowed(coordinate, exclusionList) { | ||
return !exclusionList.some(excluded => coordinate.includes(excluded)) | ||
} | ||
|
||
function isOriginAllowed(coordinate) { | ||
return isCoordinateAllowed(coordinate, ORIGIN_EXCLUSION_LIST) | ||
} | ||
|
||
function isOriginWithRevisionsAllowed(coordinate) { | ||
return isCoordinateAllowed(coordinate, ORIGIN_REVISIONS_EXCLUSION_LIST) | ||
} | ||
|
||
function getProviderType(type, provider) { | ||
switch (type) { | ||
case 'git': | ||
return 'github' | ||
case 'gem': | ||
return 'rubygems' | ||
case 'conda': | ||
return `conda/${provider}` | ||
case 'maven': | ||
return provider === 'mavengoogle' ? provider : type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about maven for mavencentral, mavengoogle and gradleplugin is the same as provider? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you think? |
||
default: | ||
return type | ||
} | ||
} | ||
|
||
function parseCoordinates(coordinates) { | ||
const [type, provider, namespaceOrEmpty, name, version] = coordinates.split('/') | ||
const namespace = namespaceOrEmpty === '-' ? '' : namespaceOrEmpty | ||
return { type, provider, namespace, name, version } | ||
} | ||
|
||
function buildCondaUrl(coordinates) { | ||
const { type, provider, name } = parseCoordinates(coordinates) | ||
return `${type}/${provider}/${name}` | ||
} | ||
|
||
function buildOriginUrl(coordinates) { | ||
const { type, provider, namespace, name } = parseCoordinates(coordinates) | ||
const resolvedType = getProviderType(type, provider) | ||
return `${resolvedType}${namespace ? `/${namespace}` : ''}${name ? `/${name}` : ''}` | ||
} | ||
|
||
async function compareEndpoints(endpoint) { | ||
const [devResponse, prodResponse] = await Promise.all([ | ||
callFetch(`${devApiBaseUrl}/origins/${endpoint}`).then(res => res.json()), | ||
callFetch(`${prodApiBaseUrl}/origins/${endpoint}`).then(res => res.json()) | ||
]) | ||
assertResponsesMatch(devResponse, prodResponse) | ||
} | ||
|
||
async function compareOriginsWithRevisions(coordinates) { | ||
const originUrl = buildOriginUrl(coordinates) | ||
compareEndpoints(`${originUrl}/revisions`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. await needs to be added |
||
} | ||
|
||
async function compareOrigins(coordinates) { | ||
const originUrl = coordinates.startsWith('conda/') ? buildCondaUrl(coordinates) : buildOriginUrl(coordinates) | ||
compareEndpoints(`${originUrl}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. await needs to be added |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have to separate gradle components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have used separate test cases for gradle since the endpoint for it is origins/gradleplugin/:pluginID where pluginID is not consistent with the name of group id or artefact id like
Here is the case where pluginId is combination of group id and artefact id
https://plugins.gradle.org/plugin/io.outfoxx.sunday-generator
https://mvnrepository.com/artifact/io.outfoxx.sunday/generator
Here is the case where pluginId is only group id -
https://plugins.gradle.org/plugin/io.github.lognet.grpc-spring-boot
https://mvnrepository.com/artifact/io.github.lognet.grpc-spring-boot/io.github.lognet.grpc-spring-boot.gradle.plugin
Please let me know if I could handle this better. Most of the cases corresponds pluginId to group id. In that case we would also need to add another buildurl function for gradleplugin.