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

Commit

Permalink
Merge pull request #76 from rebuy-de/test-make-slice
Browse files Browse the repository at this point in the history
fix MakeSlice
  • Loading branch information
svenwltr authored Aug 11, 2017
2 parents dca608e + d07f301 commit 166ec1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
35 changes: 20 additions & 15 deletions pkg/api/render.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"regexp"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -39,24 +40,28 @@ func (app *App) Render(fetched *FetchResult) ([]runtime.Object, error) {
continue
}

if strings.TrimSpace(data) == "" {
log.WithFields(log.Fields{
"Name": name,
}).Debug("Ignoring empty file.")
continue
}
splitted := regexp.MustCompile("[\n\r]---").Split(data, -1)

obj, _, err := decode([]byte(data), nil, nil)
if err != nil {
return nil, errors.Wrapf(err, "unable to decode file '%s'", name)
}
for _, part := range splitted {
if strings.TrimSpace(part) == "" {
log.WithFields(log.Fields{
"Name": name,
}).Debug("Ignoring empty file.")
continue
}

obj, err = app.Interceptors.PostManifestRender(obj)
if err != nil {
return nil, errors.WithStack(err)
}
obj, _, err := decode([]byte(part), nil, nil)
if err != nil {
return nil, errors.Wrapf(err, "unable to decode file '%s'", name)
}

objects = append(objects, obj)
obj, err = app.Interceptors.PostManifestRender(obj)
if err != nil {
return nil, errors.WithStack(err)
}

objects = append(objects, obj)
}
}

return objects, nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/templates/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"text/template"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

func RenderAll(templates map[string]string, variables Variables) (map[string]string, error) {
Expand Down Expand Up @@ -43,5 +44,9 @@ func Render(templateString string, variables Variables) (string, error) {
return "", errors.Wrapf(err, "Unable to render template")
}

log.WithFields(log.Fields{
"Result": buf.String(),
}).Debug("Rendered file")

return buf.String(), nil
}
2 changes: 2 additions & 0 deletions pkg/templates/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ func TestRender(t *testing.T) {
template = `
branch: {{.branch}}
commit: {{.sha}}
range: {{ $langs := MakeSlice "de" "fr" "nl" }}{{ range $langs }}{{.}}-{{end}}
`
values = Variables{
"branch": "foobar",
Expand All @@ -15,6 +16,7 @@ func TestRender(t *testing.T) {
expected = `
branch: foobar
commit: 123abc
range: de-fr-nl-
`
)

Expand Down

0 comments on commit 166ec1d

Please sign in to comment.