mirror of
https://github.com/gogs/gogs.git
synced 2025-12-22 16:20:14 +01:00
conf: add unit tests (#5954)
* conf: add tests for utils.go * conf: add tests for static.go * mock os/exec * Run tests on Windows * appveyor: fix gcc not found * computed: add unit tests * log: add unit tests * log: fix tests on Windows * conf: add some tests * Finish adding tests * Cover more cases * Add tests for testutil * Add more tests
This commit is contained in:
55
internal/testutil/exec_test.go
Normal file
55
internal/testutil/exec_test.go
Normal file
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user