aboutsummaryrefslogtreecommitdiff
path: root/core/caddyfile/json_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-03-19 14:55:26 +0000
committerGravatar Miek Gieben <miek@miek.nl> 2016-03-19 14:55:26 +0000
commit0ed79664dbcb8e2326004bdcfc9b3195455bbaba (patch)
treebd77e3659338b4103ec964dfc59927c144410de6 /core/caddyfile/json_test.go
parentd933bb26668583bf49d9ae87752fdb139a57e21c (diff)
downloadcoredns-0ed79664dbcb8e2326004bdcfc9b3195455bbaba.tar.gz
coredns-0ed79664dbcb8e2326004bdcfc9b3195455bbaba.tar.zst
coredns-0ed79664dbcb8e2326004bdcfc9b3195455bbaba.zip
Fix more tests and remove json caddyfile stuff
Diffstat (limited to 'core/caddyfile/json_test.go')
-rw-r--r--core/caddyfile/json_test.go161
1 files changed, 0 insertions, 161 deletions
diff --git a/core/caddyfile/json_test.go b/core/caddyfile/json_test.go
deleted file mode 100644
index c3296a98f..000000000
--- a/core/caddyfile/json_test.go
+++ /dev/null
@@ -1,161 +0,0 @@
-package caddyfile
-
-import "testing"
-
-var tests = []struct {
- caddyfile, json string
-}{
- { // 0
- caddyfile: `foo {
- root /bar
-}`,
- json: `[{"hosts":["foo"],"body":[["root","/bar"]]}]`,
- },
- { // 1
- caddyfile: `host1, host2 {
- dir {
- def
- }
-}`,
- json: `[{"hosts":["host1","host2"],"body":[["dir",[["def"]]]]}]`,
- },
- { // 2
- caddyfile: `host1, host2 {
- dir abc {
- def ghi
- jkl
- }
-}`,
- json: `[{"hosts":["host1","host2"],"body":[["dir","abc",[["def","ghi"],["jkl"]]]]}]`,
- },
- { // 3
- caddyfile: `host1:1234, host2:5678 {
- dir abc {
- }
-}`,
- json: `[{"hosts":["host1:1234","host2:5678"],"body":[["dir","abc",[]]]}]`,
- },
- { // 4
- caddyfile: `host {
- foo "bar baz"
-}`,
- json: `[{"hosts":["host"],"body":[["foo","bar baz"]]}]`,
- },
- { // 5
- caddyfile: `host, host:80 {
- foo "bar \"baz\""
-}`,
- json: `[{"hosts":["host","host:80"],"body":[["foo","bar \"baz\""]]}]`,
- },
- { // 6
- caddyfile: `host {
- foo "bar
-baz"
-}`,
- json: `[{"hosts":["host"],"body":[["foo","bar\nbaz"]]}]`,
- },
- { // 7
- caddyfile: `host {
- dir 123 4.56 true
-}`,
- json: `[{"hosts":["host"],"body":[["dir","123","4.56","true"]]}]`, // NOTE: I guess we assume numbers and booleans should be encoded as strings...?
- },
- { // 8
- caddyfile: `host, host {
-}`,
- json: `[{"hosts":["host","host"],"body":[]}]`, // hosts in JSON are always host:port format (if port is specified), for consistency
- },
- { // 9
- caddyfile: `host {
- dir1 a b
- dir2 c d
-}`,
- json: `[{"hosts":["host"],"body":[["dir1","a","b"],["dir2","c","d"]]}]`,
- },
- { // 10
- caddyfile: `host {
- dir a b
- dir c d
-}`,
- json: `[{"hosts":["host"],"body":[["dir","a","b"],["dir","c","d"]]}]`,
- },
- { // 11
- caddyfile: `host {
- dir1 a b
- dir2 {
- c
- d
- }
-}`,
- json: `[{"hosts":["host"],"body":[["dir1","a","b"],["dir2",[["c"],["d"]]]]}]`,
- },
- { // 12
- caddyfile: `host1 {
- dir1
-}
-
-host2 {
- dir2
-}`,
- json: `[{"hosts":["host1"],"body":[["dir1"]]},{"hosts":["host2"],"body":[["dir2"]]}]`,
- },
-}
-
-func TestToJSON(t *testing.T) {
- for i, test := range tests {
- output, err := ToJSON([]byte(test.caddyfile))
- if err != nil {
- t.Errorf("Test %d: %v", i, err)
- }
- if string(output) != test.json {
- t.Errorf("Test %d\nExpected:\n'%s'\nActual:\n'%s'", i, test.json, string(output))
- }
- }
-}
-
-func TestFromJSON(t *testing.T) {
- for i, test := range tests {
- output, err := FromJSON([]byte(test.json))
- if err != nil {
- t.Errorf("Test %d: %v", i, err)
- }
- if string(output) != test.caddyfile {
- t.Errorf("Test %d\nExpected:\n'%s'\nActual:\n'%s'", i, test.caddyfile, string(output))
- }
- }
-}
-
-func TestStandardizeAddress(t *testing.T) {
- // host:https should be converted to https://host
- output, err := ToJSON([]byte(`host:https`))
- if err != nil {
- t.Fatal(err)
- }
- if expected, actual := `[{"hosts":["https://host"],"body":[]}]`, string(output); expected != actual {
- t.Errorf("Expected:\n'%s'\nActual:\n'%s'", expected, actual)
- }
-
- output, err = FromJSON([]byte(`[{"hosts":["https://host"],"body":[]}]`))
- if err != nil {
- t.Fatal(err)
- }
- if expected, actual := "https://host {\n}", string(output); expected != actual {
- t.Errorf("Expected:\n'%s'\nActual:\n'%s'", expected, actual)
- }
-
- // host: should be converted to just host
- output, err = ToJSON([]byte(`host:`))
- if err != nil {
- t.Fatal(err)
- }
- if expected, actual := `[{"hosts":["host"],"body":[]}]`, string(output); expected != actual {
- t.Errorf("Expected:\n'%s'\nActual:\n'%s'", expected, actual)
- }
- output, err = FromJSON([]byte(`[{"hosts":["host:"],"body":[]}]`))
- if err != nil {
- t.Fatal(err)
- }
- if expected, actual := "host {\n}", string(output); expected != actual {
- t.Errorf("Expected:\n'%s'\nActual:\n'%s'", expected, actual)
- }
-}