(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func 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 | } |
nothing calls this directly
no test coverage detected