exec_test.go 881 B

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