2017-03-23 20:26:05 +00:00
|
|
|
package testutil
|
|
|
|
|
2017-04-21 03:14:10 +00:00
|
|
|
import "testing"
|
2017-03-23 20:26:05 +00:00
|
|
|
|
|
|
|
type WrappedServer struct {
|
|
|
|
s *TestServer
|
|
|
|
t *testing.T
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrap wraps the test server in a `testing.t` for convenience.
|
|
|
|
//
|
|
|
|
// For example, the following code snippets are equivalent.
|
|
|
|
//
|
|
|
|
// server.JoinLAN(t, "1.2.3.4")
|
|
|
|
// server.Wrap(t).JoinLAN("1.2.3.4")
|
|
|
|
//
|
|
|
|
// This is useful when you are calling multiple functions and save the wrapped
|
|
|
|
// value as another variable to reduce the inclusion of "t".
|
|
|
|
func (s *TestServer) Wrap(t *testing.T) *WrappedServer {
|
2017-04-21 03:14:10 +00:00
|
|
|
return &WrappedServer{s, t}
|
2017-03-23 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) JoinLAN(addr string) {
|
|
|
|
w.s.JoinLAN(w.t, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) JoinWAN(addr string) {
|
|
|
|
w.s.JoinWAN(w.t, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) SetKV(key string, val []byte) {
|
|
|
|
w.s.SetKV(w.t, key, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) SetKVString(key string, val string) {
|
|
|
|
w.s.SetKVString(w.t, key, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) GetKV(key string) []byte {
|
|
|
|
return w.s.GetKV(w.t, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) GetKVString(key string) string {
|
|
|
|
return w.s.GetKVString(w.t, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) PopulateKV(data map[string][]byte) {
|
|
|
|
w.s.PopulateKV(w.t, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) ListKV(prefix string) []string {
|
|
|
|
return w.s.ListKV(w.t, prefix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *WrappedServer) AddService(name, status string, tags []string) {
|
|
|
|
w.s.AddService(w.t, name, status, tags)
|
|
|
|
}
|
|
|
|
|
2016-09-30 06:26:12 +00:00
|
|
|
func (w *WrappedServer) AddAddressableService(name, status, address string, port int, tags []string) {
|
|
|
|
w.s.AddAddressableService(w.t, name, status, address, port, tags)
|
|
|
|
}
|
|
|
|
|
2017-03-23 20:26:05 +00:00
|
|
|
func (w *WrappedServer) AddCheck(name, serviceID, status string) {
|
|
|
|
w.s.AddCheck(w.t, name, serviceID, status)
|
|
|
|
}
|