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
|
|
|
|
l.GracePeriod = 30 * time.Minute
|
2015-04-11 04:29:03 +00:00
|
|
|
|
|
|
|
actual := l.LeaseTotal()
|
2015-08-21 00:47:17 +00:00
|
|
|
expected := l.TTL + l.GracePeriod
|
2015-04-11 04:29:03 +00:00
|
|
|
if actual != expected {
|
|
|
|
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
|
|
|
|
l.GracePeriod = 30 * time.Minute
|
2015-04-11 04:29:03 +00:00
|
|
|
|
|
|
|
actual := l.LeaseTotal()
|
|
|
|
expected := time.Duration(0)
|
|
|
|
if actual != expected {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLeaseOptionsLeaseTotal_negGrace(t *testing.T) {
|
|
|
|
var l LeaseOptions
|
2015-08-21 00:47:17 +00:00
|
|
|
l.TTL = 1 * time.Hour
|
|
|
|
l.GracePeriod = -1 * 30 * time.Minute
|
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 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
|
|
|
|
2015-06-17 20:59:09 +00:00
|
|
|
limit := time.Now().UTC().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_grace(t *testing.T) {
|
|
|
|
var l LeaseOptions
|
2015-08-21 00:47:17 +00:00
|
|
|
l.TTL = 1 * time.Hour
|
|
|
|
l.GracePeriod = 30 * time.Minute
|
2015-04-11 04:29:03 +00:00
|
|
|
|
2015-06-17 20:59:09 +00:00
|
|
|
limit := time.Now().UTC().Add(time.Hour + 30*time.Minute)
|
2015-04-11 04:29:03 +00:00
|
|
|
actual := l.ExpirationTime()
|
2015-06-17 20:59:09 +00:00
|
|
|
if actual.Before(limit) {
|
2015-04-11 04:29:03 +00:00
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLeaseOptionsExpirationTime_graceNegative(t *testing.T) {
|
|
|
|
var l LeaseOptions
|
2015-08-21 00:47:17 +00:00
|
|
|
l.TTL = 1 * time.Hour
|
|
|
|
l.GracePeriod = -1 * 30 * time.Minute
|
2015-04-11 04:29:03 +00:00
|
|
|
|
2015-06-17 20:59:09 +00:00
|
|
|
limit := time.Now().UTC().Add(time.Hour)
|
2015-04-11 04:29:03 +00:00
|
|
|
actual := l.ExpirationTime()
|
2015-06-17 20:59:09 +00:00
|
|
|
if actual.Before(limit) {
|
2015-04-11 04:29:03 +00:00
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLeaseOptionsExpirationTime_noLease(t *testing.T) {
|
|
|
|
var l LeaseOptions
|
|
|
|
if !l.ExpirationTime().IsZero() {
|
|
|
|
t.Fatal("should be zero")
|
|
|
|
}
|
|
|
|
}
|