From 92e8b5b95357c4823e408177636bbd94f95b2cce Mon Sep 17 00:00:00 2001 From: Andrew Kim Date: Fri, 1 Feb 2019 14:55:25 -0500 Subject: [PATCH] refactor AddToNodeAddresses test to use t.Run and include description --- .../cloud-provider/node/helpers/address_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/cloud-provider/node/helpers/address_test.go b/staging/src/k8s.io/cloud-provider/node/helpers/address_test.go index f3bdd7c069..e5dffb6f63 100644 --- a/staging/src/k8s.io/cloud-provider/node/helpers/address_test.go +++ b/staging/src/k8s.io/cloud-provider/node/helpers/address_test.go @@ -25,16 +25,19 @@ import ( func TestAddToNodeAddresses(t *testing.T) { testCases := []struct { + name string existing []v1.NodeAddress toAdd []v1.NodeAddress expected []v1.NodeAddress }{ { + name: "add no addresses to empty node addresses", existing: []v1.NodeAddress{}, toAdd: []v1.NodeAddress{}, expected: []v1.NodeAddress{}, }, { + name: "add new node addresses to empty existing addresses", existing: []v1.NodeAddress{}, toAdd: []v1.NodeAddress{ {Type: v1.NodeExternalIP, Address: "1.1.1.1"}, @@ -46,6 +49,7 @@ func TestAddToNodeAddresses(t *testing.T) { }, }, { + name: "add a duplicate node address", existing: []v1.NodeAddress{}, toAdd: []v1.NodeAddress{ {Type: v1.NodeExternalIP, Address: "1.1.1.1"}, @@ -56,6 +60,7 @@ func TestAddToNodeAddresses(t *testing.T) { }, }, { + name: "add 1 new and 1 duplicate address", existing: []v1.NodeAddress{ {Type: v1.NodeExternalIP, Address: "1.1.1.1"}, {Type: v1.NodeInternalIP, Address: "10.1.1.1"}, @@ -72,10 +77,12 @@ func TestAddToNodeAddresses(t *testing.T) { }, } - for i, tc := range testCases { - AddToNodeAddresses(&tc.existing, tc.toAdd...) - if !apiequality.Semantic.DeepEqual(tc.expected, tc.existing) { - t.Errorf("case[%d], expected: %v, got: %v", i, tc.expected, tc.existing) - } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + AddToNodeAddresses(&tc.existing, tc.toAdd...) + if !apiequality.Semantic.DeepEqual(tc.expected, tc.existing) { + t.Errorf("expected: %v, got: %v", tc.expected, tc.existing) + } + }) } }