Skip to content

Commit

Permalink
Merge pull request #510 from Shopify/load-yaml-aliases
Browse files Browse the repository at this point in the history
Allow for yaml aliases to be loaded using YAML.safe_load
  • Loading branch information
jmreid committed Jul 9, 2019
2 parents cee469d + 053c8ea commit 356ad94
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## next

*Bug Fixes*
- Re-enable support for YAML aliases when using YAML.safe_load [#510](https://github.com/Shopify/kubernetes-deploy/pull/510)

## 0.26.5

*Bug Fixes*
Expand Down
2 changes: 1 addition & 1 deletion lib/kubernetes-deploy/bindings_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parse_file(string)
when '.json'
bindings = parse_json(File.read(file_path))
when '.yaml', '.yml'
bindings = YAML.safe_load(File.read(file_path))
bindings = YAML.safe_load(File.read(file_path), [], [], true, file_path)
else
raise ArgumentError, "Supplied file does not appear to be JSON or YAML"
end
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/for_unit_tests/bindings-with-aliases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
alias: &alias
baz: bang
foo: a,b,c
bar:
<<: *alias
7 changes: 7 additions & 0 deletions test/unit/kubernetes-deploy/bindings_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def test_parse_nested_values
assert_equal(expected, bindings.parse)
end

def test_parses_yaml_file_with_aliases
expected = { "foo" => "a,b,c", "bar" => { "baz" => "bang" }, "alias" => { "baz" => "bang" } }
bindings = KubernetesDeploy::BindingsParser.new
bindings.add('@test/fixtures/for_unit_tests/bindings-with-aliases.yaml')
assert_equal(expected, bindings.parse)
end

private

def parse(string)
Expand Down

0 comments on commit 356ad94

Please sign in to comment.