aboutsummaryrefslogtreecommitdiff
path: root/middleware/trace/setup_test.go
blob: 0b9ac8c42b41394874949204240dad961505e3b3 (plain) (blame)
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
package trace

import (
	"testing"

	"github.com/mholt/caddy"
)

func TestTraceParse(t *testing.T) {
	tests := []struct {
		input     string
		shouldErr bool
		endpoint  string
	}{
		// oks
		{`trace`, false, "http://localhost:9411/api/v1/spans"},
		{`trace localhost:1234`, false, "http://localhost:1234/api/v1/spans"},
		{`trace http://localhost:1234/somewhere/else`, false, "http://localhost:1234/somewhere/else"},
		{`trace zipkin localhost:1234`, false, "http://localhost:1234/api/v1/spans"},
		{`trace zipkin http://localhost:1234/somewhere/else`, false, "http://localhost:1234/somewhere/else"},
		// fails
		{`trace footype localhost:4321`, true, ""},
	}
	for i, test := range tests {
		c := caddy.NewTestController("dns", test.input)
		m, err := traceParse(c)
		if test.shouldErr && err == nil {
			t.Errorf("Test %v: Expected error but found nil", i)
			continue
		} else if !test.shouldErr && err != nil {
			t.Errorf("Test %v: Expected no error but found error: %v", i, err)
			continue
		}

		if test.shouldErr {
			continue
		}

		if test.endpoint != m.Endpoint {
			t.Errorf("Test %v: Expected endpoint %s but found: %s", i, test.endpoint, m.Endpoint)
		}
	}
}