1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
package times
import (
"os"
"testing"
"time"
)
func TestStat(t *testing.T) {
fileTest(t, func(f *os.File) {
ts, err := Stat(f.Name())
if err != nil {
t.Error(err.Error())
}
timespecTest(ts, newInterval(time.Now(), time.Second), t)
})
}
func TestGet(t *testing.T) {
fileTest(t, func(f *os.File) {
fi, err := os.Stat(f.Name())
if err != nil {
t.Error(err.Error())
}
timespecTest(Get(fi), newInterval(time.Now(), time.Second), t)
})
}
func TestStatErr(t *testing.T) {
_, err := Stat("badfile?")
if err == nil {
t.Error("expected an error")
}
}
func TestCheat(t *testing.T) {
// not all times are available for all platforms
// this allows us to get 100% test coverage for platforms which do not have
// ChangeTime/BirthTime
var c ctime
if c.HasChangeTime() {
c.ChangeTime()
}
var b btime
if b.HasBirthTime() {
b.BirthTime()
}
var nc noctime
func() {
if !nc.HasChangeTime() {
defer func() { recover() }()
}
nc.ChangeTime()
}()
var nb nobtime
func() {
if !nb.HasBirthTime() {
defer func() { recover() }()
}
nb.BirthTime()
}()
}
|