|
|
|
@ -12,11 +12,11 @@ import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
|
|
msgpackrpc "github.com/hashicorp/consul-net-rpc/net-rpc-msgpackrpc"
|
|
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
@ -3716,21 +3716,34 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
|
require.NoError(t, msgpackrpc.CallWithCodec(codec, "Internal.AssignManualServiceVIPs", req, &resp))
|
|
|
|
|
|
|
|
|
|
type testcase struct {
|
|
|
|
|
name string
|
|
|
|
|
req structs.AssignServiceManualVIPsRequest
|
|
|
|
|
expect structs.AssignServiceManualVIPsResponse
|
|
|
|
|
expectErr string
|
|
|
|
|
name string
|
|
|
|
|
req structs.AssignServiceManualVIPsRequest
|
|
|
|
|
expect structs.AssignServiceManualVIPsResponse
|
|
|
|
|
expectAgain structs.AssignServiceManualVIPsResponse
|
|
|
|
|
expectErr string
|
|
|
|
|
}
|
|
|
|
|
run := func(t *testing.T, tc testcase) {
|
|
|
|
|
|
|
|
|
|
run := func(t *testing.T, tc testcase, again bool) {
|
|
|
|
|
if tc.expectErr != "" && again {
|
|
|
|
|
return // we don't retest known errors
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resp structs.AssignServiceManualVIPsResponse
|
|
|
|
|
idx1 := s1.raft.CommitIndex()
|
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "Internal.AssignManualServiceVIPs", tc.req, &resp)
|
|
|
|
|
idx2 := s1.raft.CommitIndex()
|
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
require.Contains(t, err.Error(), tc.expectErr)
|
|
|
|
|
return
|
|
|
|
|
testutil.RequireErrorContains(t, err, tc.expectErr)
|
|
|
|
|
} else {
|
|
|
|
|
if again {
|
|
|
|
|
require.Equal(t, tc.expectAgain, resp)
|
|
|
|
|
require.Equal(t, idx1, idx2, "no raft operations occurred")
|
|
|
|
|
} else {
|
|
|
|
|
require.Equal(t, tc.expect, resp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
require.Equal(t, tc.expect, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tcs := []testcase{
|
|
|
|
|
{
|
|
|
|
|
name: "successful manual ip assignment",
|
|
|
|
@ -3738,7 +3751,8 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
|
Service: "web",
|
|
|
|
|
ManualVIPs: []string{"1.1.1.1", "2.2.2.2"},
|
|
|
|
|
},
|
|
|
|
|
expect: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
|
expect: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
|
expectAgain: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "reassign existing ip",
|
|
|
|
@ -3754,6 +3768,8 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// When we repeat this operation the second time it's a no-op.
|
|
|
|
|
expectAgain: structs.AssignServiceManualVIPsResponse{Found: true},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "invalid ip",
|
|
|
|
@ -3767,7 +3783,14 @@ func TestInternal_AssignManualServiceVIPs(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
for _, tc := range tcs {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
run(t, tc)
|
|
|
|
|
t.Run("initial", func(t *testing.T) {
|
|
|
|
|
run(t, tc, false)
|
|
|
|
|
})
|
|
|
|
|
if tc.expectErr == "" {
|
|
|
|
|
t.Run("repeat", func(t *testing.T) {
|
|
|
|
|
run(t, tc, true) // only repeat a write if it isn't an known error
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|