Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
guiferpa authored and cezarsa committed Nov 30, 2017
1 parent 8e55eef commit 31037f0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"bytes"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -125,9 +126,8 @@ func buildHooks(yamlData TsuruYaml, envs []bind.EnvVar) error {
return execScript(cmds, envs, os.Stdout)
}

func readProcfile() (string, error) {
procfilePath := fmt.Sprintf("%s/%s", defaultWorkingDir, "Procfile")
f, err := filesystem().Open(procfilePath)
func readProcfile(path string) (string, error) {
f, err := filesystem().Open(fmt.Sprintf("%v/Procfile", path))
if err != nil {
return "", err
}
Expand All @@ -136,13 +136,13 @@ func readProcfile() (string, error) {
if err != nil {
return "", err
}
return string(procfile), nil
return string(bytes.Replace(procfile, []byte("\r\n"), []byte("\n"), -1)), nil
}

var procfileRegex = regexp.MustCompile(`^([\w-]+):\s*(\S.+)$`)

func loadProcesses(t *TsuruYaml) error {
procfile, err := readProcfile()
procfile, err := readProcfile(defaultWorkingDir)
if err != nil {
return err
}
Expand Down
35 changes: 35 additions & 0 deletions tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"os"
"syscall"

"github.com/tsuru/tsuru/app/bind"
"github.com/tsuru/tsuru/exec/exectest"
Expand Down Expand Up @@ -217,3 +218,37 @@ func (s *S) TestDiffDeploy(c *check.C) {
c.Assert(result, check.DeepEquals, diff)
c.Assert(first, check.Equals, false)
}

func (s *S) TestReadProcfileNotFound(c *check.C) {
_, err := readProcfile("./fake-path")
_, ok := err.(syscall.Errno)
c.Assert(ok, check.Equals, true)
}

func (s *S) TestReadProcfileFound(c *check.C) {
expected := "web: ls\naxl: \"echo Guns N' Roses\""
procfilePath := "."
procfileContent := expected
procfile, err := s.fs.Create(fmt.Sprintf("%v/Procfile", procfilePath))
c.Assert(err, check.IsNil)
_, err = procfile.Write([]byte(procfileContent))
c.Assert(err, check.IsNil)
c.Assert(procfile.Close(), check.IsNil)
result, err := readProcfile(procfilePath)
c.Assert(err, check.IsNil)
c.Assert(result, check.Equals, expected)
}

func (s *S) TestReadProcfileNormalizeCRLFToLF(c *check.C) {
procfilePath := "."
procfileContent := "web: ls\r\nslash: \"echo Guns N' Roses\""
expected := "web: ls\nslash: \"echo Guns N' Roses\""
procfile, err := s.fs.Create(fmt.Sprintf("%v/Procfile", procfilePath))
c.Assert(err, check.IsNil)
_, err = procfile.Write([]byte(procfileContent))
c.Assert(err, check.IsNil)
c.Assert(procfile.Close(), check.IsNil)
result, err := readProcfile(procfilePath)
c.Assert(err, check.IsNil)
c.Assert(result, check.Equals, expected)
}

0 comments on commit 31037f0

Please sign in to comment.