-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(processor): added indexing feature
- Loading branch information
1 parent
e3b314f
commit 1374ea0
Showing
3 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,103 @@ | ||
import { GitlabFillerProcessor } from './processor'; | ||
import { ConfigReader } from '@backstage/config'; | ||
import { Entity } from '@backstage/catalog-model'; | ||
|
||
// To write tests | ||
describe('Processor', () => { | ||
const config = new ConfigReader({ | ||
integrations: { | ||
gitlab: [ | ||
{ | ||
host: 'gitlab.com', | ||
host: 'my.custom-gitlab.com', | ||
apiBaseUrl: 'https://my.custom-gitlab.com/api/v4', | ||
}, | ||
{ | ||
host: 'my.second-custom-gitlab.com', | ||
apiBaseUrl: 'https://my.second-custom-gitlab.com/api/v4', | ||
}, | ||
], | ||
}, | ||
}); | ||
const processor = new GitlabFillerProcessor(config); | ||
|
||
it('added label', () => { | ||
it('Processor has the correct name', () => { | ||
const processor = new GitlabFillerProcessor(config); | ||
expect(processor.getProcessorName()).toEqual('GitlabFillerProcessor'); | ||
}); | ||
|
||
it('Processor creates the right annotation', async () => { | ||
const processor = new GitlabFillerProcessor(config); | ||
const entity: Entity = { | ||
apiVersion: 'backstage.io/v1alpha1', | ||
kind: 'Component', | ||
metadata: { | ||
name: 'backstage', | ||
}, | ||
}; | ||
await processor.postProcessEntity( | ||
entity, | ||
{ | ||
type: 'url', | ||
target: 'https://my.custom-gitlab.com/backstage/backstage/-/blob/next/catalog.yaml', | ||
}, | ||
() => undefined | ||
); | ||
|
||
expect( | ||
entity.metadata?.annotations?.['gitlab.com/project-slug'] | ||
).toEqual('0@backstage/backstage'); | ||
}); | ||
|
||
it('Processor creates the right old gitlab', async () => { | ||
const processor = new GitlabFillerProcessor(config); | ||
const entity: Entity = { | ||
apiVersion: 'backstage.io/v1alpha1', | ||
kind: 'Component', | ||
metadata: { | ||
name: 'backstage', | ||
}, | ||
}; | ||
await processor.postProcessEntity( | ||
entity, | ||
{ | ||
type: 'url', | ||
target: 'https://my.custom-gitlab.com/backstage/backstage/blob/next/catalog.yaml', | ||
}, | ||
() => undefined | ||
); | ||
|
||
expect( | ||
entity.metadata?.annotations?.['gitlab.com/project-slug'] | ||
).toEqual('0@backstage/backstage'); | ||
}); | ||
|
||
it('The processor does not update annotation if the annotations exist', async () => { | ||
const processor = new GitlabFillerProcessor(config); | ||
const projectId = '3922'; | ||
const entity: Entity = { | ||
apiVersion: 'backstage.io/v1alpha1', | ||
kind: 'Component', | ||
metadata: { | ||
name: 'backstage', | ||
annotations: { | ||
'gitlab.com/project-id': projectId, | ||
}, | ||
}, | ||
}; | ||
await processor.postProcessEntity( | ||
entity, | ||
{ | ||
type: 'url', | ||
target: 'https://my.custom-gitlab.com/backstage/backstage/blob/next/catalog.yaml', | ||
}, | ||
() => undefined | ||
); | ||
|
||
expect( | ||
entity.metadata?.annotations?.['gitlab.com/project-slug'] | ||
).toBeUndefined(); | ||
|
||
expect(entity.metadata?.annotations?.['gitlab.com/project-id']).toEqual( | ||
projectId | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters