Skip to content

Commit

Permalink
Add array property support for yaml and json resource types.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Jul 17, 2021
1 parent ee02c08 commit ffbc93d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added
- Add array property support for yaml and json resource types

## 2.0.0 - 2020-07-08
### Changed
- Change module type to ESM
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ Example `json` resource configuration:
]
}

Example `json` resource configuration with an array sub-property:

{
"resources": [
{
"path": "package.json",
"type": "json",
"params": {
"property": "versions.1.minor"
}
}
]
}

Example `yaml` resource configuration:

{
Expand All @@ -96,6 +110,20 @@ Example `yaml` resource configuration:
]
}

Example `yaml` resource configuration with an array sub-property:

{
"resources": [
{
"path": "playbook.yaml",
"type": "yaml",
"params": {
"property": "versions.1.minor"
}
}
]
}

Example `keep-a-changelog` resource configuration:

{
Expand Down
32 changes: 32 additions & 0 deletions test/resourcetypes/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('json', function() {
}
resourceType.setReleaseVersion('1.2.3', resource, { dryRun: false }, cb);
});
it('should set property under array sub-property', function(done) {
let resource = {
path: 'somepackage.json',
type: 'json',
params: {
property: 'versions.1.minor'
}
};
this.mockFs.expects('readFileSync').once().withExactArgs('somepackage.json', 'UTF-8').returns('{ "versions": [{ "major": 1, "minor": 2, "patch": 3 }, { "major": 8, "minor": 9, "patch": 0 }] }');
this.mockFs.expects('writeFile').once().withExactArgs('somepackage.json', '{\n "versions": [\n {\n "major": 1,\n "minor": 2,\n "patch": 3\n },\n {\n "major": 8,\n "minor": 9,\n "patch": 0\n }\n ]\n}', sinon.match.func).callsArgWith(2, null);
function cb(err, result) {
assert.equal(err, null);
done();
}
resourceType.setReleaseVersion(9, resource, { dryRun: false }, cb);
});
});

describe('getVersion', function() {
Expand All @@ -69,6 +85,22 @@ describe('json', function() {
}
resourceType.getVersion(resource, cb);
});
it('should get property under an array array sub-property', function(done) {
let resource = {
path: 'somepackage.json',
type: 'json',
params: {
property: 'versions.1.minor'
}
};
this.mockFs.expects('readFile').once().withExactArgs('somepackage.json', 'UTF-8', sinon.match.func).callsArgWith(2, null, '{ "versions": [{ "major": 1, "minor": 2, "patch": 3 }, { "major": 8, "minor": 9, "patch": 0 }] }');
function cb(err, result) {
assert.equal(err, null);
assert.equal(result, 9);
done();
}
resourceType.getVersion(resource, cb);
});
});

});
32 changes: 32 additions & 0 deletions test/resourcetypes/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('yaml', function() {
}
resourceType.setReleaseVersion('1.2.3', resource, { dryRun: false }, cb);
});
it('should set property under array sub-property', function(done) {
let resource = {
path: 'someplaybook.yaml',
type: 'yaml',
params: {
property: 'versions.1.minor'
}
};
this.mockFs.expects('readFileSync').once().withExactArgs('someplaybook.yaml', 'UTF-8').returns('{ "versions": [{ "major": 1, "minor": 2, "patch": 3 }, { "major": 8, "minor": 9, "patch": 0 }] }');
this.mockFs.expects('writeFile').once().withExactArgs('someplaybook.yaml', 'versions:\n - major: 1\n minor: 2\n patch: 3\n - major: 8\n minor: 9\n patch: 0\n', sinon.match.func).callsArgWith(2, null);
function cb(err, result) {
assert.equal(err, null);
done();
}
resourceType.setReleaseVersion(9, resource, { dryRun: false }, cb);
});
});

describe('getVersion', function() {
Expand All @@ -69,6 +85,22 @@ describe('yaml', function() {
}
resourceType.getVersion(resource, cb);
});
it('should get property under an array array sub-property', function(done) {
let resource = {
path: 'someplaybook.yaml',
type: 'yaml',
params: {
property: 'versions.1.minor'
}
};
this.mockFs.expects('readFile').once().withExactArgs('someplaybook.yaml', 'UTF-8', sinon.match.func).callsArgWith(2, null, '{ "versions": [{ "major": 1, "minor": 2, "patch": 3 }, { "major": 8, "minor": 9, "patch": 0 }] }');
function cb(err, result) {
assert.equal(err, null);
assert.equal(result, 9);
done();
}
resourceType.getVersion(resource, cb);
});
});

});

0 comments on commit ffbc93d

Please sign in to comment.