-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtopojson_test.go
63 lines (51 loc) · 1.82 KB
/
topojson_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
59
60
61
62
63
package xonacatl
import (
"bytes"
"strings"
"testing"
)
func runCopyTopoJSON(input string, layers map[string]bool) (output string, err error) {
var buf bytes.Buffer
rd := strings.NewReader(input)
copier := NewCopyTopoJSONLayers(layers)
err = copier.CopyLayers(rd, &buf)
if err == nil {
output = buf.String()
}
return
}
func runCopyTopoJSONSuccess(input string, layers map[string]bool, t *testing.T) string {
out, err := runCopyTopoJSON(input, layers)
if err != nil {
t.Fatalf("CopyTopoJSONLayers(%#v) failed, error: %s", input, err.Error())
}
return out
}
func runCopyTopoJSONAssertOutput(input string, layers map[string]bool, expected string, t *testing.T) {
out := runCopyTopoJSONSuccess(input, layers, t)
// get rid of spurious failures due to trailing whitespace
out = strings.TrimSpace(out)
if out != expected {
t.Fatalf("Expected output of CopyTopoJSONLayers(%#v) to be %#v, but instead was %#v", input, expected, out)
}
}
const (
minimal = `{"type":"Topology","objects":{},"arcs":[]}`
foo = `{"type":"Topology","objects":{"foo":{"foo":false}},"arcs":[]}`
foobar = `{"type":"Topology","objects":{"bar":{"bar":false},"foo":{"foo":false}},"arcs":[]}`
)
func TestTopoJSONEmptyWithoutLayers(t *testing.T) {
runCopyTopoJSONAssertOutput(minimal, map[string]bool{}, minimal, t)
}
func TestTopoJSONEmptyWithLayers(t *testing.T) {
runCopyTopoJSONAssertOutput(minimal, map[string]bool{"foo": true}, minimal, t)
}
func TestTopoJSONNonEmptyWithoutLayers(t *testing.T) {
runCopyTopoJSONAssertOutput(foobar, map[string]bool{}, minimal, t)
}
func TestTopoJSONNonEmptyWithSingleLayer(t *testing.T) {
runCopyTopoJSONAssertOutput(foobar, map[string]bool{"foo": true}, foo, t)
}
func TestTopoJSONNonEmptyWithLayers(t *testing.T) {
runCopyTopoJSONAssertOutput(foobar, map[string]bool{"foo": true, "bar": true}, foobar, t)
}