github.com/panjjo/go@v0.0.0-20161104043856-d62b31386338/src/compress/gzip/issue14937_test.go (about) 1 package gzip 2 3 import ( 4 "internal/testenv" 5 "os" 6 "path/filepath" 7 "runtime" 8 "strings" 9 "testing" 10 ) 11 12 // Per golang.org/issue/14937, check that every .gz file 13 // in the tree has a zero mtime. 14 func TestGZIPFilesHaveZeroMTimes(t *testing.T) { 15 if testing.Short() && testenv.Builder() == "" { 16 t.Skip("skipping in short mode") 17 } 18 goroot, err := filepath.EvalSymlinks(runtime.GOROOT()) 19 if err != nil { 20 t.Fatal("error evaluating GOROOT: ", err) 21 } 22 var files []string 23 err = filepath.Walk(goroot, func(path string, info os.FileInfo, err error) error { 24 if err != nil { 25 return err 26 } 27 if !info.IsDir() && strings.HasSuffix(path, ".gz") { 28 files = append(files, path) 29 } 30 return nil 31 }) 32 if err != nil { 33 if os.IsNotExist(err) { 34 t.Skipf("skipping: GOROOT directory not found: %s", runtime.GOROOT()) 35 } 36 t.Fatal("error collecting list of .gz files in GOROOT: ", err) 37 } 38 if len(files) == 0 { 39 t.Fatal("expected to find some .gz files under GOROOT") 40 } 41 for _, path := range files { 42 checkZeroMTime(t, path) 43 } 44 } 45 46 func checkZeroMTime(t *testing.T, path string) { 47 f, err := os.Open(path) 48 if err != nil { 49 t.Error(err) 50 return 51 } 52 defer f.Close() 53 gz, err := NewReader(f) 54 if err != nil { 55 t.Errorf("cannot read gzip file %s: %s", path, err) 56 return 57 } 58 defer gz.Close() 59 if !gz.ModTime.IsZero() { 60 t.Errorf("gzip file %s has non-zero mtime (%s)", path, gz.ModTime) 61 } 62 }