-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Italo Vietro <[email protected]>
- Loading branch information
Italo Vietro
committed
Feb 4, 2019
1 parent
b8942cd
commit 8e7840d
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package outboxer | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestOutboxMessage(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
scenario string | ||
function func(*testing.T) | ||
}{ | ||
{ | ||
"check if NullTime Scan works for message", | ||
testNullTimeScan, | ||
}, | ||
{ | ||
"check if NullTime Value works for message", | ||
testNullTimeValue, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.scenario, func(t *testing.T) { | ||
test.function(t) | ||
}) | ||
} | ||
} | ||
|
||
func testNullTimeScan(t *testing.T) { | ||
nt := NullTime{} | ||
if err := nt.Scan("03/05/2019"); err != nil { | ||
t.Fatalf("failed to scan NullTime value: %s", err) | ||
} | ||
|
||
if err := nt.Scan(nil); err != nil { | ||
t.Fatalf("failed to scan NullTime with nil value: %s", err) | ||
} | ||
|
||
if err := nt.Scan("wrongValue"); err != nil { | ||
t.Fatalf("an error was not expected when scannig a NullTime value: %s", err) | ||
} | ||
} | ||
|
||
func testNullTimeValue(t *testing.T) { | ||
nt := NullTime{Valid: true} | ||
if err := nt.Scan("2019-02-01 16:42:35.571831"); err != nil { | ||
t.Fatalf("failed to scan NullTime value: %s", err) | ||
} | ||
|
||
v, err := nt.Value() | ||
if err != nil { | ||
t.Fatalf("failed to get driver.Value from NullTime: %s", err) | ||
} | ||
|
||
if v != nil { | ||
t.Fatalf("driver.Value was expected from NullTime: %s", err) | ||
} | ||
|
||
nt.Valid = false | ||
v, _ = nt.Value() | ||
if v != nil { | ||
t.Fatalf("driver.Value is not supposed to be nil: %s", err) | ||
} | ||
} |