Merge pull request #1026 from vkd/refactor-tests-drop-buffer-writer
Refactor tests - drop mock writer
This commit is contained in:
commit
995ba0a892
24
app_test.go
24
app_test.go
@ -859,30 +859,12 @@ func TestApp_DefaultStdout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type mockWriter struct {
|
||||
written []byte
|
||||
}
|
||||
|
||||
func (fw *mockWriter) Write(p []byte) (n int, err error) {
|
||||
if fw.written == nil {
|
||||
fw.written = p
|
||||
} else {
|
||||
fw.written = append(fw.written, p...)
|
||||
}
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (fw *mockWriter) GetWritten() (b []byte) {
|
||||
return fw.written
|
||||
}
|
||||
|
||||
func TestApp_SetStdout(t *testing.T) {
|
||||
w := &mockWriter{}
|
||||
var w bytes.Buffer
|
||||
|
||||
app := &App{
|
||||
Name: "test",
|
||||
Writer: w,
|
||||
Writer: &w,
|
||||
}
|
||||
|
||||
err := app.Run([]string{"help"})
|
||||
@ -891,7 +873,7 @@ func TestApp_SetStdout(t *testing.T) {
|
||||
t.Fatalf("Run error: %s", err)
|
||||
}
|
||||
|
||||
if len(w.written) == 0 {
|
||||
if w.Len() == 0 {
|
||||
t.Error("App did not write output to desired writer.")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user