Source file
src/compress/gzip/issue14937_test.go
1
2
3
4
5 package gzip
6
7 import (
8 "internal/testenv"
9 "io/fs"
10 "os"
11 "path/filepath"
12 "runtime"
13 "strings"
14 "testing"
15 )
16
17
18
19
20
21
22 func TestGZIPFilesHaveZeroMTimes(t *testing.T) {
23
24
25
26 if testenv.Builder() == "" {
27 t.Skip("skipping test on non-builder")
28 }
29 if !testenv.HasSrc() {
30 t.Skip("skipping; no GOROOT available")
31 }
32
33 goroot, err := filepath.EvalSymlinks(runtime.GOROOT())
34 if err != nil {
35 t.Fatal("error evaluating GOROOT: ", err)
36 }
37 var files []string
38 err = filepath.WalkDir(goroot, func(path string, info fs.DirEntry, err error) error {
39 if err != nil {
40 return err
41 }
42 if !info.IsDir() && strings.HasSuffix(path, ".gz") {
43 files = append(files, path)
44 }
45 return nil
46 })
47 if err != nil {
48 if os.IsNotExist(err) {
49 t.Skipf("skipping: GOROOT directory not found: %s", runtime.GOROOT())
50 }
51 t.Fatal("error collecting list of .gz files in GOROOT: ", err)
52 }
53 if len(files) == 0 {
54 t.Fatal("expected to find some .gz files under GOROOT")
55 }
56 for _, path := range files {
57 checkZeroMTime(t, path)
58 }
59 }
60
61 func checkZeroMTime(t *testing.T, path string) {
62 f, err := os.Open(path)
63 if err != nil {
64 t.Error(err)
65 return
66 }
67 defer f.Close()
68 gz, err := NewReader(f)
69 if err != nil {
70 t.Errorf("cannot read gzip file %s: %s", path, err)
71 return
72 }
73 defer gz.Close()
74 if !gz.ModTime.IsZero() {
75 t.Errorf("gzip file %s has non-zero mtime (%s)", path, gz.ModTime)
76 }
77 }
78
View as plain text