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