|
| 1 | +package placeholder |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/captainhook-go/captainhook/configuration" |
| 5 | + "github.com/captainhook-go/captainhook/git" |
| 6 | + "github.com/captainhook-go/captainhook/hooks/app" |
| 7 | + "github.com/captainhook-go/captainhook/io" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +func TestStdin(t *testing.T) { |
| 12 | + argMap := map[string]string{} |
| 13 | + optMap := map[string]string{"input": "foo bar"} |
| 14 | + expected := "'foo bar'" |
| 15 | + |
| 16 | + config := configuration.NewConfiguration("foo", false) |
| 17 | + repo, _ := git.NewRepository(".git") |
| 18 | + ctx := app.NewContext( |
| 19 | + io.NewDefaultIO(io.NORMAL, optMap, argMap), |
| 20 | + config, |
| 21 | + repo, |
| 22 | + ) |
| 23 | + opts := map[string]string{} |
| 24 | + placeholder := &StdIn{context: ctx} |
| 25 | + result := placeholder.Replacement(opts) |
| 26 | + if result != expected { |
| 27 | + t.Errorf("Replacement didn't work, got: %s, want: %s.", result, expected) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestStdinUnescaped(t *testing.T) { |
| 32 | + argMap := map[string]string{} |
| 33 | + optMap := map[string]string{"input": "foo bar"} |
| 34 | + expected := "foo bar" |
| 35 | + |
| 36 | + config := configuration.NewConfiguration("foo", false) |
| 37 | + repo, _ := git.NewRepository(".git") |
| 38 | + ctx := app.NewContext( |
| 39 | + io.NewDefaultIO(io.NORMAL, optMap, argMap), |
| 40 | + config, |
| 41 | + repo, |
| 42 | + ) |
| 43 | + opts := map[string]string{"escaped": "false"} |
| 44 | + placeholder := &StdIn{context: ctx} |
| 45 | + result := placeholder.Replacement(opts) |
| 46 | + if result != expected { |
| 47 | + t.Errorf("Replacement didn't work, got: %s, want: %s.", result, expected) |
| 48 | + } |
| 49 | +} |
0 commit comments