github.com/outbrain/consul@v1.4.5/testutil/server_wrapper.go (about)

     1  package testutil
     2  
     3  import "testing"
     4  
     5  type WrappedServer struct {
     6  	s *TestServer
     7  	t *testing.T
     8  }
     9  
    10  // Wrap wraps the test server in a `testing.t` for convenience.
    11  //
    12  // For example, the following code snippets are equivalent.
    13  //
    14  //   server.JoinLAN(t, "1.2.3.4")
    15  //   server.Wrap(t).JoinLAN("1.2.3.4")
    16  //
    17  // This is useful when you are calling multiple functions and save the wrapped
    18  // value as another variable to reduce the inclusion of "t".
    19  func (s *TestServer) Wrap(t *testing.T) *WrappedServer {
    20  	return &WrappedServer{s, t}
    21  }
    22  
    23  func (w *WrappedServer) JoinLAN(addr string) {
    24  	w.s.JoinLAN(w.t, addr)
    25  }
    26  
    27  func (w *WrappedServer) JoinWAN(addr string) {
    28  	w.s.JoinWAN(w.t, addr)
    29  }
    30  
    31  func (w *WrappedServer) SetKV(key string, val []byte) {
    32  	w.s.SetKV(w.t, key, val)
    33  }
    34  
    35  func (w *WrappedServer) SetKVString(key string, val string) {
    36  	w.s.SetKVString(w.t, key, val)
    37  }
    38  
    39  func (w *WrappedServer) GetKV(key string) []byte {
    40  	return w.s.GetKV(w.t, key)
    41  }
    42  
    43  func (w *WrappedServer) GetKVString(key string) string {
    44  	return w.s.GetKVString(w.t, key)
    45  }
    46  
    47  func (w *WrappedServer) PopulateKV(data map[string][]byte) {
    48  	w.s.PopulateKV(w.t, data)
    49  }
    50  
    51  func (w *WrappedServer) ListKV(prefix string) []string {
    52  	return w.s.ListKV(w.t, prefix)
    53  }
    54  
    55  func (w *WrappedServer) AddService(name, status string, tags []string) {
    56  	w.s.AddService(w.t, name, status, tags)
    57  }
    58  
    59  func (w *WrappedServer) AddAddressableService(name, status, address string, port int, tags []string) {
    60  	w.s.AddAddressableService(w.t, name, status, address, port, tags)
    61  }
    62  
    63  func (w *WrappedServer) AddCheck(name, serviceID, status string) {
    64  	w.s.AddCheck(w.t, name, serviceID, status)
    65  }