Skip to content

Commit

Permalink
feat(3234): Improve metadata functional tests (#3236)
Browse files Browse the repository at this point in the history
Co-authored-by: Tiffany K <[email protected]>
  • Loading branch information
VonnyJap and tkyi authored Nov 6, 2024
1 parent 2815209 commit 2bac861
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 9 deletions.
32 changes: 26 additions & 6 deletions features/metadata.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,42 @@ Feature: Metadata

Scenario Outline: Adding some data to metadata
Given an existing pipeline with the workflow:
| job | triggers |
| main | BAR |
| BAR | BAZ |
| job | triggers |
| main | BAR |
| BAR | BAZ |
| BAZ | BOOZ |
| BAM | |
Then the BOOZ job is "disabled"
When the "main" job is started
Then add the { "foo": <foobar> } to metadata in the "main" build container
And the build succeeded
Then add the { "foo": <foobar> } to metadata in the "main" build container
And the "BAR" job is started
Then in the build, the { "foo": <foobar> } is available from metadata
And add the { "bar": <barbaz> } to metadata in the "BAR" build container
And the build succeeded
And add the { "bar": <barbaz> } to metadata in the "BAR" build container
And the "BAZ" job is started
And the build succeeded
Then in the build, the { "foo": <foobar> } is available from metadata
And in the build, the { "bar": <barbaz> } is available from metadata
And the build succeeded
And the event is done
Then a record of the metadata is stored
When the detached "BAM" job is started
And the build succeeded
Then in the build, the { "foo": <foobar> } is available from metadata
And in the build, the { "bar": <barbaz> } is available from metadata
When the BOOZ job is "enabled"
Then the "BOOZ" job is started
And the build succeeded
Then in the build, the { "foo": <foobar> } is available from metadata
And in the build, the { "bar": <barbaz> } is available from metadata
When the "main" job is restarted
And the build succeeded
Then in the build, the { "foo": "foobarfoobar" } is available from metadata
And in the build, the { "bar": <barbaz> } is available from metadata
And the "BAR" job is started
And the build succeeded
Then in the build, the { "foo": "foobarfoobar" } is available from metadata
And in the build, the { "bar": <barbaz> } is available from metadata

Examples:
| foobar | barbaz |
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ When(/^the "main" job is restarted$/, { timeout: TIMEOUT }, function step() {
json: {
pipelineId: this.pipelineId,
parentEventId: this.previousEventId,
groupEventId: this.previousEventId,
startFrom: 'main'
},
context: {
Expand Down
89 changes: 86 additions & 3 deletions features/step_definitions/metadata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Assert = require('chai').assert;
const { Before, Given, Then } = require('@cucumber/cucumber');
const { Before, Given, Then, When } = require('@cucumber/cucumber');
const request = require('screwdriver-request');
const sdapi = require('../support/sdapi');

Expand All @@ -16,13 +16,50 @@ Before(
this.repoName = 'functional-metadata';
this.pipelineId = null;
this.eventId = null;
this.previousEventId = null;
this.meta = null;
this.buildMeta = null;
this.jwt = null;
}
);

Given(/^a metadata starts with an empty object$/, { timeout: TIMEOUT }, () => null);

When(/^the BOOZ job is "(disabled|enabled)"$/, { timeout: TIMEOUT }, function step(jobState) {
const jobName = 'fourth';

return request({
url: `${this.instance}/${this.namespace}/pipelines/${this.pipelineId}/jobs?jobName=${jobName}`,
method: 'GET',
context: {
token: this.jwt
}
})
.then(resp => {
Assert.equal(resp.statusCode, 200);
Assert.equal(resp.body.length, 1);
Assert.equal(resp.body[0].name, jobName);

return resp.body[0].id;
})
.then(jobId => {
return request({
url: `${this.instance}/${this.namespace}/jobs/${jobId}`,
method: 'PUT',
json: {
state: jobState.toUpperCase(),
stateChangeMessage: `${jobState} for testing`
},
context: {
token: this.jwt
}
});
})
.then(resp => {
Assert.equal(resp.statusCode, 200);
});
});

Then(/^the "(BAR|BAZ)" job is started$/, { timeout: TIMEOUT }, function step(jobName) {
switch (jobName) {
case 'BAR':
Expand All @@ -46,6 +83,8 @@ Then(/^the "(BAR|BAZ)" job is started$/, { timeout: TIMEOUT }, function step(job
})
.then(build => {
this.buildId = build.id;
this.eventId = build.eventId;
this.previousEventId = build.eventId;
});
});

Expand All @@ -54,15 +93,18 @@ Then(/^add the { "(.*)": "(.*)" } to metadata/, function step(key, value) {
this.expectedMeta[key] = value;
});

Then(/^in the build, the { "(?:.*)": "(?:.*)" } is available from metadata$/, () => null);

Then(/^the build succeeded$/, { timeout: TIMEOUT }, function step() {
return this.waitForBuild(this.buildId).then(resp => {
this.buildMeta = resp.body.meta;
Assert.equal(resp.body.status, 'SUCCESS');
Assert.equal(resp.statusCode, 200);
});
});

Then(/^in the build, the { "(.*)": "(.*)" } is available from metadata$/, function step(key, value) {
Assert.equal(this.buildMeta[key], value);
});

Then(/^the event is done$/, { timeout: TIMEOUT }, function step() {
return request({
url: `${this.instance}/${this.namespace}/jobs/${this.thirdJobId}/builds`,
Expand All @@ -85,3 +127,44 @@ Then(/^a record of the metadata is stored$/, { timeout: TIMEOUT }, function step
Assert.equal(this.meta[key], this.expectedMeta[key]);
});
});

When(/^the (detached )?"(BAM|BOOZ)" job is started$/, { timeout: TIMEOUT }, function step(detached, jobName) {
let startFrom = jobName;

if (detached) {
startFrom = 'detached';
} else {
startFrom = 'fourth';
}

return request({
url: `${this.instance}/${this.namespace}/events`,
method: 'POST',
json: {
pipelineId: this.pipelineId,
startFrom,
parentEventId: this.previousEventId,
groupEventId: this.previousEventId
},
context: {
token: this.jwt
}
})
.then(resp => {
Assert.equal(resp.statusCode, 201);
this.eventId = resp.body.id;
})
.then(() =>
request({
url: `${this.instance}/${this.namespace}/events/${this.eventId}/builds`,
method: 'GET',
context: {
token: this.jwt
}
})
)
.then(resp => {
Assert.equal(resp.statusCode, 200);
this.buildId = resp.body[0].id;
});
});

0 comments on commit 2bac861

Please sign in to comment.