aboutsummaryrefslogtreecommitdiffstats
path: root/commands/root_test.go
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2022-06-06 09:38:15 -0400
committerSteve Moyer <smoyer1@selesy.com>2022-06-06 09:38:15 -0400
commit99669d77b11851dd35e4c9998594d3cb517543f3 (patch)
tree4b958f0f7b1469cc81a9cdd1c4f6771617e1ae84 /commands/root_test.go
parent1a504e05225bb86492bec5a6f8b1b0172d1860c7 (diff)
downloadgit-bug-99669d77b11851dd35e4c9998594d3cb517543f3.tar.gz
test(808): do not run golden file tests on Windows
Diffstat (limited to 'commands/root_test.go')
-rw-r--r--commands/root_test.go55
1 files changed, 3 insertions, 52 deletions
diff --git a/commands/root_test.go b/commands/root_test.go
index c26964d7..8983037c 100644
--- a/commands/root_test.go
+++ b/commands/root_test.go
@@ -1,70 +1,21 @@
+//go:build !windows
+
package commands_test
import (
"bytes"
- "context"
- "flag"
"io/ioutil"
- "os"
"path/filepath"
"testing"
- "github.com/MichaelMure/git-bug/commands"
- "github.com/MichaelMure/git-bug/repository"
- "github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)
-var update = flag.Bool("update", false, "pass -update to the test runner to update golden files")
-
-type testEnv struct {
- cwd string
- repo *repository.GoGitRepo
- cmd *cobra.Command
- out *bytes.Buffer
-}
-
-func newTestEnv(t *testing.T) *testEnv {
- t.Helper()
-
- cwd, err := ioutil.TempDir("", "")
- require.NoError(t, err)
- t.Cleanup(func() {
- require.NoError(t, os.RemoveAll(cwd))
- })
-
- repo, err := repository.InitGoGitRepo(cwd, commands.GitBugNamespace)
- require.NoError(t, err)
- t.Cleanup(func() {
- require.NoError(t, repo.Close())
- })
-
- out := new(bytes.Buffer)
- cmd := commands.NewRootCommand()
- cmd.SetArgs([]string{})
- cmd.SetErr(out)
- cmd.SetOut(out)
-
- return &testEnv{
- cwd: cwd,
- repo: repo,
- cmd: cmd,
- out: out,
- }
-}
-
-func (e *testEnv) Execute(t *testing.T) {
- t.Helper()
-
- ctx := context.WithValue(context.Background(), "cwd", e.cwd)
- require.NoError(t, e.cmd.ExecuteContext(ctx))
-}
-
func requireGoldenFileEqual(t *testing.T, path string, act []byte) {
t.Helper()
// Replace Windows line terminators
- // act = []byte(strings.ReplaceAll(string(act), "\r\n", "\n"))
+ act = bytes.ReplaceAll(act, []byte{'\r'}, []byte{})
path = filepath.Join("testdata", path)