Skip to content

Commit

Permalink
fix(yaml): modified strain doesn't preserve version-lock on save
Browse files Browse the repository at this point in the history
fixes #394
  • Loading branch information
tripodsan committed Dec 3, 2020
1 parent ad5f903 commit 55ba0bb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Strain.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class Strain {
this._ownProperties.forEach((key) => {
const idx = node.items.findIndex((i) => i.key === key
|| (i.key.value && i.key.value === key));
let value = this[key];
let value = key === 'version-lock' ? this.versionLock : this[key];
if (value && value.toYAMLNode) {
value = value.toYAMLNode();
}
Expand Down
12 changes: 12 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ describe('Helix Config Serializing', () => {
assert.equal(actual, expected);
});

it('can serialize back a modified strain with version-lock and modified package', async () => {
const source = await fs.readFile(path.resolve(SPEC_ROOT, 'minimal-lock.yaml'), 'utf-8');
const cfg = await new HelixConfig()
.withSource(source)
.init();

cfg.strains.get('default').package = 'bfbde5fbfbde5fbfbde5f';
const actual = cfg.toYAML();
const expected = await fs.readFile(path.resolve(SPEC_ROOT, 'minimal-lock-package.yaml'), 'utf-8');
assert.equal(actual, expected);
});

it('can serialize back a modified strain with modified package (with refs)', async () => {
const source = await fs.readFile(path.resolve(SPEC_ROOT, 'minimal-with-refs.yaml'), 'utf-8');
const cfg = await new HelixConfig()
Expand Down
31 changes: 31 additions & 0 deletions test/specs/configs/minimal-lock-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2018 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
version: 1

definitions:
constants:
defaultRepo:
&myrepo
owner: adobe
repo: project-helix.io
ref: master
strains:
base:
&basestrain
code: *myrepo
content: *myrepo
static: *myrepo

strains:
- name: default
<<: *basestrain
version-lock:
word2md: 1.2.3
package: bfbde5fbfbde5fbfbde5f
30 changes: 30 additions & 0 deletions test/specs/configs/minimal-lock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2018 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
version: 1

definitions:
constants:
defaultRepo:
&myrepo
owner: adobe
repo: project-helix.io
ref: master
strains:
base:
&basestrain
code: *myrepo
content: *myrepo
static: *myrepo

strains:
- name: default
<<: *basestrain
version-lock:
word2md: 1.2.3

0 comments on commit 55ba0bb

Please sign in to comment.