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
23
24
25
26 func TestGZIPFilesHaveZeroMTimes(t *testing.T) {
27
28
29
30 if testenv.Builder() == "" {
31 t.Skip("skipping test on non-builder")
32 }
33 if !testenv.HasSrc() {
34 t.Skip("skipping; no GOROOT available")
35 }
36
37 goroot, err := filepath.EvalSymlinks(runtime.GOROOT())
38 if err != nil {
39 t.Fatal("error evaluating GOROOT: ", err)
40 }
41 var files []string
42 err = filepath.WalkDir(goroot, func(path string, info fs.DirEntry, err error) error {
43 if err != nil {
44 return err
45 }
46 if !info.IsDir() && strings.HasSuffix(path, ".gz") {
47 files = append(files, path)
48 }
49 return nil
50 })
51 if err != nil {
52 if os.IsNotExist(err) {
53 t.Skipf("skipping: GOROOT directory not found: %s", runtime.GOROOT())
54 }
55 t.Fatal("error collecting list of .gz files in GOROOT: ", err)
56 }
57 if len(files) == 0 {
58 t.Fatal("expected to find some .gz files under GOROOT")
59 }
60 for _, path := range files {
61 checkZeroMTime(t, path)
62 }
63 }
64
65 func checkZeroMTime(t *testing.T, path string) {
66 f, err := os.Open(path)
67 if err != nil {
68 t.Error(err)
69 return
70 }
71 defer f.Close()
72 gz, err := NewReader(f)
73 if err != nil {
74 t.Errorf("cannot read gzip file %s: %s", path, err)
75 return
76 }
77 defer gz.Close()
78 if !gz.ModTime.IsZero() {
79 t.Errorf("gzip file %s has non-zero mtime (%s)", path, gz.ModTime)
80 }
81 }
82
View as plain text