(t *testing.T)
| 3038 | } |
| 3039 | |
| 3040 | func TestRequestCtxSendFileNotModified(t *testing.T) { |
| 3041 | t.Parallel() |
| 3042 | |
| 3043 | var ctx RequestCtx |
| 3044 | var req Request |
| 3045 | ctx.Init(&req, nil, defaultLogger) |
| 3046 | |
| 3047 | filePath := "./server_test.go" |
| 3048 | lastModified, err := FileLastModified(filePath) |
| 3049 | if err != nil { |
| 3050 | t.Fatalf("unexpected error: %v", err) |
| 3051 | } |
| 3052 | ctx.Request.Header.Set("If-Modified-Since", string(AppendHTTPDate(nil, lastModified))) |
| 3053 | |
| 3054 | ctx.SendFile(filePath) |
| 3055 | |
| 3056 | s := ctx.Response.String() |
| 3057 | |
| 3058 | var resp Response |
| 3059 | br := bufio.NewReader(bytes.NewBufferString(s)) |
| 3060 | if err := resp.Read(br); err != nil { |
| 3061 | t.Fatalf("error when reading response: %v", err) |
| 3062 | } |
| 3063 | if resp.StatusCode() != StatusNotModified { |
| 3064 | t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusNotModified) |
| 3065 | } |
| 3066 | if len(resp.Body()) > 0 { |
| 3067 | t.Fatalf("unexpected non-zero response body: %q", resp.Body()) |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | func TestRequestCtxSendFileModified(t *testing.T) { |
| 3072 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…