Skip to content

Commit 2bac861

Browse files
VonnyJaptkyi
andauthored
feat(3234): Improve metadata functional tests (#3236)
Co-authored-by: Tiffany K <tiffanykyi@gmail.com>
1 parent 2815209 commit 2bac861

3 files changed

Lines changed: 113 additions & 9 deletions

File tree

‎features/metadata.feature‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,42 @@ Feature: Metadata
3838

3939
Scenario Outline: Adding some data to metadata
4040
Given an existing pipeline with the workflow:
41-
| job | triggers |
42-
| main | BAR |
43-
| BAR | BAZ |
41+
| job | triggers |
42+
| main | BAR |
43+
| BAR | BAZ |
44+
| BAZ | BOOZ |
45+
| BAM | |
46+
Then the BOOZ job is "disabled"
4447
When the "main" job is started
45-
Then add the { "foo": <foobar> } to metadata in the "main" build container
4648
And the build succeeded
49+
Then add the { "foo": <foobar> } to metadata in the "main" build container
4750
And the "BAR" job is started
4851
Then in the build, the { "foo": <foobar> } is available from metadata
49-
And add the { "bar": <barbaz> } to metadata in the "BAR" build container
5052
And the build succeeded
53+
And add the { "bar": <barbaz> } to metadata in the "BAR" build container
5154
And the "BAZ" job is started
55+
And the build succeeded
5256
Then in the build, the { "foo": <foobar> } is available from metadata
5357
And in the build, the { "bar": <barbaz> } is available from metadata
54-
And the build succeeded
5558
And the event is done
5659
Then a record of the metadata is stored
60+
When the detached "BAM" job is started
61+
And the build succeeded
62+
Then in the build, the { "foo": <foobar> } is available from metadata
63+
And in the build, the { "bar": <barbaz> } is available from metadata
64+
When the BOOZ job is "enabled"
65+
Then the "BOOZ" job is started
66+
And the build succeeded
67+
Then in the build, the { "foo": <foobar> } is available from metadata
68+
And in the build, the { "bar": <barbaz> } is available from metadata
69+
When the "main" job is restarted
70+
And the build succeeded
71+
Then in the build, the { "foo": "foobarfoobar" } is available from metadata
72+
And in the build, the { "bar": <barbaz> } is available from metadata
73+
And the "BAR" job is started
74+
And the build succeeded
75+
Then in the build, the { "foo": "foobarfoobar" } is available from metadata
76+
And in the build, the { "bar": <barbaz> } is available from metadata
5777

5878
Examples:
5979
| foobar | barbaz |

‎features/step_definitions/events.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ When(/^the "main" job is restarted$/, { timeout: TIMEOUT }, function step() {
6161
json: {
6262
pipelineId: this.pipelineId,
6363
parentEventId: this.previousEventId,
64+
groupEventId: this.previousEventId,
6465
startFrom: 'main'
6566
},
6667
context: {

‎features/step_definitions/metadata.js‎

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

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

@@ -16,13 +16,50 @@ Before(
1616
this.repoName = 'functional-metadata';
1717
this.pipelineId = null;
1818
this.eventId = null;
19+
this.previousEventId = null;
1920
this.meta = null;
21+
this.buildMeta = null;
2022
this.jwt = null;
2123
}
2224
);
2325

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

28+
When(/^the BOOZ job is "(disabled|enabled)"$/, { timeout: TIMEOUT }, function step(jobState) {
29+
const jobName = 'fourth';
30+
31+
return request({
32+
url: `${this.instance}/${this.namespace}/pipelines/${this.pipelineId}/jobs?jobName=${jobName}`,
33+
method: 'GET',
34+
context: {
35+
token: this.jwt
36+
}
37+
})
38+
.then(resp => {
39+
Assert.equal(resp.statusCode, 200);
40+
Assert.equal(resp.body.length, 1);
41+
Assert.equal(resp.body[0].name, jobName);
42+
43+
return resp.body[0].id;
44+
})
45+
.then(jobId => {
46+
return request({
47+
url: `${this.instance}/${this.namespace}/jobs/${jobId}`,
48+
method: 'PUT',
49+
json: {
50+
state: jobState.toUpperCase(),
51+
stateChangeMessage: `${jobState} for testing`
52+
},
53+
context: {
54+
token: this.jwt
55+
}
56+
});
57+
})
58+
.then(resp => {
59+
Assert.equal(resp.statusCode, 200);
60+
});
61+
});
62+
2663
Then(/^the "(BAR|BAZ)" job is started$/, { timeout: TIMEOUT }, function step(jobName) {
2764
switch (jobName) {
2865
case 'BAR':
@@ -46,6 +83,8 @@ Then(/^the "(BAR|BAZ)" job is started$/, { timeout: TIMEOUT }, function step(job
4683
})
4784
.then(build => {
4885
this.buildId = build.id;
86+
this.eventId = build.eventId;
87+
this.previousEventId = build.eventId;
4988
});
5089
});
5190

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

57-
Then(/^in the build, the { "(?:.*)": "(?:.*)" } is available from metadata$/, () => null);
58-
5996
Then(/^the build succeeded$/, { timeout: TIMEOUT }, function step() {
6097
return this.waitForBuild(this.buildId).then(resp => {
98+
this.buildMeta = resp.body.meta;
6199
Assert.equal(resp.body.status, 'SUCCESS');
62100
Assert.equal(resp.statusCode, 200);
63101
});
64102
});
65103

104+
Then(/^in the build, the { "(.*)": "(.*)" } is available from metadata$/, function step(key, value) {
105+
Assert.equal(this.buildMeta[key], value);
106+
});
107+
66108
Then(/^the event is done$/, { timeout: TIMEOUT }, function step() {
67109
return request({
68110
url: `${this.instance}/${this.namespace}/jobs/${this.thirdJobId}/builds`,
@@ -85,3 +127,44 @@ Then(/^a record of the metadata is stored$/, { timeout: TIMEOUT }, function step
85127
Assert.equal(this.meta[key], this.expectedMeta[key]);
86128
});
87129
});
130+
131+
When(/^the (detached )?"(BAM|BOOZ)" job is started$/, { timeout: TIMEOUT }, function step(detached, jobName) {
132+
let startFrom = jobName;
133+
134+
if (detached) {
135+
startFrom = 'detached';
136+
} else {
137+
startFrom = 'fourth';
138+
}
139+
140+
return request({
141+
url: `${this.instance}/${this.namespace}/events`,
142+
method: 'POST',
143+
json: {
144+
pipelineId: this.pipelineId,
145+
startFrom,
146+
parentEventId: this.previousEventId,
147+
groupEventId: this.previousEventId
148+
},
149+
context: {
150+
token: this.jwt
151+
}
152+
})
153+
.then(resp => {
154+
Assert.equal(resp.statusCode, 201);
155+
this.eventId = resp.body.id;
156+
})
157+
.then(() =>
158+
request({
159+
url: `${this.instance}/${this.namespace}/events/${this.eventId}/builds`,
160+
method: 'GET',
161+
context: {
162+
token: this.jwt
163+
}
164+
})
165+
)
166+
.then(resp => {
167+
Assert.equal(resp.statusCode, 200);
168+
this.buildId = resp.body[0].id;
169+
});
170+
});

0 commit comments

Comments
 (0)