template / windows / files / postscript_test.go
Branch windows · default branch · all branches
postscript_test.go
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/stretchr/testify/assert" |
| 7 | ) |
| 8 | |
| 9 | func TestCreatePostScriptArrays(t *testing.T) { |
| 10 | testFailure := func(profile Profile) { |
| 11 | _, err := createPostScriptArrays(profile, PostPatternData{FullPath: "test"}) |
| 12 | assert.NotNil(t, err, "Expected to fail to create post script arrays, but succeeded") |
| 13 | } |
| 14 | testSuccess := func(profile Profile) { |
| 15 | postscripts, err := createPostScriptArrays(profile, PostPatternData{ |
| 16 | FullPath: "test", |
| 17 | PrePatternData: PrePatternData{ |
| 18 | Extras: map[string]string{"foo": "bar"}, |
| 19 | }, |
| 20 | }) |
| 21 | assert.Nil(t, err, "Error creating postscript array") |
| 22 | assert.Equal(t, postscripts, []string{"echo \"test\"-bar "}) |
| 23 | } |
| 24 | |
| 25 | testSuccess(Profile{ |
| 26 | PostScripts: []ParameterizedText{ |
| 27 | "echo \"{{.FullPath}}\"-{{.Extras.foo}} ", |
| 28 | }, |
| 29 | }) |
| 30 | testFailure(Profile{ |
| 31 | PostScripts: nil, |
| 32 | }) |
| 33 | testFailure(Profile{ |
| 34 | PostScripts: []ParameterizedText{}, |
| 35 | }) |
| 36 | testFailure(Profile{ |
| 37 | PostScripts: []ParameterizedText{ |
| 38 | "echo \"{{.Name\"", |
| 39 | }, |
| 40 | }) |
| 41 | testFailure(Profile{ |
| 42 | PostScripts: []ParameterizedText{ |
| 43 | "echo \"{{.NameUnknown}}\"", |
| 44 | }, |
| 45 | }) |
| 46 | } |