1package logical
2
3import (
4	"testing"
5	"time"
6)
7
8func TestLeaseOptionsLeaseTotal(t *testing.T) {
9	var l LeaseOptions
10	l.TTL = 1 * time.Hour
11
12	actual := l.LeaseTotal()
13	expected := l.TTL
14	if actual != expected {
15		t.Fatalf("bad: %s", actual)
16	}
17}
18
19func TestLeaseOptionsLeaseTotal_grace(t *testing.T) {
20	var l LeaseOptions
21	l.TTL = 1 * time.Hour
22
23	actual := l.LeaseTotal()
24	if actual != l.TTL {
25		t.Fatalf("bad: %s", actual)
26	}
27}
28
29func TestLeaseOptionsLeaseTotal_negLease(t *testing.T) {
30	var l LeaseOptions
31	l.TTL = -1 * 1 * time.Hour
32
33	actual := l.LeaseTotal()
34	expected := time.Duration(0)
35	if actual != expected {
36		t.Fatalf("bad: %s", actual)
37	}
38}
39
40func TestLeaseOptionsExpirationTime(t *testing.T) {
41	var l LeaseOptions
42	l.TTL = 1 * time.Hour
43
44	limit := time.Now().Add(time.Hour)
45	exp := l.ExpirationTime()
46	if exp.Before(limit) {
47		t.Fatalf("bad: %s", exp)
48	}
49}
50
51func TestLeaseOptionsExpirationTime_noLease(t *testing.T) {
52	var l LeaseOptions
53	if !l.ExpirationTime().IsZero() {
54		t.Fatal("should be zero")
55	}
56}
57