Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad76f64

Browse files
committed
Add test using cobra cmd
1 parent8204c57 commitad76f64

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+
returnnil
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)

[8]ページ先頭

©2009-2025 Movatter.jp