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

Commit2ad1d62

Browse files
committed
chore: move over some of the clibase changes
This will help reduce merge conflicts + review overhead in#6491.
1 parent1b3b0ea commit2ad1d62

File tree

9 files changed

+868
-38
lines changed

9 files changed

+868
-38
lines changed

‎cli/clibase/clibase.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// We will extend its usage to the rest of our application, completely replacing
66
// cobra/viper. It's also a candidate to be broken out into its own open-source
77
// library, so we avoid deep coupling with Coder concepts.
8+
//
9+
// The Command interface is loosely based on the chi middleware pattern and
10+
// http.Handler/HandlerFunc.
811
package clibase
912

1013
import (

‎cli/clibase/clibasetest/invokation.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package clibasetest
2+
3+
import (
4+
"bytes"
5+
"io"
6+
"testing"
7+
8+
"github.com/coder/coder/cli/clibase"
9+
)
10+
11+
// IO is the standard input, output, and error for a command.
12+
typeIOstruct {
13+
Stdin*bytes.Buffer
14+
Stdout*bytes.Buffer
15+
Stderr*bytes.Buffer
16+
}
17+
18+
// FakeIO sets Stdin, Stdout, and Stderr to buffers.
19+
funcFakeIO(i*clibase.Invokation)*IO {
20+
b:=&IO{
21+
Stdin:bytes.NewBuffer(nil),
22+
Stdout:bytes.NewBuffer(nil),
23+
Stderr:bytes.NewBuffer(nil),
24+
}
25+
i.Stdout=b.Stdout
26+
i.Stderr=b.Stderr
27+
i.Stdin=b.Stdin
28+
returnb
29+
}
30+
31+
typetestWriterstruct {
32+
prefixstring
33+
t*testing.T
34+
}
35+
36+
func (w*testWriter)Write(p []byte) (nint,errerror) {
37+
w.t.Helper()
38+
w.t.Log(w.prefix,string(p))
39+
returnlen(p),nil
40+
}
41+
42+
funcTestWriter(t*testing.T,prefixstring) io.Writer {
43+
return&testWriter{prefix:prefix,t:t}
44+
}
45+
46+
// Invoke creates a fake invokation and IO.
47+
funcInvoke(cmd*clibase.Cmd,args...string) (*clibase.Invokation,*IO) {
48+
i:=cmd.Invoke(args...)
49+
returni,FakeIO(i)
50+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp