@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"crypto"
22
22
"crypto/x509"
23
- "os"
24
23
"reflect"
25
24
"testing"
26
25
"time"
@@ -38,7 +37,14 @@ import (
38
37
testutil "github.com/cert-manager/csi-lib/test/util"
39
38
)
40
39
41
- func testResumesExistingRequest (t * testing.T , issueBeforeCall bool ) {
40
+ type WhenToCallIssue bool
41
+
42
+ const (
43
+ CallIssueDuringPublish = false
44
+ CallIssueBetweenPublish = true
45
+ )
46
+
47
+ func testResumesExistingRequest (t * testing.T , issueBeforeCall WhenToCallIssue ) {
42
48
store := storage .NewMemoryFS ()
43
49
ns := "certificaterequest-namespace"
44
50
clock := fakeclock .NewFakeClock (time .Now ())
@@ -66,13 +72,9 @@ func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
66
72
return store .WriteMetadata (meta .VolumeID , meta )
67
73
},
68
74
})
69
- defer stop ( )
75
+ t . Cleanup ( stop )
70
76
71
- tmpDir , err := os .MkdirTemp ("" , "*" )
72
- if err != nil {
73
- t .Fatal (err )
74
- }
75
- defer os .RemoveAll (tmpDir )
77
+ tmpDir := t .TempDir ()
76
78
77
79
// create a root, non-expiring context
78
80
ctx := context .Background ()
@@ -91,8 +93,8 @@ func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
91
93
92
94
// create a context that expires in 2s (enough time for at least a single call of `issue`)
93
95
twoSecondCtx , cancel := context .WithTimeout (ctx , time .Second * 2 )
94
- defer cancel ( )
95
- _ , err = cl .NodePublishVolume (twoSecondCtx , nodePublishVolumeRequest )
96
+ t . Cleanup ( cancel )
97
+ _ , err : = cl .NodePublishVolume (twoSecondCtx , nodePublishVolumeRequest )
96
98
// assert that an error has been returned - we don't mind what kind of error, as due to the async nature of
97
99
// de-registering metadata from the metadata store upon failures, there is a slim chance that a metadata read error
98
100
// can be returned instead of a deadline exceeded error.
@@ -155,11 +157,11 @@ func testResumesExistingRequest(t *testing.T, issueBeforeCall bool) {
155
157
}
156
158
157
159
func TestResumesExistingRequest_IssuedBetweenPublishCalls (t * testing.T ) {
158
- testResumesExistingRequest (t , true )
160
+ testResumesExistingRequest (t , CallIssueBetweenPublish )
159
161
}
160
162
161
163
func TestResumesExistingRequest_IssuedDuringPublishCall (t * testing.T ) {
162
- testResumesExistingRequest (t , false )
164
+ testResumesExistingRequest (t , CallIssueDuringPublish )
163
165
}
164
166
165
167
// ensureOneRequestExists will fail the test if more than a single CertificateRequest exists.
0 commit comments