aboutsummaryrefslogtreecommitdiff
path: root/internal/testutil/exec_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/testutil/exec_test.go')
-rw-r--r--internal/testutil/exec_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/testutil/exec_test.go b/internal/testutil/exec_test.go
new file mode 100644
index 00000000..679dc9d0
--- /dev/null
+++ b/internal/testutil/exec_test.go
@@ -0,0 +1,55 @@
+// Copyright 2020 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package testutil
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestExecHelper(t *testing.T) {
+ if !WantHelperProcess() {
+ return
+ }
+
+ if os.Getenv("PASS") != "1" {
+ fmt.Fprintln(os.Stdout, "tests failed")
+ os.Exit(1)
+ }
+
+ fmt.Fprintln(os.Stdout, "tests succeed")
+}
+
+func TestExec(t *testing.T) {
+ tests := []struct {
+ helper string
+ env string
+ expOut string
+ expErr error
+ }{
+ {
+ helper: "NoTestsToRun",
+ expErr: errors.New("no tests to run"),
+ }, {
+ helper: "TestExecHelper",
+ expErr: errors.New("exit status 1 - tests failed\n"),
+ }, {
+ helper: "TestExecHelper",
+ env: "PASS=1",
+ expOut: "tests succeed",
+ },
+ }
+ for _, test := range tests {
+ t.Run("", func(t *testing.T) {
+ out, err := Exec(test.helper, test.env)
+ assert.Equal(t, test.expErr, err)
+ assert.Equal(t, test.expOut, out)
+ })
+ }
+}