2023-03-15 16:00:52 +00:00
|
|
|
// 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
|
2015-08-21 00:47:17 +00:00
|
|
|
l.TTL = 1 * time.Hour
|
2015-04-11 04:29:03 +00:00
|
|
|
|
|
|
|
actual := l.LeaseTotal()
|
2015-08-21 00:47:17 +00:00
|
|
|
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
|
2015-08-21 00:47:17 +00:00
|
|
|
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
|
2015-08-21 00:47:17 +00:00
|
|
|
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
|
2015-08-21 00:47:17 +00:00
|
|
|
l.TTL = 1 * time.Hour
|
2015-04-11 04:29:03 +00:00
|
|
|
|
2016-07-07 21:44:14 +00:00
|
|
|
limit := time.Now().Add(time.Hour)
|
2015-06-17 20:59:09 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|