template / files / internal / core / postscript_test.go
postscript_test.go
37160b89 2026-05-01 Pavel Safronov | 1 | package core |
fd0a4446 2023-04-03 Pavel Safronov | 2 | |
| 3 | import ( | |
| 4 | "testing" | |
| 5 | ||
| 6 | "github.com/stretchr/testify/assert" | |
| 7 | ) | |
| 8 | ||
| 9 | func TestCreatePostScriptArrays(t *testing.T) { | |
| 10 | callCreatePostScriptArrays := func(postScripts []ParameterizedText) ([]string, error) { | |
| 11 | return createPostScriptArrays( | |
| 12 | Profile{PostScripts: postScripts}, | |
| 13 | PostPatternData{ | |
| 14 | FullPath: "test", | |
| 15 | PrePatternData: PrePatternData{ | |
| 16 | Extras: map[string]string{"foo": "bar"}, | |
| 17 | }, | |
| 18 | }) | |
| 19 | } | |
| 20 | ||
| 21 | arr, err := callCreatePostScriptArrays([]ParameterizedText{"echo \"{{.FullPath}}\"-{{.Extras.foo}} "}) | |
| 22 | assert.Nil(t, err, "Error creating postscript array") | |
| 23 | assert.Equal(t, 1, len(arr)) | |
| 24 | assert.Equal(t, arr[0], "echo \"test\"-bar ") | |
| 25 | ||
| 26 | arr, err = callCreatePostScriptArrays(nil) | |
| 27 | assert.NotNil(t, err, "nil postscripts should fail") | |
| 28 | assert.Nil(t, arr) | |
| 29 | ||
| 30 | arr, err = callCreatePostScriptArrays([]ParameterizedText{}) | |
| 31 | assert.NotNil(t, err, "empty postscripts should fail") | |
| 32 | assert.Nil(t, arr) | |
| 33 | ||
| 34 | arr, err = callCreatePostScriptArrays([]ParameterizedText{"echo \"{{.Name"}) | |
| 35 | assert.NotNil(t, err, "invalid template should fail") | |
| 36 | assert.Nil(t, arr) | |
| 37 | ||
| 38 | arr, err = callCreatePostScriptArrays([]ParameterizedText{"echo \"{{.NameUnknown}}\""}) | |
| 39 | assert.NotNil(t, err, "invalid template variable should fail") | |
| 40 | assert.Nil(t, arr) | |
| 41 | } |