Merge pull request #3837 from consideRatio/toYaml-pr

toYaml - Fix #3470 and #3410's trailing \n issues
pull/3876/head
Matthew Fisher 7 years ago committed by GitHub
commit 6f02d9e412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -175,7 +175,7 @@ func ToYaml(v interface{}) string {
// Swallow errors inside of a template.
return ""
}
return string(data)
return strings.TrimSuffix(string(data), "\n")
}
// FromYaml converts a YAML document into a map[string]interface{}.

@ -72,10 +72,10 @@ func TestToConfig(t *testing.T) {
f := NewFiles(getTestFiles())
out := f.Glob("**/captain.txt").AsConfig()
as.Equal("captain.txt: The Captain\n", out)
as.Equal("captain.txt: The Captain", out)
out = f.Glob("ship/**").AsConfig()
as.Equal("captain.txt: The Captain\nstowaway.txt: Legatt\n", out)
as.Equal("captain.txt: The Captain\nstowaway.txt: Legatt", out)
}
func TestToSecret(t *testing.T) {
@ -84,7 +84,7 @@ func TestToSecret(t *testing.T) {
f := NewFiles(getTestFiles())
out := f.Glob("ship/**").AsSecrets()
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0\n", out)
as.Equal("captain.txt: VGhlIENhcHRhaW4=\nstowaway.txt: TGVnYXR0", out)
}
func TestLines(t *testing.T) {
@ -99,7 +99,7 @@ func TestLines(t *testing.T) {
}
func TestToYaml(t *testing.T) {
expect := "foo: bar\n"
expect := "foo: bar"
v := struct {
Foo string `json:"foo"`
}{

@ -36,7 +36,7 @@ func ToYAML(s string) (string, error) {
return "", err
}
d, err := yaml.Marshal(m)
return string(d), err
return strings.TrimSuffix(string(d), "\n"), err
}
// Parse parses a set line.

@ -365,7 +365,7 @@ func TestToYAML(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expect := "name: value\n"
expect := "name: value"
if o != expect {
t.Errorf("Expected %q, got %q", expect, o)
}

Loading…
Cancel
Save