Skip to content

Commit

Permalink
Update builder tests and snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
snehajais22 committed Jun 7, 2024
1 parent 767b4d3 commit 1100e37
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 30 deletions.
76 changes: 76 additions & 0 deletions test/__snapshots__/pipelinebuilder.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 30 additions & 23 deletions test/pipelinebuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
TaskBuilder,
WorkspaceBuilder,
fromPipelineParam,
constant
constant,
} from '../src';

class PipelineRunTest extends Chart {
constructor(scope: Construct, id: string, props?: ChartProps) {
super(scope, id, props);

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const myTask = new TaskBuilder(this, 'fetch-source')
.withName('git-clone')
Expand Down Expand Up @@ -45,7 +45,7 @@ class PipelineRunTestWithUndefinedWorkspaceError extends Chart {
super(scope, id, props);

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const myTask = new TaskBuilder(this, 'fetch-source')
.withName('git-clone')
Expand All @@ -72,7 +72,7 @@ class PipelineRunTestWithUndefinedParamError extends Chart {
super(scope, id, props);

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const myTask = new TaskBuilder(this, 'fetch-source')
.withName('git-clone')
Expand Down Expand Up @@ -100,7 +100,7 @@ class PipelineRunTestWithError extends Chart {
super(scope, id, props);

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const myTask = new TaskBuilder(this, 'fetch-source')
.withName('git-clone')
Expand Down Expand Up @@ -128,13 +128,13 @@ class MySecondTestChart extends Chart {
super(scope, id, props);

const repoParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');
const nameParam = new ParameterBuilder('your-name')
.withDefaultValue('')
.withDefaultValue('');
const colorParam = new ParameterBuilder('your-color')
.withDefaultValue('')
.withDefaultValue('');
const questParam = new ParameterBuilder('your-quest')
.withDefaultValue('')
.withDefaultValue('');

const myTask = new TaskBuilder(this, 'git-clone')
.withName('fetch-source')
Expand Down Expand Up @@ -171,9 +171,9 @@ class MyTestChartWithDuplicateParams extends Chart {
const myWorkspace = new WorkspaceBuilder('output')
.withDescription('The files cloned by the task')
.withName('shared-data');

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const urlParam = new ParameterBuilder('url')
.withValue(fromPipelineParam(pipelineParam));
Expand Down Expand Up @@ -206,10 +206,10 @@ class MyTestChartWithStaticOverride extends Chart {
super(scope, id, props);

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const urlParam = new ParameterBuilder('url')
.withValue(fromPipelineParam(pipelineParam));
.withValue(fromPipelineParam(pipelineParam));

const myTask2 = new TaskBuilder(this, 'cat-readme')
.withName('print-readme')
Expand Down Expand Up @@ -237,7 +237,7 @@ class MyTestChartWithDuplicateTasks extends Chart {
.withName('shared-data');

const pipelineParam = new ParameterBuilder('repo-url')
.withDefaultValue('')
.withDefaultValue('');

const urlParam = new ParameterBuilder('url')
.withValue(fromPipelineParam(pipelineParam));
Expand All @@ -263,19 +263,19 @@ class PipelineLevelParamTest extends Chart {
super(scope, id, props);

const pipelineParam = new ParameterBuilder('context')
.withDefaultValue('/some/where/or/other')
.withDefaultValue('/some/where/or/other');

const taskParam = new ParameterBuilder('pathToDockerFile')
.withValue(constant('Dockerfile'))
.withValue(constant('Dockerfile'));

const taskParam2 = new ParameterBuilder('pathToContext')
.withValue(fromPipelineParam(pipelineParam))
.withValue(fromPipelineParam(pipelineParam));

const myTask = new TaskBuilder(this, 'build-skaffold-web')
.withName('build-push')
.withStringParam(taskParam)
.withStringParam(taskParam2)
.withStringParam(taskParam2);

new PipelineBuilder(this, 'pipeline-with-parameters')
.withStringParam(pipelineParam)
.withTask(myTask)
Expand Down Expand Up @@ -342,4 +342,11 @@ describe('PipelineBuilderTest', () => {
const results = Testing.synth(chart);
expect(results).toMatchSnapshot();
});

test('PipelineBuilderWithParameters', () => {
const app = Testing.app();
const chart = new PipelineLevelParamTest(app, 'test-chart');
const results = Testing.synth(chart);
expect(results).toMatchSnapshot();
});
});
18 changes: 11 additions & 7 deletions test/taskbuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';
import { Chart, Testing } from 'cdk8s';
import { ChartProps } from 'cdk8s/lib/chart';
import { Construct } from 'constructs';
import { usingBuildParameter, usingWorkspacePath, secretKeyRef, TaskBuilder, TaskStepBuilder, valueFrom, WorkspaceBuilder, ParameterBuilder } from '../src';
import { usingBuildParameter, usingWorkspacePath, secretKeyRef, TaskBuilder, TaskStepBuilder, valueFrom, WorkspaceBuilder, ParameterBuilder, fromPipelineParam } from '../src';

/**
* Using "ansible-runner" as the reference task that I want this test builder to
Expand All @@ -17,9 +17,11 @@ class TestBasicTaskBuild extends Chart {
const runnerDir = new WorkspaceBuilder('runner-dir')
.withDescription('The Ansibler runner directory');

const pipelineParam = new ParameterBuilder('project-dir');

const projectDirName = new ParameterBuilder('project-dir')
.ofType('string')
.withPiplineParameter('project-dir');
.withValue(fromPipelineParam(pipelineParam));

new TaskBuilder(this, 'my-task')
.withName('ansible-runner')
Expand Down Expand Up @@ -79,9 +81,11 @@ class TestBasicTaskBuildFromObject extends Chart {
const runnerDir = new WorkspaceBuilder('runner-dir')
.withDescription('The Ansibler runner directory');

const pipelineParam = new ParameterBuilder('project-dir');

const projectDirName = new ParameterBuilder('project-dir')
.ofType('string')
.withPiplineParameter('project-dir');
.withValue(fromPipelineParam(pipelineParam));

new TaskBuilder(this, 'my-task')
.withName('ansible-runner')
Expand Down Expand Up @@ -159,16 +163,16 @@ class TestPullRequestTaskBuild extends Chart {
.withName('pull-request')
.withDescription('This Task allows a user to interact with an SCM (source control management)\nsystem through an abstracted interface\n\nThis Task works with both public SCM instances and self-hosted/enterprise GitHub/GitLab\ninstances. In download mode, this Task will look at the state of an existing pull\nrequest and populate the pr workspace with the state of the pull request, including the\n.MANIFEST file. In upload mode, this Task will look at the contents of the pr workspace\n and compare it to the .MANIFEST file (if it exists).')
.withStringParam(new ParameterBuilder('mode')
.withPiplineParameter('mode')
.withValue(fromPipelineParam(new ParameterBuilder('mode')))
.withDescription('If "download", the state of the pull request at `url` will be fetched. If "upload" then the pull request at `url` will be updated.'))
.withStringParam(new ParameterBuilder('url')
.withPiplineParameter('repo-url')
.withValue(fromPipelineParam(new ParameterBuilder('repo-url')))
.withDescription('The URL of the Pull Reuqest, e.g. `https://github.com/bobcatfish/catservice/pull/16`'))
.withStringParam(new ParameterBuilder('provider')
.withPiplineParameter('provider')
.withValue(fromPipelineParam(new ParameterBuilder('provider')))
.withDescription('The type of SCM system, currently `github` or `gitlab`'))
.withStringParam(new ParameterBuilder('secret-key-ref')
.withPiplineParameter('secret-key-ref')
.withValue(fromPipelineParam(new ParameterBuilder('secret-key-ref')))
.withDescription('The name of an opaque secret containing a key called "token" with a base64 encoded SCM token'))
.withStringParam(new ParameterBuilder('insecure-skip-tls-verify')
.withDefaultValue('false')
Expand Down

0 comments on commit 1100e37

Please sign in to comment.