Skip to content

Commit

Permalink
Added CRLF -> line separator normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Jun 3, 2018
1 parent ff1301f commit c8283ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions kubetpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ func newTemplate(file string, flavor string) (engine.Template, error) {
if err != nil {
return nil, err
}
content = bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1)
directives, err := parseDirectives(content)
if err != nil {
return nil, fmt.Errorf("%s: %s", file, err.Error())
Expand Down
24 changes: 24 additions & 0 deletions kubetpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,27 @@ metadata:
name: app-caed0c7
`)
}

func TestCRLFIsNormalizedToLF(t *testing.T) {
tmplFile, err := ioutil.TempFile("", "kubetpl-test")
if err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(tmplFile.Name(), []byte("# kubetpl:syntax:$\r\nkind: ConfigMap\r\nmetadata:\r\n name: $NAME"), 0600); err != nil {
t.Fatal(err)
}
cfg := map[string]interface{}{
"NAME": "windows",
}
actual, err := render([]string{tmplFile.Name()}, cfg, renderOpts{})
if err != nil {
t.Fatal(err)
}
if len(actual) == 0 {
t.Fatal("len(rendered) == 0")
}
expected := "---\nkind: ConfigMap\nmetadata:\n name: windows\n"
if string(actual) != expected {
t.Fatalf("actual: \n%s != expected: \n%s", actual, expected)
}
}

0 comments on commit c8283ab

Please sign in to comment.