(t *testing.T)
| 71 | } |
| 72 | |
| 73 | func TestSetContentDisposition(t *testing.T) { |
| 74 | t.Parallel() |
| 75 | |
| 76 | testCases := map[string]struct { |
| 77 | filename string |
| 78 | inline bool |
| 79 | expected string |
| 80 | }{ |
| 81 | "inline simple filename": { |
| 82 | filename: "document.pdf", |
| 83 | inline: true, |
| 84 | expected: "inline; filename*=utf-8''" + url.PathEscape("document.pdf"), |
| 85 | }, |
| 86 | "attachment simple filename": { |
| 87 | filename: "document.pdf", |
| 88 | inline: false, |
| 89 | expected: "attachment; filename*=utf-8''" + url.PathEscape("document.pdf"), |
| 90 | }, |
| 91 | "inline non-ASCII filename": { |
| 92 | filename: "日本語.txt", |
| 93 | inline: true, |
| 94 | expected: "inline; filename*=utf-8''" + url.PathEscape("日本語.txt"), |
| 95 | }, |
| 96 | "attachment non-ASCII filename": { |
| 97 | filename: "日本語.txt", |
| 98 | inline: false, |
| 99 | expected: "attachment; filename*=utf-8''" + url.PathEscape("日本語.txt"), |
| 100 | }, |
| 101 | "inline filename with spaces": { |
| 102 | filename: "my file.txt", |
| 103 | inline: true, |
| 104 | expected: "inline; filename*=utf-8''" + url.PathEscape("my file.txt"), |
| 105 | }, |
| 106 | "attachment filename with spaces": { |
| 107 | filename: "my file.txt", |
| 108 | inline: false, |
| 109 | expected: "attachment; filename*=utf-8''" + url.PathEscape("my file.txt"), |
| 110 | }, |
| 111 | } |
| 112 | |
| 113 | for name, tc := range testCases { |
| 114 | t.Run(name, func(t *testing.T) { |
| 115 | t.Parallel() |
| 116 | |
| 117 | recorder := httptest.NewRecorder() |
| 118 | req, err := http.NewRequest(http.MethodGet, "/test", http.NoBody) |
| 119 | if err != nil { |
| 120 | t.Fatalf("failed to create request: %v", err) |
| 121 | } |
| 122 | if tc.inline { |
| 123 | req.URL.RawQuery = "inline=true" |
| 124 | } |
| 125 | |
| 126 | file := &files.FileInfo{Name: tc.filename} |
| 127 | |
| 128 | setContentDisposition(recorder, req, file) |
| 129 | |
| 130 | got := recorder.Header().Get("Content-Disposition") |
nothing calls this directly
no test coverage detected