forked from barnybug/cli53
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatters_test.go
58 lines (49 loc) · 1.84 KB
/
formatters_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
50
51
52
53
54
55
56
57
58
package cli53
import (
"bytes"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/stretchr/testify/assert"
)
func testZones() chan *route53.HostedZone {
ret := make(chan *route53.HostedZone)
go func() {
zone := &route53.HostedZone{
Id: aws.String("/hostedzone/Z1RWMUCMCPKCJX"),
Name: aws.String("example.com."),
Config: &route53.HostedZoneConfig{
Comment: aws.String("comment"),
},
ResourceRecordSetCount: aws.Int64(2),
}
ret <- zone
close(ret)
}()
return ret
}
func formatTest(f Formatter) string {
w := &bytes.Buffer{}
f.formatZoneList(testZones(), w)
return w.String()
}
func TestTextFormatter(t *testing.T) {
f := &TextFormatter{}
assert.Equal(t, "{\n Config: {\n Comment: \"comment\"\n },\n Id: \"/hostedzone/Z1RWMUCMCPKCJX\",\n Name: \"example.com.\",\n ResourceRecordSetCount: 2\n}\n", formatTest(f))
}
func TestJsonFormatter(t *testing.T) {
f := &JsonFormatter{}
assert.Equal(t, "[{\"CallerReference\":null,\"Config\":{\"Comment\":\"comment\",\"PrivateZone\":null},\"Id\":\"/hostedzone/Z1RWMUCMCPKCJX\",\"LinkedService\":null,\"Name\":\"example.com.\",\"ResourceRecordSetCount\":2}]\n", formatTest(f))
}
func TestJlFormatter(t *testing.T) {
f := &JlFormatter{}
assert.Equal(t, "{\"CallerReference\":null,\"Config\":{\"Comment\":\"comment\",\"PrivateZone\":null},\"Id\":\"/hostedzone/Z1RWMUCMCPKCJX\",\"LinkedService\":null,\"Name\":\"example.com.\",\"ResourceRecordSetCount\":2}\n", formatTest(f))
}
func TestTableFormatter(t *testing.T) {
f := &TableFormatter{}
assert.Equal(t, "ID Name Record count Comment\nZ1RWMUCMCPKCJX example.com. 2 comment\n", formatTest(f))
}
func TestCSVFormatter(t *testing.T) {
f := &CSVFormatter{}
assert.Equal(t, "id,name,record count,comment\nZ1RWMUCMCPKCJX,example.com.,2,comment\n", formatTest(f))
}