github.com/fastest963/consul@v1.4.5/agent/structs/testing_connect_proxy_config.go (about)

     1  package structs
     2  
     3  import "github.com/mitchellh/go-testing-interface"
     4  
     5  // TestConnectProxyConfig returns a ConnectProxyConfig representing a valid
     6  // Connect proxy.
     7  func TestConnectProxyConfig(t testing.T) ConnectProxyConfig {
     8  	return ConnectProxyConfig{
     9  		DestinationServiceName: "web",
    10  		Upstreams:              TestUpstreams(t),
    11  	}
    12  }
    13  
    14  // TestUpstreams returns a set of upstreams to be used in tests exercising most
    15  // important configuration patterns.
    16  func TestUpstreams(t testing.T) Upstreams {
    17  	return Upstreams{
    18  		{
    19  			// We rely on this one having default type in a few tests...
    20  			DestinationName: "db",
    21  			LocalBindPort:   9191,
    22  			Config: map[string]interface{}{
    23  				// Float because this is how it is decoded by JSON decoder so this
    24  				// enables the value returned to be compared directly to a decoded JSON
    25  				// response without spurios type loss.
    26  				"connect_timeout_ms": float64(1000),
    27  			},
    28  		},
    29  		{
    30  			DestinationType:  UpstreamDestTypePreparedQuery,
    31  			DestinationName:  "geo-cache",
    32  			LocalBindPort:    8181,
    33  			LocalBindAddress: "127.10.10.10",
    34  		},
    35  	}
    36  }
    37  
    38  // TestAddDefaultsToUpstreams takes an array of upstreams (such as that from
    39  // TestUpstreams) and adds default values that are populated during
    40  // refigistration. Use this for generating the expected Upstreams value after
    41  // registration.
    42  func TestAddDefaultsToUpstreams(t testing.T, upstreams []Upstream) Upstreams {
    43  	ups := make([]Upstream, len(upstreams))
    44  	for i := range upstreams {
    45  		ups[i] = upstreams[i]
    46  		// Fill in default fields we expect to have back explicitly in a response
    47  		if ups[i].DestinationType == "" {
    48  			ups[i].DestinationType = UpstreamDestTypeService
    49  		}
    50  	}
    51  	return ups
    52  }