From 4db54a151b09cad57a16f09f18f7121476e8d593 Mon Sep 17 00:00:00 2001 From: Emman Date: Wed, 28 Feb 2018 01:05:00 +0800 Subject: [PATCH] Add relevant tests for FileAttachment method --- context_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/context_test.go b/context_test.go index 9024cfc1..af45e096 100644 --- a/context_test.go +++ b/context_test.go @@ -856,6 +856,19 @@ func TestContextRenderFile(t *testing.T) { assert.Equal(t, "text/plain; charset=utf-8", w.HeaderMap.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 // and Content-Type is set to application/x-yaml func TestContextRenderYAML(t *testing.T) {