From 11df89c77858b21fd1d4fc4e35d099a75d963275 Mon Sep 17 00:00:00 2001 From: tanjing2020 Date: Fri, 19 Feb 2021 16:30:30 +0800 Subject: [PATCH] attacher: organize unit tests into subtests --- pkg/volume/awsebs/attacher_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/volume/awsebs/attacher_test.go b/pkg/volume/awsebs/attacher_test.go index 1a360080106..5f2a039545a 100644 --- a/pkg/volume/awsebs/attacher_test.go +++ b/pkg/volume/awsebs/attacher_test.go @@ -62,7 +62,7 @@ func TestGetVolumeName_PersistentVolume(t *testing.T) { // One testcase for TestAttachDetach table test below type testcase struct { - name aws.KubernetesVolumeID + name string // For fake AWS: attach attachCall detach detachCall @@ -128,15 +128,16 @@ func TestAttachDetach(t *testing.T) { } for _, testcase := range tests { - testcase.t = t - device, err := testcase.test(&testcase) - if err != testcase.expectedError { - t.Errorf("%s failed: expected err=%q, got %q", testcase.name, testcase.expectedError.Error(), err.Error()) - } - if device != testcase.expectedDevice { - t.Errorf("%s failed: expected device=%q, got %q", testcase.name, testcase.expectedDevice, device) - } - t.Logf("Test %q succeeded", testcase.name) + t.Run(testcase.name, func(t *testing.T) { + testcase.t = t + device, err := testcase.test(&testcase) + if err != testcase.expectedError { + t.Errorf("failed: expected err=%q, got %q", testcase.expectedError.Error(), err.Error()) + } + if device != testcase.expectedDevice { + t.Errorf("failed: expected device=%q, got %q", testcase.expectedDevice, device) + } + }) } }