| 22 | } |
| 23 | |
| 24 | func TestExec(t *testing.T) { |
| 25 | tests := []struct { |
| 26 | helper string |
| 27 | env string |
| 28 | expOut string |
| 29 | expErrMsg string |
| 30 | }{ |
| 31 | { |
| 32 | helper: "NoTestsToRun", |
| 33 | expErrMsg: "no tests to run", |
| 34 | }, { |
| 35 | helper: "TestExecHelper", |
| 36 | expErrMsg: "exit status 1 - tests failed\n", |
| 37 | }, { |
| 38 | helper: "TestExecHelper", |
| 39 | env: "PASS=1", |
| 40 | expOut: "tests succeed", |
| 41 | }, |
| 42 | } |
| 43 | for _, test := range tests { |
| 44 | t.Run("", func(t *testing.T) { |
| 45 | out, err := Exec(test.helper, test.env) |
| 46 | if test.expErrMsg != "" { |
| 47 | assert.Error(t, err) |
| 48 | assert.Contains(t, err.Error(), test.expErrMsg) |
| 49 | } else { |
| 50 | assert.NoError(t, err) |
| 51 | } |
| 52 | assert.Equal(t, test.expOut, out) |
| 53 | }) |
| 54 | } |
| 55 | } |