Skip to content

Commit 638acb6

Browse files
Emyrkmafredri
authored andcommitted
Add test using cobra cmd
1 parent 65f3304 commit 638acb6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pty/ptytest/ptytest_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package ptytest_test
22

33
import (
4+
"fmt"
45
"os/exec"
56
"testing"
67

8+
"github.com/spf13/cobra"
79
"github.com/stretchr/testify/require"
810

911
"github.com/coder/coder/pty/ptytest"
@@ -18,6 +20,7 @@ func TestPtytest(t *testing.T) {
1820
pty.ExpectMatch("write")
1921
pty.WriteLine("read")
2022
})
23+
2124
// nolint:paralleltest
2225
t.Run("Do not hang on Intel macOS", func(t *testing.T) {
2326
cmd := exec.Command("sh", "-c", "echo hi, I will cause a hang")
@@ -27,4 +30,23 @@ func TestPtytest(t *testing.T) {
2730
err := cmd.Run()
2831
require.NoError(t, err)
2932
})
33+
34+
// nolint:paralleltest
35+
t.Run("CobraCommandWorksLinux", func(t *testing.T) {
36+
// Example with cobra command instead of exec. More abstractions, but
37+
// for some reason works on linux.
38+
cmd := cobra.Command{
39+
Use: "test",
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
fmt.Println("Hello world")
42+
return nil
43+
},
44+
}
45+
46+
pty := ptytest.New(t)
47+
cmd.SetIn(pty.Input())
48+
cmd.SetOut(pty.Output())
49+
err := cmd.Execute()
50+
require.NoError(t, err)
51+
})
3052
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy