-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from screwdriver-cd/templatetags
feat(616): Add template tag model
- Loading branch information
Showing
8 changed files
with
304 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const BaseModel = require('./base'); | ||
|
||
class TemplateTagModel extends BaseModel { | ||
/** | ||
* Construct a TemplateTagModel object | ||
* @method constructor | ||
* @param {Object} config | ||
* @param {Object} config.datastore Object that will perform operations on the datastore | ||
* @param {String} config.name The template name | ||
* @param {String} config.tag The template tag (e.g.: 'stable' or 'latest') | ||
* @param {String} config.version Version of the template | ||
*/ | ||
constructor(config) { | ||
super('templateTag', config); | ||
} | ||
|
||
} | ||
|
||
module.exports = TemplateTagModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const BaseFactory = require('./baseFactory'); | ||
const TemplateTag = require('./templateTag'); | ||
let instance; | ||
|
||
class TemplateTagFactory extends BaseFactory { | ||
/** | ||
* Construct a TemplateTagFactory object | ||
* @method constructor | ||
* @param {Object} config | ||
* @param {Datastore} config.datastore Object that will perform operations on the datastore | ||
*/ | ||
constructor(config) { | ||
super('templateTag', config); | ||
} | ||
|
||
/** | ||
* Instantiate a TemplateTag class | ||
* @method createClass | ||
* @param {Object} config Template tag data | ||
* @param {Datastore} config.datastore Object that will perform operations on the datastore | ||
* @param {String} config.name The template name | ||
* @param {String} config.tag The template tag (e.g.: 'stable' or 'latest') | ||
* @param {String} config.version Version of the template | ||
* @return {TemplateTag} | ||
*/ | ||
createClass(config) { | ||
return new TemplateTag(config); | ||
} | ||
|
||
/** | ||
* Get an instance of the TemplateTagFactory | ||
* @method getInstance | ||
* @param {Object} config | ||
* @param {Datastore} config.datastore | ||
* @return {TemplateTagFactory} | ||
*/ | ||
static getInstance(config) { | ||
instance = BaseFactory.getInstance(TemplateTagFactory, instance, config); | ||
|
||
return instance; | ||
} | ||
} | ||
|
||
module.exports = TemplateTagFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
const assert = require('chai').assert; | ||
const sinon = require('sinon'); | ||
const mockery = require('mockery'); | ||
const schema = require('screwdriver-data-schema'); | ||
|
||
sinon.assert.expose(assert, { prefix: '' }); | ||
|
||
describe('TemplateTag Model', () => { | ||
let BaseModel; | ||
let TemplateTagModel; | ||
let datastore; | ||
let createConfig; | ||
let templateTag; | ||
|
||
before(() => { | ||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnUnregistered: false | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
datastore = { | ||
update: sinon.stub() | ||
}; | ||
|
||
// eslint-disable-next-line global-require | ||
BaseModel = require('../../lib/base'); | ||
|
||
// eslint-disable-next-line global-require | ||
TemplateTagModel = require('../../lib/templateTag'); | ||
|
||
createConfig = { | ||
datastore, | ||
id: 12345, | ||
name: 'testTemplateTag', | ||
tag: 'latest', | ||
version: '1.3' | ||
}; | ||
templateTag = new TemplateTagModel(createConfig); | ||
}); | ||
|
||
afterEach(() => { | ||
datastore = null; | ||
mockery.deregisterAll(); | ||
mockery.resetCache(); | ||
}); | ||
|
||
after(() => { | ||
mockery.disable(); | ||
}); | ||
|
||
it('is constructed properly', () => { | ||
assert.instanceOf(templateTag, TemplateTagModel); | ||
assert.instanceOf(templateTag, BaseModel); | ||
schema.models.secret.allKeys.forEach((key) => { | ||
assert.strictEqual(templateTag[key], createConfig[key]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
'use strict'; | ||
|
||
const assert = require('chai').assert; | ||
const mockery = require('mockery'); | ||
const sinon = require('sinon'); | ||
|
||
sinon.assert.expose(assert, { prefix: '' }); | ||
|
||
describe('TemplateTag Factory', () => { | ||
const name = 'testTemplateTag'; | ||
const version = '1.3'; | ||
const tag = 'latest'; | ||
const metaData = { | ||
name, | ||
tag, | ||
version | ||
}; | ||
let TemplateTagFactory; | ||
let datastore; | ||
let factory; | ||
let TemplateTag; | ||
|
||
before(() => { | ||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnUnregistered: false | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
datastore = { | ||
save: sinon.stub(), | ||
get: sinon.stub(), | ||
scan: sinon.stub() | ||
}; | ||
|
||
// eslint-disable-next-line global-require | ||
TemplateTag = require('../../lib/templateTag'); | ||
// eslint-disable-next-line global-require | ||
TemplateTagFactory = require('../../lib/templateTagFactory'); | ||
|
||
factory = new TemplateTagFactory({ datastore }); | ||
}); | ||
|
||
afterEach(() => { | ||
datastore = null; | ||
mockery.deregisterAll(); | ||
mockery.resetCache(); | ||
}); | ||
|
||
after(() => { | ||
mockery.disable(); | ||
}); | ||
|
||
describe('createClass', () => { | ||
it('should return a TemplateTag model', () => { | ||
const model = factory.createClass(metaData); | ||
|
||
assert.instanceOf(model, TemplateTag); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
const generatedId = 1234135; | ||
let expected; | ||
|
||
beforeEach(() => { | ||
expected = { | ||
id: generatedId, | ||
name, | ||
tag, | ||
version | ||
}; | ||
}); | ||
|
||
it('creates a TemplateTag given name, tag, and version', () => { | ||
datastore.save.resolves(expected); | ||
|
||
return factory.create({ | ||
name, | ||
tag, | ||
version | ||
}).then((model) => { | ||
assert.instanceOf(model, TemplateTag); | ||
Object.keys(expected).forEach((key) => { | ||
assert.strictEqual(model[key], expected[key]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getInstance', () => { | ||
let config; | ||
|
||
beforeEach(() => { | ||
config = { datastore }; | ||
}); | ||
|
||
it('should get an instance', () => { | ||
const f1 = TemplateTagFactory.getInstance(config); | ||
const f2 = TemplateTagFactory.getInstance(config); | ||
|
||
assert.instanceOf(f1, TemplateTagFactory); | ||
assert.instanceOf(f2, TemplateTagFactory); | ||
|
||
assert.equal(f1, f2); | ||
}); | ||
|
||
it('should throw when config not supplied', () => { | ||
assert.throw(TemplateTagFactory.getInstance, | ||
Error, 'No datastore provided to TemplateTagFactory'); | ||
}); | ||
}); | ||
}); |