mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 02:48:19 +00:00
agent: fix crash that could happen if proxy was nil on load
This commit is contained in:
parent
420edc4c1e
commit
6539280f2a
@ -2523,6 +2523,9 @@ func (a *Agent) loadProxies(conf *config.RuntimeConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed adding proxy: %s", err)
|
return fmt.Errorf("failed adding proxy: %s", err)
|
||||||
}
|
}
|
||||||
|
if proxy == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := a.AddProxy(proxy, false); err != nil {
|
if err := a.AddProxy(proxy, false); err != nil {
|
||||||
return fmt.Errorf("failed adding proxy: %s", err)
|
return fmt.Errorf("failed adding proxy: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/checks"
|
"github.com/hashicorp/consul/agent/checks"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
@ -25,6 +23,7 @@ import (
|
|||||||
"github.com/hashicorp/consul/types"
|
"github.com/hashicorp/consul/types"
|
||||||
uuid "github.com/hashicorp/go-uuid"
|
uuid "github.com/hashicorp/go-uuid"
|
||||||
"github.com/pascaldekloe/goe/verify"
|
"github.com/pascaldekloe/goe/verify"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func externalIP() (string, error) {
|
func externalIP() (string, error) {
|
||||||
@ -1669,6 +1668,27 @@ func TestAgent_loadProxies(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAgent_loadProxies_nilProxy(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
a := NewTestAgent(t.Name(), `
|
||||||
|
service = {
|
||||||
|
id = "rabbitmq"
|
||||||
|
name = "rabbitmq"
|
||||||
|
port = 5672
|
||||||
|
token = "abc123"
|
||||||
|
connect {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
defer a.Shutdown()
|
||||||
|
|
||||||
|
services := a.State.Services()
|
||||||
|
require.Contains(t, services, "rabbitmq")
|
||||||
|
require.Equal(t, "abc123", a.State.ServiceToken("rabbitmq"))
|
||||||
|
require.NotContains(t, services, "rabbitme-proxy")
|
||||||
|
require.Empty(t, a.State.Proxies())
|
||||||
|
}
|
||||||
|
|
||||||
func TestAgent_unloadProxies(t *testing.T) {
|
func TestAgent_unloadProxies(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
a := NewTestAgent(t.Name(), `
|
a := NewTestAgent(t.Name(), `
|
||||||
|
Loading…
x
Reference in New Issue
Block a user