/usr/share/gocode/src/github.com/hashicorp/consul/watch/watch_test.go is in golang-github-hashicorp-consul-dev 0.6.4~dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | package watch
import (
"bytes"
"encoding/json"
"testing"
)
func TestParseBasic(t *testing.T) {
params := makeParams(t, `{"type":"key", "datacenter":"dc2", "token":"12345", "key":"foo"}`)
p, err := Parse(params)
if err != nil {
t.Fatalf("err: %v", err)
}
if p.Datacenter != "dc2" {
t.Fatalf("Bad: %#v", p)
}
if p.Token != "12345" {
t.Fatalf("Bad: %#v", p)
}
if p.Type != "key" {
t.Fatalf("Bad: %#v", p)
}
}
func TestParse_exempt(t *testing.T) {
params := makeParams(t, `{"type":"key", "key":"foo", "handler": "foobar"}`)
p, err := ParseExempt(params, []string{"handler"})
if err != nil {
t.Fatalf("err: %v", err)
}
if p.Type != "key" {
t.Fatalf("Bad: %#v", p)
}
ex := p.Exempt["handler"]
if ex != "foobar" {
t.Fatalf("bad: %v", ex)
}
}
func makeParams(t *testing.T, s string) map[string]interface{} {
var out map[string]interface{}
dec := json.NewDecoder(bytes.NewReader([]byte(s)))
if err := dec.Decode(&out); err != nil {
t.Fatalf("err: %v", err)
}
return out
}
|