MCPcopy Create free account
hub / github.com/basecamp/hey-cli / TestTodoAddStdin

Function TestTodoAddStdin

internal/cmd/todo_test.go:145–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

143}
144
145func TestTodoAddStdin(t *testing.T) {
146 server := todoServer(t)
147 defer server.Close()
148
149 // Replace stdin with a pipe
150 r, w, err := os.Pipe()
151 if err != nil {
152 t.Fatal(err)
153 }
154 oldStdin := os.Stdin
155 os.Stdin = r
156 defer func() { os.Stdin = oldStdin }()
157
158 go func() {
159 w.Write([]byte("Buy milk from stdin\n"))
160 w.Close()
161 }()
162
163 resp, err := runTodoAdd(t, server)
164 if err != nil {
165 t.Fatalf("execute: %v", err)
166 }
167
168 data, ok := resp.Data.(map[string]any)
169 if !ok {
170 t.Fatalf("data type = %T, want map[string]any", resp.Data)
171 }
172 if got := data["title"]; got != "Buy milk from stdin" {
173 t.Errorf("title = %q, want %q", got, "Buy milk from stdin")
174 }
175}

Callers

nothing calls this directly

Calls 2

todoServerFunction · 0.85
runTodoAddFunction · 0.85

Tested by

no test coverage detected