Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ckaznocha/feature/template
Feature/template
- Loading branch information
Showing
31 changed files
with
6,795 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo": "bar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo": "{{ foo }}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo": "{{%^}}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"path/filepath" | ||
|
||
"github.com/aymerick/raymond" | ||
) | ||
|
||
func parsePayload(p params, path string) (io.Reader, error) { | ||
var ( | ||
replacments = map[string]string{} | ||
buf = bytes.NewBuffer([]byte{}) | ||
) | ||
for _, v := range p.Replacements { | ||
replacments[v.Name] = v.Value | ||
} | ||
tmpl, err := raymond.ParseFile(filepath.Join(path, p.AppJSON)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
app, err := tmpl.Exec(replacments) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if _, err = buf.WriteString(app); err != nil { | ||
return nil, err | ||
} | ||
return buf, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_parsePayload(t *testing.T) { | ||
type args struct { | ||
p params | ||
path string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []byte | ||
wantErr bool | ||
}{ | ||
{"Reads file with no replacements", args{params{AppJSON: "app.json"}, "fixtures"}, []byte{123, 10, 32, 32, 32, 32, 34, 102, 111, 111, 34, 58, 32, 34, 98, 97, 114, 34, 10, 125, 10}, false}, | ||
{"Reads file with replacements", args{params{AppJSON: "app_template.json", Replacements: []metadata{{"foo", "bar"}}}, "fixtures"}, []byte{123, 10, 32, 32, 32, 32, 34, 102, 111, 111, 34, 58, 32, 34, 98, 97, 114, 34, 10, 125, 10}, false}, | ||
{"Reads file with bad tmpl", args{params{AppJSON: "app_template_bad.json", Replacements: []metadata{{"foo", "bar"}}}, "fixtures"}, nil, true}, | ||
} | ||
for _, tt := range tests { | ||
got, err := parsePayload(tt.args.p, tt.args.path) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("%q. parsePayload() error = %v, wantErr %v", tt.name, err, tt.wantErr) | ||
continue | ||
} | ||
if !tt.wantErr { | ||
p, _ := ioutil.ReadAll(got) | ||
if !reflect.DeepEqual(p, tt.want) { | ||
t.Errorf("%q. parsePayload() = %v, want %v", tt.name, string(p), string(tt.want)) | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.