Fix up tests broken by master merge; add proxy tests to services command (and fix it!); actually run the proxycfg.Manager

This commit is contained in:
Paul Banks 2018-10-04 14:08:12 +01:00
parent a28e4a33b2
commit 161482d2cd
6 changed files with 93 additions and 11 deletions

View File

@ -442,6 +442,11 @@ func (a *Agent) Start() error {
if err != nil {
return err
}
go func() {
if err := a.proxyConfig.Run(); err != nil {
a.logger.Printf("[ERR] Proxy Config Manager exited: %s", err)
}
}()
// Start watching for critical services to deregister, based on their
// checks.

View File

@ -352,6 +352,14 @@ func (s *HTTPServer) AgentService(resp http.ResponseWriter, req *http.Request) (
proxy = svc.Proxy.ToAPI()
}
var weights api.AgentWeights
if svc.Weights != nil {
err := mapstructure.Decode(svc.Weights, &weights)
if err != nil {
return "", nil, err
}
}
// Calculate the content hash over the response, minus the hash field
reply := &api.AgentService{
Kind: api.ServiceKind(svc.Kind),
@ -362,6 +370,7 @@ func (s *HTTPServer) AgentService(resp http.ResponseWriter, req *http.Request) (
Port: svc.Port,
Address: svc.Address,
EnableTagOverride: svc.EnableTagOverride,
Weights: weights,
Proxy: proxy,
Connect: connect,
}

View File

@ -250,6 +250,10 @@ func TestAgent_Service(t *testing.T) {
},
Port: 8000,
Proxy: &proxy,
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
}
// Define an updated version. Be careful to copy it.
@ -268,20 +272,28 @@ func TestAgent_Service(t *testing.T) {
Service: "web-sidecar-proxy",
Port: 8000,
Proxy: expectProxy.ToAPI(),
ContentHash: "26959a754e182054",
ContentHash: "3442362e971c43d1",
Weights: api.AgentWeights{
Passing: 1,
Warning: 1,
},
}
// Copy and modify
updatedResponse := *expectedResponse
updatedResponse.Port = 9999
updatedResponse.ContentHash = "1bdcf042660b33f6"
updatedResponse.ContentHash = "90b5c19bf0f5073"
// Simple response for non-proxy service regustered in TestAgent config
// Simple response for non-proxy service registered in TestAgent config
expectWebResponse := &api.AgentService{
ID: "web",
Service: "web",
Port: 8181,
ContentHash: "7be2b0411161d3b1",
ContentHash: "69351c1ac865b034",
Weights: api.AgentWeights{
Passing: 1,
Warning: 1,
},
}
tests := []struct {

View File

@ -2505,8 +2505,16 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
},
},
},
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
},
},
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
},
}
},
@ -2592,8 +2600,16 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
},
},
},
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
},
},
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
},
}
},
@ -4209,7 +4225,12 @@ func TestFullConfig(t *testing.T) {
// it can make intelligent decisions about automatic port assignments
// etc. So we expect config just to pass it through verbatim.
Connect: &structs.ServiceConnect{
SidecarService: &structs.ServiceDefinition{},
SidecarService: &structs.ServiceDefinition{
Weights: &structs.Weights{
Passing: 1,
Warning: 1,
},
},
},
},
{

View File

@ -673,7 +673,7 @@ func TestAPI_AgentService(t *testing.T) {
ID: "foo",
Service: "foo",
Tags: []string{"bar", "baz"},
ContentHash: "bf5bd67c5d74b26d",
ContentHash: "5d286f5494330b04",
Port: 8000,
}
require.Equal(expect, got)
@ -683,7 +683,7 @@ func TestAPI_AgentService(t *testing.T) {
// agent endpoint tests but this ensures that the API package is at least
// passing the hash param properly.
opts := QueryOptions{
WaitHash: "bf5bd67c5d74b26d",
WaitHash: "5d286f5494330b04",
WaitTime: 100 * time.Millisecond, // Just long enough to be reliably measurable
}
start := time.Now()

View File

@ -88,9 +88,47 @@ func TestStructsToAgentService(t *testing.T) {
},
},
},
{
"Proxy service",
&structs.ServiceDefinition{
Name: "web-proxy",
Kind: structs.ServiceKindConnectProxy,
Tags: []string{"leader"},
Port: 1234,
Proxy: &structs.ConnectProxyConfig{
DestinationServiceID: "web1",
DestinationServiceName: "web",
LocalServiceAddress: "127.0.0.1",
LocalServicePort: 8181,
Upstreams: structs.TestUpstreams(t),
Config: map[string]interface{}{
"foo": "bar",
},
},
},
&api.AgentServiceRegistration{
Name: "web-proxy",
Tags: []string{"leader"},
Port: 1234,
Kind: api.ServiceKindConnectProxy,
Proxy: &api.AgentServiceConnectProxyConfig{
DestinationServiceID: "web1",
DestinationServiceName: "web",
LocalServiceAddress: "127.0.0.1",
LocalServicePort: 8181,
Upstreams: structs.TestUpstreams(t).ToAPI(),
Config: map[string]interface{}{
"foo": "bar",
},
},
},
},
}
for _, tc := range cases {
for _, tt := range cases {
// Capture the loop variable locally otherwise parallel will cause us to run
// N copies of the last test case but with different names!!
tc := tt
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
require := require.New(t)
@ -100,6 +138,3 @@ func TestStructsToAgentService(t *testing.T) {
})
}
}
func intPtr(v int) *int { return &v }
func strPtr(v string) *string { return &v }