2831c8993d
* Move the watch package into the api module It was already just a thin wrapper around the API anyways. The biggest change was to the testing. Instead of using a test agent directly from the agent package it now uses the binary on the PATH just like the other API tests. The other big changes were to fix up the connect based watch tests so that we didn’t need to pull in the connect package (and therefore all of Consul)
51 lines
1 KiB
Go
51 lines
1 KiB
Go
package watch
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseBasic(t *testing.T) {
|
|
t.Parallel()
|
|
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) {
|
|
t.Parallel()
|
|
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
|
|
}
|