github.com/wangyougui/gf/v2@v2.6.5/os/gfile/gfile_z_unit_time_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package gfile_test 8 9 import ( 10 "os" 11 "testing" 12 "time" 13 14 "github.com/wangyougui/gf/v2/os/gfile" 15 "github.com/wangyougui/gf/v2/test/gtest" 16 ) 17 18 func Test_MTime(t *testing.T) { 19 gtest.C(t, func(t *gtest.T) { 20 21 var ( 22 file1 = "/testfile_t1.txt" 23 err error 24 fileobj os.FileInfo 25 ) 26 27 createTestFile(file1, "") 28 defer delTestFiles(file1) 29 fileobj, err = os.Stat(testpath() + file1) 30 t.AssertNil(err) 31 32 t.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime()) 33 t.Assert(gfile.MTime(""), "") 34 }) 35 } 36 37 func Test_MTimeMillisecond(t *testing.T) { 38 gtest.C(t, func(t *gtest.T) { 39 var ( 40 file1 = "/testfile_t1.txt" 41 err error 42 fileobj os.FileInfo 43 ) 44 45 createTestFile(file1, "") 46 defer delTestFiles(file1) 47 fileobj, err = os.Stat(testpath() + file1) 48 t.AssertNil(err) 49 50 time.Sleep(time.Millisecond * 100) 51 t.AssertGE( 52 gfile.MTimestampMilli(testpath()+file1), 53 fileobj.ModTime().UnixNano()/1000000, 54 ) 55 t.Assert(gfile.MTimestampMilli(""), -1) 56 }) 57 }