Skip to content

Commit e9f7ae7

Browse files
committed
adding local variable for seconds convert
1 parent 08a2416 commit e9f7ae7

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

dependency/vault_common_test.go

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ func init() {
2121
func TestVaultRenewDuration(t *testing.T) {
2222
renewable := Secret{LeaseDuration: 100, Renewable: true}
2323
renewableDur, _ := leaseCheckWait(&renewable)
24-
if renewableDur < 16*time.Second || renewableDur >= 34*time.Second {
25-
t.Fatalf("renewable duration is not within 1/6 to 1/3 of lease duration: %f", renewableDur.Seconds())
24+
renewableDurSec := renewableDur.Seconds()
25+
if renewableDurSec < 16 || renewableDurSec >= 34 {
26+
t.Fatalf("renewable duration is not within 1/6 to 1/3 of lease duration: %f", renewableDurSec)
2627
}
2728

2829
nonRenewable := Secret{LeaseDuration: 100}
2930
nonRenewableDur, _ := leaseCheckWait(&nonRenewable)
30-
if nonRenewableDur < 80*time.Second || nonRenewableDur > 95*time.Second {
31-
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", nonRenewableDur.Seconds())
31+
nonRenewableDurSec := nonRenewableDur.Seconds()
32+
33+
if nonRenewableDurSec < 80 || nonRenewableDurSec > 95 {
34+
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", nonRenewableDurSec)
3235
}
3336

3437
data := map[string]interface{}{
@@ -38,9 +41,10 @@ func TestVaultRenewDuration(t *testing.T) {
3841

3942
nonRenewableRotated := Secret{LeaseDuration: 100, Data: data}
4043
nonRenewableRotatedDur, _ := leaseCheckWait(&nonRenewableRotated)
44+
nonRenewableRotatedDurSec := nonRenewableRotatedDur.Seconds()
4145
// We expect a 1 second cushion
42-
if nonRenewableRotatedDur != 31*time.Second {
43-
t.Fatalf("renewable duration is not 31: %f", nonRenewableRotatedDur.Seconds())
46+
if nonRenewableRotatedDurSec != 31 {
47+
t.Fatalf("renewable duration is not 31: %f", nonRenewableRotatedDurSec)
4448
}
4549

4650
data = map[string]interface{}{
@@ -50,9 +54,10 @@ func TestVaultRenewDuration(t *testing.T) {
5054

5155
nonRenewableRotated = Secret{LeaseDuration: 100, Data: data}
5256
nonRenewableRotatedDur, _ = leaseCheckWait(&nonRenewableRotated)
57+
nonRenewableRotatedDurSeconds := nonRenewableRotatedDur.Seconds()
5358
// We expect a 1 second cushion
54-
if nonRenewableRotatedDur != 6*time.Second {
55-
t.Fatalf("renewable duration is not 6: %f", nonRenewableRotatedDur.Seconds())
59+
if nonRenewableRotatedDurSeconds != 6 {
60+
t.Fatalf("renewable duration is not 6: %f", nonRenewableRotatedDurSeconds)
5661
}
5762
// Test TTL=0 case - should return error
5863
data = map[string]interface{}{
@@ -78,8 +83,10 @@ func TestVaultRenewDuration(t *testing.T) {
7883

7984
nonRenewableCert := Secret{LeaseDuration: 100, Data: data}
8085
nonRenewableCertDur, _ := leaseCheckWait(&nonRenewableCert)
81-
if nonRenewableCertDur < 80*time.Second || nonRenewableCertDur > 95*time.Second {
82-
t.Fatalf("non renewable certificate duration is not within 80%% to 95%%: %f", nonRenewableCertDur.Seconds())
86+
nonRenewableCertDurSec := nonRenewableCertDur.Seconds()
87+
88+
if nonRenewableCertDurSec < 80 || nonRenewableCertDurSec > 95 {
89+
t.Fatalf("non renewable certificate duration is not within 80%% to 95%%: %f", nonRenewableCertDurSec)
8390
}
8491

8592
t.Run("secret ID handling", func(t *testing.T) {
@@ -92,10 +99,10 @@ func TestVaultRenewDuration(t *testing.T) {
9299

93100
nonRenewableSecretID := Secret{LeaseDuration: 100, Data: data}
94101
nonRenewableSecretIDDur, _ := leaseCheckWait(&nonRenewableSecretID)
95-
secs := nonRenewableSecretIDDur.Seconds()
102+
nonRenewableSecretIDDurSec := nonRenewableSecretIDDur.Seconds()
96103

97-
if secs < 0.80*(60+1) || secs > 0.95*(60+1) {
98-
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", secs)
104+
if nonRenewableSecretIDDurSec < 0.80*(60+1) || nonRenewableSecretIDDurSec > 0.95*(60+1) {
105+
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", nonRenewableSecretIDDurSec)
99106
}
100107
})
101108

@@ -109,10 +116,10 @@ func TestVaultRenewDuration(t *testing.T) {
109116

110117
nonRenewableSecretID := Secret{LeaseDuration: leaseDuration, Data: data}
111118
nonRenewableSecretIDDur, _ := leaseCheckWait(&nonRenewableSecretID)
112-
secs := nonRenewableSecretIDDur.Seconds()
119+
nonRenewableSecretIDDurSec := nonRenewableSecretIDDur.Seconds()
113120

114-
if secs < 0.80*(leaseDuration+1) || secs > 0.95*(leaseDuration+1) {
115-
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", secs)
121+
if nonRenewableSecretIDDurSec < 0.80*(leaseDuration+1) || nonRenewableSecretIDDurSec > 0.95*(leaseDuration+1) {
122+
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", nonRenewableSecretIDDurSec)
116123
}
117124
})
118125

@@ -125,10 +132,10 @@ func TestVaultRenewDuration(t *testing.T) {
125132

126133
nonRenewableSecretID := Secret{LeaseDuration: leaseDuration, Data: data}
127134
nonRenewableSecretIDDur, _ := leaseCheckWait(&nonRenewableSecretID)
128-
secs := nonRenewableSecretIDDur.Seconds()
135+
nonRenewableSecretIDDurSec := nonRenewableSecretIDDur.Seconds()
129136

130-
if secs < 0.80*(leaseDuration+1) || secs > 0.95*(leaseDuration+1) {
131-
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", secs)
137+
if nonRenewableSecretIDDurSec < 0.80*(leaseDuration+1) || nonRenewableSecretIDDurSec > 0.95*(leaseDuration+1) {
138+
t.Fatalf("renewable duration is not within 80%% to 95%% of lease duration: %f", nonRenewableSecretIDDurSec)
132139
}
133140
})
134141
})

0 commit comments

Comments
 (0)