1// Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2// 3// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved. 4// 5// This Source Code Form is subject to the terms of the Mozilla Public 6// License, v. 2.0. If a copy of the MPL was not distributed with this file, 7// You can obtain one at http://mozilla.org/MPL/2.0/. 8 9package mysql 10 11import ( 12 "database/sql" 13 "database/sql/driver" 14 "testing" 15 "time" 16) 17 18var ( 19 // Check implementation of interfaces 20 _ driver.Valuer = NullTime{} 21 _ sql.Scanner = (*NullTime)(nil) 22) 23 24func TestScanNullTime(t *testing.T) { 25 var scanTests = []struct { 26 in interface{} 27 error bool 28 valid bool 29 time time.Time 30 }{ 31 {tDate, false, true, tDate}, 32 {sDate, false, true, tDate}, 33 {[]byte(sDate), false, true, tDate}, 34 {tDateTime, false, true, tDateTime}, 35 {sDateTime, false, true, tDateTime}, 36 {[]byte(sDateTime), false, true, tDateTime}, 37 {tDate0, false, true, tDate0}, 38 {sDate0, false, true, tDate0}, 39 {[]byte(sDate0), false, true, tDate0}, 40 {sDateTime0, false, true, tDate0}, 41 {[]byte(sDateTime0), false, true, tDate0}, 42 {"", true, false, tDate0}, 43 {"1234", true, false, tDate0}, 44 {0, true, false, tDate0}, 45 } 46 47 var nt = NullTime{} 48 var err error 49 50 for _, tst := range scanTests { 51 err = nt.Scan(tst.in) 52 if (err != nil) != tst.error { 53 t.Errorf("%v: expected error status %t, got %t", tst.in, tst.error, (err != nil)) 54 } 55 if nt.Valid != tst.valid { 56 t.Errorf("%v: expected valid status %t, got %t", tst.in, tst.valid, nt.Valid) 57 } 58 if nt.Time != tst.time { 59 t.Errorf("%v: expected time %v, got %v", tst.in, tst.time, nt.Time) 60 } 61 } 62} 63