diff --git a/features/metadata.feature b/features/metadata.feature index e2cb61470..1929d76b2 100644 --- a/features/metadata.feature +++ b/features/metadata.feature @@ -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": } to metadata in the "main" build container And the build succeeded + Then add the { "foo": } to metadata in the "main" build container And the "BAR" job is started Then in the build, the { "foo": } is available from metadata - And add the { "bar": } to metadata in the "BAR" build container And the build succeeded + And add the { "bar": } to metadata in the "BAR" build container And the "BAZ" job is started + And the build succeeded Then in the build, the { "foo": } is available from metadata And in the build, the { "bar": } 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": } is available from metadata + And in the build, the { "bar": } 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": } is available from metadata + And in the build, the { "bar": } 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": } 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": } is available from metadata Examples: | foobar | barbaz | diff --git a/features/step_definitions/events.js b/features/step_definitions/events.js index 714de8c0a..4194b9bdb 100644 --- a/features/step_definitions/events.js +++ b/features/step_definitions/events.js @@ -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: { diff --git a/features/step_definitions/metadata.js b/features/step_definitions/metadata.js index cf0d8e6a7..26a991b63 100644 --- a/features/step_definitions/metadata.js +++ b/features/step_definitions/metadata.js @@ -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'); @@ -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': @@ -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; }); }); @@ -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`, @@ -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; + }); +});