(t *testing.T)
| 160 | func (b readBootFile) WriteBootFile(id ID, r io.Reader) error { return errors.New("no") } |
| 161 | |
| 162 | func TestFile(t *testing.T) { |
| 163 | log := func(subsystem, msg string) { t.Logf("[%s] %s", subsystem, msg) } |
| 164 | s := &Server{ |
| 165 | Booter: readBootFile("stuff"), |
| 166 | Log: log, |
| 167 | Debug: log, |
| 168 | } |
| 169 | rr := httptest.NewRecorder() |
| 170 | req, err := http.NewRequest("GET", "/_/file?name=test", nil) |
| 171 | if err != nil { |
| 172 | t.Fatalf("Constructing file request: %s", err) |
| 173 | } |
| 174 | s.handleFile(rr, req) |
| 175 | |
| 176 | if rr.Code != 200 { |
| 177 | t.Fatalf("Got HTTP %d from request, expected 200", rr.Code) |
| 178 | } |
| 179 | |
| 180 | expected := "test stuff" |
| 181 | if rr.Body.String() != expected { |
| 182 | t.Fatalf("Wrong file contents, want %q, got %q", expected, rr.Body.Bytes()) |
| 183 | } |
| 184 | |
| 185 | rr = httptest.NewRecorder() |
| 186 | req, err = http.NewRequest("GET", "/_/file?name=quux", nil) |
| 187 | if err != nil { |
| 188 | t.Fatalf("Constructing file request: %s", err) |
| 189 | } |
| 190 | s.handleFile(rr, req) |
| 191 | |
| 192 | if rr.Code != 200 { |
| 193 | t.Fatalf("Got HTTP %d from request, expected 200", rr.Code) |
| 194 | } |
| 195 | |
| 196 | expected = "quux stuff" |
| 197 | if rr.Body.String() != expected { |
| 198 | t.Fatalf("Wrong file contents, want %q, got %q", expected, rr.Body.Bytes()) |
| 199 | } |
| 200 | } |
nothing calls this directly
no test coverage detected