-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_options_test.go
110 lines (102 loc) · 4.44 KB
/
entry_options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2017 Cameron Bergoon
// Licensed under the LGPLv3, see LICENCE file for details.
package stitchdb
import (
"strings"
"testing"
"time"
)
func TestExpireTime(t *testing.T) {
now := time.Now()
entryOptions, err := NewEntryOptions(ExpireTime(now))
if err != nil {
t.Errorf("Failure: NewEntryOptions(ExpireTime(now)) returned error \"%v\"", err)
}
if entryOptions == nil {
t.Errorf("Failure: NewEntryOptions(ExpireTime(now)) returned nil entry options")
}
if entryOptions.expTime != now {
t.Errorf("Failure: NewEntryOptions(ExpireTime(now)) expected entryOptions.expTime == %v got entryOptions.expTime == %v", now, entryOptions.expTime)
}
}
func TestInvalidTime(t *testing.T) {
now := time.Now()
entryOptions, err := NewEntryOptions(InvalidTime(now))
if err != nil {
t.Errorf("Failure: NewEntryOptions(InvalidTime(now)) returned error \"%v\"", err)
}
if entryOptions == nil {
t.Errorf("Failure: NewEntryOptions(InvalidTime(now)) returned nil entry options")
}
if entryOptions.invTime != now {
t.Errorf("Failure: NewEntryOptions(InvalidTime(now)) expected entryOptions.invTime == %v got entryOptions.invTime == %v", now, entryOptions.invTime)
}
}
func TestTol(t *testing.T) {
entryOptions, err := NewEntryOptions(Tol(9.99))
if err != nil {
t.Errorf("Failure: NewEntryOptions(Tol(9.99)) returned error \"%v\"", err)
}
if entryOptions == nil {
t.Errorf("Failure: NewEntryOptions(Tol(9.99)) returned nil entry options")
}
if entryOptions.tol != 9.99 {
t.Errorf("Failure: NewEntryOptions(Tol(9.99)) expected entryOptions.tol == %v got entryOptions.tol == %v", 9.99, entryOptions.tol)
}
}
func TestNewEntryOptions(t *testing.T) {
now := time.Now()
entryOptions, err := NewEntryOptions(ExpireTime(now), InvalidTime(now), Tol(9.99))
if err != nil {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) returned error \"%v\"", err)
}
if entryOptions == nil {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) returned nil entry options")
}
if entryOptions.expTime != now {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) expected entryOptions.expTime == %v got entryOptions.expTime == %v", now, entryOptions.expTime)
}
if entryOptions.invTime != now {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) expected entryOptions.invTime == %v got entryOptions.invTime == %v", now, entryOptions.invTime)
}
if entryOptions.tol != 9.99 {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) expected entryOptions.tol == %v got entryOptions.tol == %v", 9.99, entryOptions.tol)
}
}
func TestEntryOptions_entryOptionsCreateStmt(t *testing.T) {
now := time.Now()
entryOptions, err := NewEntryOptions(ExpireTime(now), InvalidTime(now), Tol(9.99))
if err != nil {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) returned error \"%v\"", err)
}
opts := entryOptions.entryOptionsCreateStmt()
if len(opts) != 30 {
t.Errorf("Failure: entryOptionsCreateStmt() statement expected length 30 got length %v", len(opts))
}
}
func TestNewEntryOptionsFromStmt(t *testing.T) {
now := time.Now()
entryOptions, err := NewEntryOptions(ExpireTime(now), InvalidTime(now), Tol(9.99))
if err != nil {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) returned error \"%v\"", err)
}
opts := entryOptions.entryOptionsCreateStmt()
if len(opts) != 30 {
t.Errorf("Failure: entryOptionsCreateStmt() statement expected length 30 got length %v", len(opts))
}
parts := strings.Split(string(opts), "~")
newEntryOptions, err := NewEntryOptionsFromStmt(parts)
if err != nil {
t.Errorf("Failure: NewEntryOptionsFromStmt(parts) returned error \"%v\"", err)
}
//Todo (cbergoon): Improve resolution of the time.
//if !newEntryOptions.expTime.Equal(now) {
// t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) expected newEntryOptions.expTime == %v got newEntryOptions.expTime == %v", now, newEntryOptions.expTime)
//}
//if !newEntryOptions.invTime.Equal(now) {
// t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) expected newEntryOptions.invTime == %v got newEntryOptions.invTime == %v", now, newEntryOptions.invTime)
//}
if newEntryOptions.tol != 9.99 {
t.Errorf("Failure: NewEntryOptions(ExpireTime(), InvalidTime(now), Tol(9.99)) expected newEntryOptions.tol == %v got newEntryOptions.tol == %v", 9.99, newEntryOptions.tol)
}
}