mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gfile_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/v2/os/gfile"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
func Test_MTime(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
|
|
var (
|
|
file1 = "/testfile_t1.txt"
|
|
err error
|
|
fileobj os.FileInfo
|
|
)
|
|
|
|
createTestFile(file1, "")
|
|
defer delTestFiles(file1)
|
|
fileobj, err = os.Stat(testpath() + file1)
|
|
t.AssertNil(err)
|
|
|
|
t.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime())
|
|
t.Assert(gfile.MTime(""), "")
|
|
})
|
|
}
|
|
|
|
func Test_MTimeMillisecond(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
var (
|
|
file1 = "/testfile_t1.txt"
|
|
err error
|
|
fileobj os.FileInfo
|
|
)
|
|
|
|
createTestFile(file1, "")
|
|
defer delTestFiles(file1)
|
|
fileobj, err = os.Stat(testpath() + file1)
|
|
t.AssertNil(err)
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
t.AssertGE(
|
|
gfile.MTimestampMilli(testpath()+file1),
|
|
fileobj.ModTime().UnixNano()/1000000,
|
|
)
|
|
t.Assert(gfile.MTimestampMilli(""), -1)
|
|
})
|
|
}
|