|
@@ -979,6 +979,19 @@ func TestContextRenderFile(t *testing.T) {
|
|
|
assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type"))
|
|
assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type"))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestContextRenderAttachment(t *testing.T) {
|
|
|
|
|
+ w := httptest.NewRecorder()
|
|
|
|
|
+ c, _ := CreateTestContext(w)
|
|
|
|
|
+ newFilename := "new_filename.go"
|
|
|
|
|
+
|
|
|
|
|
+ c.Request, _ = http.NewRequest("GET", "/", nil)
|
|
|
|
|
+ c.FileAttachment("./gin.go", newFilename)
|
|
|
|
|
+
|
|
|
|
|
+ assert.Equal(t, 200, w.Code)
|
|
|
|
|
+ assert.Contains(t, w.Body.String(), "func New() *Engine {")
|
|
|
|
|
+ assert.Equal(t, fmt.Sprintf("attachment; filename=\"%s\"", newFilename), w.HeaderMap.Get("Content-Disposition"))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// TestContextRenderYAML tests that the response is serialized as YAML
|
|
// TestContextRenderYAML tests that the response is serialized as YAML
|
|
|
// and Content-Type is set to application/x-yaml
|
|
// and Content-Type is set to application/x-yaml
|
|
|
func TestContextRenderYAML(t *testing.T) {
|
|
func TestContextRenderYAML(t *testing.T) {
|