From 0c897ccda06260aae85338bd63e2047bbd49880e Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Tue, 31 Mar 2020 15:06:22 -0400 Subject: [PATCH] cni: fix assertion ordering in tests with multiple node networks --- client/client_test.go | 7 ++++--- client/fingerprint/cni_test.go | 5 ++++- client/fingerprint/env_aws.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index a9793ebaf04..6bde661462c 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1263,7 +1263,7 @@ func Test_UpdateNodeFromFingerprintMultiIP(t *testing.T) { // Client without network configured updates to match fingerprint client, cleanup := TestClient(t, func(c *config.Config) { c.NetworkInterface = dev - c.Node.NodeResources.Networks[0].Device = dev + c.Options["fingerprint.blacklist"] = "network,cni,bridge" c.Node.Resources.Networks = c.Node.NodeResources.Networks }) defer cleanup() @@ -1278,12 +1278,13 @@ func Test_UpdateNodeFromFingerprintMultiIP(t *testing.T) { }, }) - two := structs.Networks{ + nets := structs.Networks{ + mock.Node().NodeResources.Networks[0], {Device: dev, IP: "127.0.0.1"}, {Device: dev, IP: "::1"}, } - require.Equal(t, two, client.config.Node.NodeResources.Networks) + require.Equal(t, nets, client.config.Node.NodeResources.Networks) } func TestClient_computeAllocatedDeviceStats(t *testing.T) { diff --git a/client/fingerprint/cni_test.go b/client/fingerprint/cni_test.go index d89a930b27a..169c636f208 100644 --- a/client/fingerprint/cni_test.go +++ b/client/fingerprint/cni_test.go @@ -72,7 +72,10 @@ func TestCNIFingerprint(t *testing.T) { require.Contains(err.Error(), c.errMatch) } else { require.NoError(err) - require.Exactly(c.exp, resp) + require.Equal(c.exp.Detected, resp.Detected) + if resp.NodeResources != nil || c.exp.NodeResources != nil { + require.ElementsMatch(c.exp.NodeResources.Networks, resp.NodeResources.Networks) + } } }) } diff --git a/client/fingerprint/env_aws.go b/client/fingerprint/env_aws.go index cd98375702f..4ccb9c3c216 100644 --- a/client/fingerprint/env_aws.go +++ b/client/fingerprint/env_aws.go @@ -133,7 +133,7 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F response.AddAttribute("unique.network.ip-address", val) newNetwork := &structs.NetworkResource{ - Mode: "host", + Mode: "host", Device: "eth0", IP: val, CIDR: val + "/32",