exec_test.go 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package testutil
  2. import (
  3. "fmt"
  4. "os"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestExecHelper(_ *testing.T) {
  9. if !WantHelperProcess() {
  10. return
  11. }
  12. if os.Getenv("PASS") != "1" {
  13. fmt.Fprintln(os.Stdout, "tests failed")
  14. os.Exit(1)
  15. }
  16. fmt.Fprintln(os.Stdout, "tests succeed")
  17. }
  18. func TestExec(t *testing.T) {
  19. tests := []struct {
  20. helper string
  21. env string
  22. expOut string
  23. expErrMsg string
  24. }{
  25. {
  26. helper: "NoTestsToRun",
  27. expErrMsg: "no tests to run",
  28. }, {
  29. helper: "TestExecHelper",
  30. expErrMsg: "exit status 1 - tests failed\n",
  31. }, {
  32. helper: "TestExecHelper",
  33. env: "PASS=1",
  34. expOut: "tests succeed",
  35. },
  36. }
  37. for _, test := range tests {
  38. t.Run("", func(t *testing.T) {
  39. out, err := Exec(test.helper, test.env)
  40. if test.expErrMsg != "" {
  41. assert.Error(t, err)
  42. assert.Contains(t, err.Error(), test.expErrMsg)
  43. } else {
  44. assert.NoError(t, err)
  45. }
  46. assert.Equal(t, test.expOut, out)
  47. })
  48. }
  49. }