Skip to content

Commit

Permalink
fix tests for vault-client
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten Kraus authored and Karsten Kraus committed Sep 15, 2023
1 parent a865f50 commit eaaee69
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/app/vault_raft_snapshot_agent/vault/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ func TestClientDoesNotTakeSnapshotIfAuthRefreshFails(t *testing.T) {
leader: true,
}

initalAuthExpiration := time.Now().Add(time.Second * -1)
client := NewVaultClient[any, *clientVaultAPIAuthStub](
clientApi,
authStub,
time.Now().Add(time.Second*-1),
initalAuthExpiration,
)

err := client.TakeSnapshot(context.Background(), bufio.NewWriter(&bytes.Buffer{}))

assert.Error(t, err, "TakeSnapshot() returned no error although auth-refresh failed")
assert.NotEqual(t, authStub.leaseDuration, client.authExpiration, "TakeSnapshot() refreshed token-expiration although auth-refresh failed")
assert.Equal(t, initalAuthExpiration, client.authExpiration, "TakeSnapshot() refreshed auth-expiration although auth-refresh failed")
assert.False(t, clientApi.snapshotTaken, "TakeSnapshot() took snapshot although aut-refresh failed")
}

Expand All @@ -62,7 +63,7 @@ func TestClientOnlyTakesSnaphotWhenLeader(t *testing.T) {
client := NewVaultClient[any, *clientVaultAPIAuthStub](
clientApi,
&clientVaultAPIAuthStub{},
time.Now(),
time.Now().Add(time.Minute),
)

ctx := context.Background()
Expand Down Expand Up @@ -114,9 +115,8 @@ func assertAuthRefresh(t *testing.T, refreshed bool, client *VaultClient[any, *c
}
}

expectedTokenExpiration := time.Now().Add(auth.leaseDuration / 2)
if refreshed && client.authExpiration.Before(expectedTokenExpiration) {
t.Fatalf("client did not accept tokenExpiration from auth! expected: %v, client: %v, lease-duration: %v", expectedTokenExpiration, client.authExpiration, auth.leaseDuration)
if refreshed {
assert.WithinDuration(t, time.Now().Add(auth.leaseDuration/2), client.authExpiration, time.Second, "client did not refresh auth-expiration!")
}
}

Expand Down

0 comments on commit eaaee69

Please sign in to comment.