Skip to content

Commit

Permalink
Return no error if tsuru.yaml file was not found
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Feb 6, 2019
1 parent dc16d9d commit 5dd1ad3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
7 changes: 2 additions & 5 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func deploy(c tsuru.Client, appName string, fs Filesystem, executor exec.Executo
return err
}
}
rawYamlData, err := loadTsuruYamlRaw(fs)
if err != nil {
return err
}
rawYamlData := loadTsuruYamlRaw(fs)
yamlData, err := parseTsuruYaml(rawYamlData)
if err != nil {
return err
Expand Down Expand Up @@ -119,7 +116,7 @@ func inspect(dockerClient *docker.Client, image string, filesystem Filesystem, w
if err != nil {
return fmt.Errorf("failed to inspect image %q: %v", image, err)
}
rawYamlData, err := loadTsuruYamlRaw(filesystem)
rawYamlData := loadTsuruYamlRaw(filesystem)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func execScript(cmds []string, envs []bind.EnvVar, w io.Writer, fs Filesystem, e
return nil
}

func loadTsuruYamlRaw(fs Filesystem) ([]byte, error) {
func loadTsuruYamlRaw(fs Filesystem) []byte {
for _, yamlFile := range tsuruYamlFiles {
filePath := fmt.Sprintf("%s/%s", defaultWorkingDir, yamlFile)
tsuruYaml, err := fs.ReadFile(filePath)
if err == nil {
return tsuruYaml, nil
return tsuruYaml
}
}
return nil, fmt.Errorf("error loading tsuru yaml file")
return nil
}

func parseTsuruYaml(data []byte) (tsuru.TsuruYaml, error) {
Expand Down
20 changes: 18 additions & 2 deletions tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ unknown: ok`
_, err := s.fs.Create(tsuruYmlPath)
c.Assert(err, check.IsNil)
c.Assert(s.testFS().HasAction(fmt.Sprintf("create %s", tsuruYmlPath)), check.Equals, true)
raw, err := loadTsuruYamlRaw(s.fs)
c.Assert(err, check.IsNil)
raw := loadTsuruYamlRaw(s.fs)
c.Assert(string(raw), check.DeepEquals, tsuruYmlData)
}

func (s *S) TestLoadTsuruYamlRawNotFound(c *check.C) {
raw := loadTsuruYamlRaw(s.fs)
c.Assert(raw, check.IsNil)
}

func (s *S) TestParseAppYaml(c *check.C) {
tsuruYmlData := `hooks:
build:
Expand Down Expand Up @@ -302,3 +306,15 @@ func (s *S) TestReadProcfileNormalizeCRLFToLF(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(result, check.Equals, expected)
}

func (s *S) TestParseTsuruYamlEmpty(c *check.C) {
t, err := parseTsuruYaml(nil)
c.Assert(err, check.IsNil)
c.Assert(t, check.DeepEquals, tsuru.TsuruYaml{})
}

func (s *S) TestParseAllTsuruYamlEmpty(c *check.C) {
t, err := parseAllTsuruYaml(nil)
c.Assert(err, check.IsNil)
c.Assert(t, check.IsNil)
}

0 comments on commit 5dd1ad3

Please sign in to comment.