Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #372 from mrtyler/gpii-3641-parsehole
Browse files Browse the repository at this point in the history
GPII-3641: Handle tags that look like floats (or integers)
  • Loading branch information
Tyler Roscoe committed Apr 24, 2019
2 parents ce462a5 + d3f46ab commit 31c6b40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions shared/rakefiles/tests/spec/vars_spec.rb
Expand Up @@ -200,6 +200,30 @@ def scrub_env
expect(ENV).not_to have_received(:[]=).with("TF_VAR_component_without_sha_repository", any_args)
expect(ENV).not_to have_received(:[]=).with("TF_VAR_component_without_tag_repository", any_args)
end

it "set_versions handles tags that look like floats" do
# Usually, the yaml library can deduce that a tag is a string. However, if
# the tag is a valid float it is imported as such. Then,
# ENV[component_tag]= raises "TypeError: no implicit conversion of Float
# into String".
fake_tag = 3.9
fake_versions = {
"flowmanager" => {
"upstream" => {
"repository" => "fake_repository:fake_tag",
},
"generated" => {
"repository" => "gcr.io/some-project/fake_repository",
"sha" => "sha256:c0ffee",
"tag" => fake_tag,
},
},
}
allow(File).to receive(:read)
allow(YAML).to receive(:load).and_return(fake_versions)
Vars.set_versions()
expect(ENV).to have_received(:[]=).with("TF_VAR_flowmanager_tag", "#{fake_tag}")
end
end


Expand Down
6 changes: 5 additions & 1 deletion shared/rakefiles/vars.rb
Expand Up @@ -74,7 +74,11 @@ def self.set_versions()
values["generated"]["tag"])
ENV["TF_VAR_#{component}_repository"] = values["generated"]["repository"]
ENV["TF_VAR_#{component}_checksum"] = values["generated"]["sha"]
ENV["TF_VAR_#{component}_tag"] = values["generated"]["tag"]
# Usually, the yaml library can deduce that a tag is a string. However, if
# the tag is a valid float it is imported as such. Then,
# ENV[component_tag]= raises "TypeError: no implicit conversion of Float
# into String".
ENV["TF_VAR_#{component}_tag"] = values["generated"]["tag"].to_s
end
end
end
Expand Down

0 comments on commit 31c6b40

Please sign in to comment.