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