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