command/agent/consul: remove duplicated tests
This commit is contained in:
parent
ab01e19df3
commit
bb060bd46b
|
@ -4,9 +4,6 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/plugins/drivers"
|
||||
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -303,77 +300,3 @@ func TestSyncLogic_maybeTweakTags_emptySC(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestServiceClient_getAddress(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
addrMode string
|
||||
portLabel string
|
||||
networks structs.Networks
|
||||
driverNet *drivers.DriverNetwork
|
||||
ports structs.AllocatedPorts
|
||||
netStatus *structs.AllocNetworkStatus
|
||||
resultAddr string
|
||||
resultPort int
|
||||
resultHasErr bool
|
||||
}{
|
||||
{
|
||||
name: "nil case",
|
||||
resultHasErr: true,
|
||||
},
|
||||
{
|
||||
name: "auto happy path",
|
||||
addrMode: "auto",
|
||||
portLabel: "www",
|
||||
ports: []structs.AllocatedPortMapping{
|
||||
{
|
||||
"www",
|
||||
80,
|
||||
80,
|
||||
"10.0.0.1",
|
||||
},
|
||||
},
|
||||
resultAddr: "10.0.0.1",
|
||||
resultPort: 80,
|
||||
},
|
||||
{
|
||||
name: "alloc mode with to value",
|
||||
addrMode: "alloc",
|
||||
portLabel: "www",
|
||||
ports: []structs.AllocatedPortMapping{{"www", 22222, 80, "10.0.0.1"}},
|
||||
netStatus: &structs.AllocNetworkStatus{
|
||||
|
||||
Address: "172.16.0.1",
|
||||
},
|
||||
resultAddr: "172.16.0.1",
|
||||
resultPort: 80,
|
||||
},
|
||||
{
|
||||
name: "alloc mode without to value",
|
||||
addrMode: "alloc",
|
||||
portLabel: "www",
|
||||
ports: []structs.AllocatedPortMapping{{"www", 22222, 0, "10.0.0.1"}},
|
||||
netStatus: &structs.AllocNetworkStatus{
|
||||
|
||||
Address: "172.16.0.1",
|
||||
},
|
||||
resultAddr: "172.16.0.1",
|
||||
resultPort: 22222,
|
||||
},
|
||||
}
|
||||
require := require.New(t)
|
||||
for _, c := range cases {
|
||||
tc := c
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
|
||||
addr, port, err := getAddress(tc.addrMode, tc.portLabel, tc.networks, tc.driverNet, tc.ports, tc.netStatus)
|
||||
if tc.resultHasErr {
|
||||
require.Error(err)
|
||||
return
|
||||
}
|
||||
require.Equal(addr, tc.resultAddr)
|
||||
require.Equal(port, tc.resultPort)
|
||||
require.NoError(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1632,6 +1632,24 @@ func TestGetAddress(t *testing.T) {
|
|||
Address: "172.26.0.1",
|
||||
},
|
||||
ExpectedIP: "172.26.0.1",
|
||||
ExpectedPort: 6379,
|
||||
},
|
||||
{
|
||||
Name: "Alloc no to value",
|
||||
Mode: structs.AddressModeAlloc,
|
||||
PortLabel: "db",
|
||||
Ports: []structs.AllocatedPortMapping{
|
||||
{
|
||||
Label: "db",
|
||||
Value: 12345,
|
||||
HostIP: HostIP,
|
||||
},
|
||||
},
|
||||
Status: &structs.AllocNetworkStatus{
|
||||
InterfaceName: "eth0",
|
||||
Address: "172.26.0.1",
|
||||
},
|
||||
ExpectedIP: "172.26.0.1",
|
||||
ExpectedPort: 12345,
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue