-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnulltime_test.go
More file actions
56 lines (51 loc) · 1.05 KB
/
nulltime_test.go
File metadata and controls
56 lines (51 loc) · 1.05 KB
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
// Package NullTime provides a time.Time that may be null.
// Copyright (c) 2011-2013, 'pq' Contributors
// Portions Copyright (C) 2011 Blake Mizerany
package NullTime
import (
"testing"
"time"
)
func TestScanTimestamp(t *testing.T) {
var nt NullTime
tn := time.Now()
nt.Scan(tn)
if !nt.Valid {
t.Errorf("Expected Valid=false")
}
if nt.Time != tn {
t.Errorf("Time value mismatch")
}
}
func TestValue(t *testing.T) {
var (
nt NullTime
returnedTime time.Time
isValid bool
)
returnedTime, isValid, _ = nt.Value()
if isValid {
t.Errorf("Expected isValid false but found true")
}
var emptyTime time.Time
emptyTime = time.Time{}
if returnedTime != emptyTime {
t.Errorf("Time value mismatch")
}
tn := time.Now()
nt.Scan(tn)
returnedTime, isValid, _ = nt.Value()
if !isValid {
t.Errorf("Expected isValid true but found false")
}
if returnedTime != tn {
t.Errorf("Time value mismatch")
}
}
func TestScanNilTimestamp(t *testing.T) {
var nt NullTime
nt.Scan(nil)
if nt.Valid {
t.Errorf("Expected Valid=false")
}
}