Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(yaml): modified strain doesn't preserve version-lock on save #395

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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