Added examples for publish:azure action and updated its test cases
Signed-off-by: parmar-abhinav <abhinav.parmar@infosys.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-azure': minor
|
||||
---
|
||||
|
||||
Added examples for publish:azure action and updated its test cases
|
||||
@@ -19,7 +19,10 @@ import { ConfigReader } from '@backstage/config';
|
||||
import { createPublishAzureAction } from './azure';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { WebApi } from 'azure-devops-node-api';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import {
|
||||
getRepoSourceDirectory,
|
||||
initRepoAndPush,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { examples } from './azure.examples';
|
||||
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
|
||||
|
||||
@@ -48,6 +51,10 @@ describe('publish:azure examples', () => {
|
||||
host: 'dev.azure.com',
|
||||
credentials: [{ personalAccessToken: 'tokenlols' }],
|
||||
},
|
||||
{
|
||||
host: 'test.azure.com',
|
||||
credentials: [{ personalAccessToken: 'tokenlols' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -114,4 +121,172 @@ describe('publish:azure examples', () => {
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[3].description}`, async () => {
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
id: '709e891c-dee7-4f91-b963-534713c0737f',
|
||||
});
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[3].example).steps[0].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
...input,
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'notempty', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: input.gitCommitMessage,
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[4].description}`, async () => {
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
id: '709e891c-dee7-4f91-b963-534713c0737f',
|
||||
});
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[4].example).steps[0].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
...input,
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'notempty', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: {
|
||||
name: input.gitAuthorName,
|
||||
email: input.gitAuthorEmail,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[5].description}`, async () => {
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
id: '709e891c-dee7-4f91-b963-534713c0737f',
|
||||
});
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[5].example).steps[0].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
...input,
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: getRepoSourceDirectory(mockContext.workspacePath, input.sourcePath),
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'notempty', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[6].description}`, async () => {
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
id: '709e891c-dee7-4f91-b963-534713c0737f',
|
||||
});
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[6].example).steps[0].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
...input,
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'notempty', password: input.token },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
|
||||
it(`should ${examples[7].description}`, async () => {
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://test.azure.com/organization/project/_git/repo',
|
||||
webUrl: 'https://test.azure.com/organization/project/_git/repo',
|
||||
id: '709e891c-dee7-4f91-b963-534713c0737f',
|
||||
});
|
||||
|
||||
let input;
|
||||
try {
|
||||
input = yaml.parse(examples[7].example).steps[0].input;
|
||||
} catch (error) {
|
||||
console.error('Failed to parse YAML:', error);
|
||||
}
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
...input,
|
||||
},
|
||||
});
|
||||
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://test.azure.com/organization/project/_git/repo',
|
||||
defaultBranch: 'master',
|
||||
auth: { username: 'notempty', password: 'tokenlols' },
|
||||
logger: mockContext.logger,
|
||||
commitMessage: 'initial commit',
|
||||
gitAuthorInfo: {},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,4 +70,94 @@ export const examples: TemplateExample[] = [
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
description:
|
||||
'Initializes an Azure DevOps repository with a custom commit message',
|
||||
example: yaml.stringify({
|
||||
steps: [
|
||||
{
|
||||
id: 'publish',
|
||||
action: 'publish:azure',
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
gitCommitMessage: 'Initial setup and configuration',
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
description:
|
||||
'Initializes an Azure DevOps repository with a custom author name and email',
|
||||
example: yaml.stringify({
|
||||
steps: [
|
||||
{
|
||||
id: 'publish',
|
||||
action: 'publish:azure',
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
gitAuthorName: 'John Doe',
|
||||
gitAuthorEmail: 'john.doe@example.com',
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
description:
|
||||
'Initializes an Azure DevOps repository using a specific source path',
|
||||
example: yaml.stringify({
|
||||
steps: [
|
||||
{
|
||||
id: 'publish',
|
||||
action: 'publish:azure',
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
sourcePath: 'path/to/source',
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
description:
|
||||
'Initializes an Azure DevOps repository using an authentication token',
|
||||
example: yaml.stringify({
|
||||
steps: [
|
||||
{
|
||||
id: 'publish',
|
||||
action: 'publish:azure',
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'dev.azure.com?organization=organization&project=project&repo=repo',
|
||||
token: 'personal-access-token',
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
description:
|
||||
'Initializes an Azure DevOps repository using an custom repo url',
|
||||
example: yaml.stringify({
|
||||
steps: [
|
||||
{
|
||||
id: 'publish',
|
||||
action: 'publish:azure',
|
||||
name: 'Publish to Azure',
|
||||
input: {
|
||||
repoUrl:
|
||||
'test.azure.com?organization=organization&project=project&repo=repo',
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user