2
0

exec_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package testutil
  5. import (
  6. "errors"
  7. "fmt"
  8. "os"
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestExecHelper(t *testing.T) {
  13. if !WantHelperProcess() {
  14. return
  15. }
  16. if os.Getenv("PASS") != "1" {
  17. fmt.Fprintln(os.Stdout, "tests failed")
  18. os.Exit(1)
  19. }
  20. fmt.Fprintln(os.Stdout, "tests succeed")
  21. }
  22. func TestExec(t *testing.T) {
  23. tests := []struct {
  24. helper string
  25. env string
  26. expOut string
  27. expErr error
  28. }{
  29. {
  30. helper: "NoTestsToRun",
  31. expErr: errors.New("no tests to run"),
  32. }, {
  33. helper: "TestExecHelper",
  34. expErr: errors.New("exit status 1 - tests failed\n"),
  35. }, {
  36. helper: "TestExecHelper",
  37. env: "PASS=1",
  38. expOut: "tests succeed",
  39. },
  40. }
  41. for _, test := range tests {
  42. t.Run("", func(t *testing.T) {
  43. out, err := Exec(test.helper, test.env)
  44. assert.Equal(t, test.expErr, err)
  45. assert.Equal(t, test.expOut, out)
  46. })
  47. }
  48. }