summaryrefslogtreecommitdiff
path: root/nulltime_test.go
diff options
context:
space:
mode:
authorroot <sina@snix.ir>2022-05-27 13:13:53 +0000
committerroot <sina@snix.ir>2022-05-27 13:13:53 +0000
commit937c561db4b25a1becdc81701511fafc67b90389 (patch)
tree17e5d4c692ec4ab3c8b0deb0072d5784cc4be084 /nulltime_test.go
fork mysql driverHEADmaster
Diffstat (limited to 'nulltime_test.go')
-rw-r--r--nulltime_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/nulltime_test.go b/nulltime_test.go
new file mode 100644
index 0000000..f0f8fd7
--- /dev/null
+++ b/nulltime_test.go
@@ -0,0 +1,62 @@
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
+//
+// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// You can obtain one at http://mozilla.org/MPL/2.0/.
+
+package mariadb
+
+import (
+ "database/sql"
+ "database/sql/driver"
+ "testing"
+ "time"
+)
+
+var (
+ // Check implementation of interfaces
+ _ driver.Valuer = NullTime{}
+ _ sql.Scanner = (*NullTime)(nil)
+)
+
+func TestScanNullTime(t *testing.T) {
+ var scanTests = []struct {
+ in interface{}
+ error bool
+ valid bool
+ time time.Time
+ }{
+ {tDate, false, true, tDate},
+ {sDate, false, true, tDate},
+ {[]byte(sDate), false, true, tDate},
+ {tDateTime, false, true, tDateTime},
+ {sDateTime, false, true, tDateTime},
+ {[]byte(sDateTime), false, true, tDateTime},
+ {tDate0, false, true, tDate0},
+ {sDate0, false, true, tDate0},
+ {[]byte(sDate0), false, true, tDate0},
+ {sDateTime0, false, true, tDate0},
+ {[]byte(sDateTime0), false, true, tDate0},
+ {"", true, false, tDate0},
+ {"1234", true, false, tDate0},
+ {0, true, false, tDate0},
+ }
+
+ var nt = NullTime{}
+ var err error
+
+ for _, tst := range scanTests {
+ err = nt.Scan(tst.in)
+ if (err != nil) != tst.error {
+ t.Errorf("%v: expected error status %t, got %t", tst.in, tst.error, (err != nil))
+ }
+ if nt.Valid != tst.valid {
+ t.Errorf("%v: expected valid status %t, got %t", tst.in, tst.valid, nt.Valid)
+ }
+ if nt.Time != tst.time {
+ t.Errorf("%v: expected time %v, got %v", tst.in, tst.time, nt.Time)
+ }
+ }
+}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR