-
Notifications
You must be signed in to change notification settings - Fork 4
/
render_test.go
49 lines (38 loc) · 1.17 KB
/
render_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2012 Numerotron Inc.
// Use of this source code is governed by an MIT-style license
// that can be found in the LICENSE file.
package bingo
import (
"testing"
)
func TestRenderCSV(t *testing.T) {
c := newTestContext()
data := [][]string{{"col1", "col2", "col3"}, {"abc", "def", "ghi"}}
err := RenderCSV(c, data, "")
if err != nil {
t.Errorf("unexpected app error: %q", err)
}
expected := "col1,col2,col3\nabc,def,ghi\n"
if c.body() != expected {
t.Errorf("expected csv %q, got %q", expected, c.body())
}
if c.contentType() != "text/csv" {
t.Errorf("didn't get csv content type: %q", c.contentType())
}
if c.contentDisposition() != "" {
t.Errorf("not expecting disposition, got %q", c.contentDisposition())
}
}
func TestRenderCSVFilename(t *testing.T) {
c := newTestContext()
data := [][]string{{"col1", "col2", "col3"}, {"abc", "def", "ghi"}}
filename := "download.csv"
err := RenderCSV(c, data, filename)
if err != nil {
t.Errorf("unexpected app error: %q", err)
}
expected := "attachment;filename=" + filename
if c.contentDisposition() != expected {
t.Errorf("expecting disposition %q, got %q", expected, c.contentDisposition())
}
}