github.com/zhongdalu/gf@v1.0.0/g/os/gfile/gfile_z_time_test.go (about)

     1  package gfile_test
     2  
     3  import (
     4  	"github.com/zhongdalu/gf/g/os/gfile"
     5  	"github.com/zhongdalu/gf/g/test/gtest"
     6  	"os"
     7  	"testing"
     8  )
     9  
    10  func TestMTime(t *testing.T) {
    11  	gtest.Case(t, func() {
    12  
    13  		var (
    14  			file1   string = "/testfile_t1.txt"
    15  			err     error
    16  			fileobj os.FileInfo
    17  		)
    18  
    19  		createTestFile(file1, "")
    20  		defer delTestFiles(file1)
    21  		fileobj, err = os.Stat(testpath() + file1)
    22  		gtest.Assert(err, nil)
    23  
    24  		gtest.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime().Unix())
    25  		gtest.Assert(gfile.MTime(""), 0)
    26  	})
    27  }
    28  
    29  func TestMTimeMillisecond(t *testing.T) {
    30  	gtest.Case(t, func() {
    31  		var (
    32  			file1   string = "/testfile_t1.txt"
    33  			err     error
    34  			fileobj os.FileInfo
    35  		)
    36  
    37  		createTestFile(file1, "")
    38  		defer delTestFiles(file1)
    39  		fileobj, err = os.Stat(testpath() + file1)
    40  		gtest.Assert(err, nil)
    41  
    42  		gtest.AssertGTE(gfile.MTimeMillisecond(testpath()+file1), fileobj.ModTime().Nanosecond()/1000000)
    43  		gtest.Assert(gfile.MTimeMillisecond(""), 0)
    44  	})
    45  }