template / ci-testing / files / postscript_test.go
Branch ci-testing · default branch · all branches
postscript_test.go
763c260d 2022-10-06 Pavel Safronov | 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) { | |
687d5626 2022-10-28 Pavel Safronov | 11 | _, err := createPostScriptArrays(profile, PostPatternData{FullPath: "test"}) |
763c260d 2022-10-06 Pavel Safronov | 12 | assert.NotNil(t, err, "Expected to fail to create post script arrays, but succeeded") |
| 13 | } | |
| 14 | testSuccess := func(profile Profile) { | |
687d5626 2022-10-28 Pavel Safronov | 15 | postscripts, err := createPostScriptArrays(profile, PostPatternData{ |
| 16 | FullPath: "test", | |
| 17 | PrePatternData: PrePatternData{ | |
| 18 | Extras: map[string]string{"foo": "bar"}, | |
| 19 | }, | |
| 20 | }) | |
763c260d 2022-10-06 Pavel Safronov | 21 | assert.Nil(t, err, "Error creating postscript array") |
687d5626 2022-10-28 Pavel Safronov | 22 | assert.Equal(t, postscripts, []string{"echo \"test\"-bar "}) |
763c260d 2022-10-06 Pavel Safronov | 23 | } |
| 24 | ||
| 25 | testSuccess(Profile{ | |
1a02ef4e 2022-10-21 Pavel Safronov | 26 | PostScripts: []ParameterizedText{ |
687d5626 2022-10-28 Pavel Safronov | 27 | "echo \"{{.FullPath}}\"-{{.Extras.foo}} ", |
763c260d 2022-10-06 Pavel Safronov | 28 | }, |
| 29 | }) | |
| 30 | testFailure(Profile{ | |
| 31 | PostScripts: nil, | |
| 32 | }) | |
| 33 | testFailure(Profile{ | |
1a02ef4e 2022-10-21 Pavel Safronov | 34 | PostScripts: []ParameterizedText{}, |
763c260d 2022-10-06 Pavel Safronov | 35 | }) |
| 36 | testFailure(Profile{ | |
1a02ef4e 2022-10-21 Pavel Safronov | 37 | PostScripts: []ParameterizedText{ |
763c260d 2022-10-06 Pavel Safronov | 38 | "echo \"{{.Name\"", |
| 39 | }, | |
| 40 | }) | |
| 41 | testFailure(Profile{ | |
1a02ef4e 2022-10-21 Pavel Safronov | 42 | PostScripts: []ParameterizedText{ |
763c260d 2022-10-06 Pavel Safronov | 43 | "echo \"{{.NameUnknown}}\"", |
| 44 | }, | |
| 45 | }) | |
| 46 | } |