Skip to content

Commit

Permalink
fix: build.recreate should also check the string version of true/false (
Browse files Browse the repository at this point in the history
#297)

fixes #295
  • Loading branch information
lholmquist committed Mar 25, 2019
1 parent fa79166 commit 140b13a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function createOrUpdateBuildConfig (config) {
}

// There is a buildConfig, check our "recreate" option if we need to delete and re-create
if (config.build && (config.build.recreate === true || config.build.recreate === 'buildConfig')) {
if (config.build && (config.build.recreate === true || config.build.recreate === 'true' || config.build.recreate === 'buildConfig')) {
logger.info(`Recreate option is enabled`);

await removeBuildsAndBuildConfig(config);
Expand Down
2 changes: 1 addition & 1 deletion lib/image-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function createOrUpdateImageStream (config) {
return config.openshiftRestClient.imagestreams.create(createImageStream(config));
}

if (config.build && (config.build.recreate === true || config.build.recreate === 'imageStream')) {
if (config.build && (config.build.recreate === true || config.build.recreate === 'true' || config.build.recreate === 'imageStream')) {
logger.info('Recreate option is enabled');

await removeImageStream(config);
Expand Down
61 changes: 61 additions & 0 deletions test/build-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,64 @@ test('build recreate true with removing builds', (t) => {
t.end();
});
});

test('build recreate true with removing builds with "true"', (t) => {
t.plan(4);
const returnedBuilds = [
{
kind: 'Build',
metadata: {
name: 'build1'
}
},
{
kind: 'Build',
metadata: {
name: 'build2'
}
}
];

const config = {
build: {
recreate: 'true'
},
buildName: 'nodejs-s2i-build',
projectName: 'project-name',
version: '1.0.0',
context: {
namespace: ''
},
openshiftRestClient: {
builds: {
findAll: () => {
t.pass();
return Promise.resolve({ items: returnedBuilds });
},
remove: (buildName) => {
t.pass();
return Promise.resolve();
}
},
buildconfigs: {
find: (buildName) => {
return Promise.resolve({ code: 200 });
},
remove: (buildName, options) => {
return Promise.resolve();
},
create: (buildConfig) => {
return Promise.resolve(buildConfig);
}
}
}
};

const buildConfig = proxyquire('../lib/build-config', {
});

buildConfig.createOrUpdateBuildConfig(config).then((buildConfig) => {
t.pass();
t.end();
});
});
38 changes: 38 additions & 0 deletions test/image-stream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,41 @@ test('imagestream recreate true', (t) => {
t.end();
});
});

test('imagestream recreate true with "true"', (t) => {
t.plan(2);

const config = {
build: {
recreate: 'true'
},
buildName: 'nodejs-s2i-build',
projectName: 'project-name',
version: '1.0.0',
context: {
namespace: ''
},
openshiftRestClient: {
imagestreams: {
find: (imageStreamName) => {
return Promise.resolve({ code: 200 });
},
remove: (imageStreamName, options) => {
t.pass();
return Promise.resolve();
},
create: (imageStreamName) => {
return Promise.resolve(imageStreamName);
}
}
}
};

const imageStream = proxyquire('../lib/image-stream', {
});

imageStream.createOrUpdateImageStream(config).then((imageStream) => {
t.pass();
t.end();
});
});

0 comments on commit 140b13a

Please sign in to comment.