open-vault/sdk/logical/lease_test.go

60 lines
1.1 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2015-04-11 04:29:03 +00:00
package logical
import (
"testing"
"time"
)
func TestLeaseOptionsLeaseTotal(t *testing.T) {
var l LeaseOptions
l.TTL = 1 * time.Hour
2015-04-11 04:29:03 +00:00
actual := l.LeaseTotal()
expected := l.TTL
2015-04-11 04:29:03 +00:00
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
func TestLeaseOptionsLeaseTotal_grace(t *testing.T) {
var l LeaseOptions
l.TTL = 1 * time.Hour
2015-04-11 04:29:03 +00:00
actual := l.LeaseTotal()
2016-02-01 00:33:16 +00:00
if actual != l.TTL {
2015-04-11 04:29:03 +00:00
t.Fatalf("bad: %s", actual)
}
}
func TestLeaseOptionsLeaseTotal_negLease(t *testing.T) {
var l LeaseOptions
l.TTL = -1 * 1 * time.Hour
2015-04-11 04:29:03 +00:00
actual := l.LeaseTotal()
expected := time.Duration(0)
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
func TestLeaseOptionsExpirationTime(t *testing.T) {
var l LeaseOptions
l.TTL = 1 * time.Hour
2015-04-11 04:29:03 +00:00
limit := time.Now().Add(time.Hour)
exp := l.ExpirationTime()
if exp.Before(limit) {
t.Fatalf("bad: %s", exp)
2015-04-11 04:29:03 +00:00
}
}
func TestLeaseOptionsExpirationTime_noLease(t *testing.T) {
var l LeaseOptions
if !l.ExpirationTime().IsZero() {
t.Fatal("should be zero")
}
}