"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/archive/tar/tar_test.go" between
moby-20.10.7.tar.gz and moby-20.10.8.tar.gz

About: Moby is a framework to assemble specialized container systems (formerly project name Docker; see here to clarify the relationship between the projects).

tar_test.go  (moby-20.10.7):tar_test.go  (moby-20.10.8)
skipping to change at line 13 skipping to change at line 13
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package tar package tar
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"internal/testenv" "internal/testenv"
"io" "io"
"io/ioutil" "io/fs"
"math" "math"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"time" "time"
) )
skipping to change at line 265 skipping to change at line 265
t.Errorf("Size = %v; want %v", g, e) t.Errorf("Size = %v; want %v", g, e)
} }
if g, e := h.ModTime, fi.ModTime(); !g.Equal(e) { if g, e := h.ModTime, fi.ModTime(); !g.Equal(e) {
t.Errorf("ModTime = %v; want %v", g, e) t.Errorf("ModTime = %v; want %v", g, e)
} }
} }
func TestFileInfoHeaderSymlink(t *testing.T) { func TestFileInfoHeaderSymlink(t *testing.T) {
testenv.MustHaveSymlink(t) testenv.MustHaveSymlink(t)
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink") tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
link := filepath.Join(tmpdir, "link") link := filepath.Join(tmpdir, "link")
target := tmpdir target := tmpdir
err = os.Symlink(target, link) err = os.Symlink(target, link)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
skipping to change at line 330 skipping to change at line 330
// Read it back. // Read it back.
tr := NewReader(&b) tr := NewReader(&b)
rHdr, err := tr.Next() rHdr, err := tr.Next()
if err != nil { if err != nil {
t.Fatalf("tr.Next: %v", err) t.Fatalf("tr.Next: %v", err)
} }
if !reflect.DeepEqual(rHdr, hdr) { if !reflect.DeepEqual(rHdr, hdr) {
t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr) t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr)
} }
rData, err := ioutil.ReadAll(tr) rData, err := io.ReadAll(tr)
if err != nil { if err != nil {
t.Fatalf("Read: %v", err) t.Fatalf("Read: %v", err)
} }
if !bytes.Equal(rData, data) { if !bytes.Equal(rData, data) {
t.Errorf("Data mismatch.\n got %q\nwant %q", rData, data) t.Errorf("Data mismatch.\n got %q\nwant %q", rData, data)
} }
} }
type headerRoundTripTest struct { type headerRoundTripTest struct {
h *Header h *Header
fm os.FileMode fm fs.FileMode
} }
func TestHeaderRoundTrip(t *testing.T) { func TestHeaderRoundTrip(t *testing.T) {
vectors := []headerRoundTripTest{{ vectors := []headerRoundTripTest{{
// regular file. // regular file.
h: &Header{ h: &Header{
Name: "test.txt", Name: "test.txt",
Mode: 0644, Mode: 0644,
Size: 12, Size: 12,
ModTime: time.Unix(1360600916, 0), ModTime: time.Unix(1360600916, 0),
skipping to change at line 364 skipping to change at line 364
fm: 0644, fm: 0644,
}, { }, {
// symbolic link. // symbolic link.
h: &Header{ h: &Header{
Name: "link.txt", Name: "link.txt",
Mode: 0777, Mode: 0777,
Size: 0, Size: 0,
ModTime: time.Unix(1360600852, 0), ModTime: time.Unix(1360600852, 0),
Typeflag: TypeSymlink, Typeflag: TypeSymlink,
}, },
fm: 0777 | os.ModeSymlink, fm: 0777 | fs.ModeSymlink,
}, { }, {
// character device node. // character device node.
h: &Header{ h: &Header{
Name: "dev/null", Name: "dev/null",
Mode: 0666, Mode: 0666,
Size: 0, Size: 0,
ModTime: time.Unix(1360578951, 0), ModTime: time.Unix(1360578951, 0),
Typeflag: TypeChar, Typeflag: TypeChar,
}, },
fm: 0666 | os.ModeDevice | os.ModeCharDevice, fm: 0666 | fs.ModeDevice | fs.ModeCharDevice,
}, { }, {
// block device node. // block device node.
h: &Header{ h: &Header{
Name: "dev/sda", Name: "dev/sda",
Mode: 0660, Mode: 0660,
Size: 0, Size: 0,
ModTime: time.Unix(1360578954, 0), ModTime: time.Unix(1360578954, 0),
Typeflag: TypeBlock, Typeflag: TypeBlock,
}, },
fm: 0660 | os.ModeDevice, fm: 0660 | fs.ModeDevice,
}, { }, {
// directory. // directory.
h: &Header{ h: &Header{
Name: "dir/", Name: "dir/",
Mode: 0755, Mode: 0755,
Size: 0, Size: 0,
ModTime: time.Unix(1360601116, 0), ModTime: time.Unix(1360601116, 0),
Typeflag: TypeDir, Typeflag: TypeDir,
}, },
fm: 0755 | os.ModeDir, fm: 0755 | fs.ModeDir,
}, { }, {
// fifo node. // fifo node.
h: &Header{ h: &Header{
Name: "dev/initctl", Name: "dev/initctl",
Mode: 0600, Mode: 0600,
Size: 0, Size: 0,
ModTime: time.Unix(1360578949, 0), ModTime: time.Unix(1360578949, 0),
Typeflag: TypeFifo, Typeflag: TypeFifo,
}, },
fm: 0600 | os.ModeNamedPipe, fm: 0600 | fs.ModeNamedPipe,
}, { }, {
// setuid. // setuid.
h: &Header{ h: &Header{
Name: "bin/su", Name: "bin/su",
Mode: 0755 | c_ISUID, Mode: 0755 | c_ISUID,
Size: 23232, Size: 23232,
ModTime: time.Unix(1355405093, 0), ModTime: time.Unix(1355405093, 0),
Typeflag: TypeReg, Typeflag: TypeReg,
}, },
fm: 0755 | os.ModeSetuid, fm: 0755 | fs.ModeSetuid,
}, { }, {
// setguid. // setguid.
h: &Header{ h: &Header{
Name: "group.txt", Name: "group.txt",
Mode: 0750 | c_ISGID, Mode: 0750 | c_ISGID,
Size: 0, Size: 0,
ModTime: time.Unix(1360602346, 0), ModTime: time.Unix(1360602346, 0),
Typeflag: TypeReg, Typeflag: TypeReg,
}, },
fm: 0750 | os.ModeSetgid, fm: 0750 | fs.ModeSetgid,
}, { }, {
// sticky. // sticky.
h: &Header{ h: &Header{
Name: "sticky.txt", Name: "sticky.txt",
Mode: 0600 | c_ISVTX, Mode: 0600 | c_ISVTX,
Size: 7, Size: 7,
ModTime: time.Unix(1360602540, 0), ModTime: time.Unix(1360602540, 0),
Typeflag: TypeReg, Typeflag: TypeReg,
}, },
fm: 0600 | os.ModeSticky, fm: 0600 | fs.ModeSticky,
}, { }, {
// hard link. // hard link.
h: &Header{ h: &Header{
Name: "hard.txt", Name: "hard.txt",
Mode: 0644, Mode: 0644,
Size: 0, Size: 0,
Linkname: "file.txt", Linkname: "file.txt",
ModTime: time.Unix(1360600916, 0), ModTime: time.Unix(1360600916, 0),
Typeflag: TypeLink, Typeflag: TypeLink,
}, },
skipping to change at line 807 skipping to change at line 807
&Header{Name: "world", Mode: 0640, Size: int64(5), Xattrs : map[string]string{"foo": "bar"}}, &Header{Name: "world", Mode: 0640, Size: int64(5), Xattrs : map[string]string{"foo": "bar"}},
[]byte("hello"), []byte("hello"),
}}, }},
}} }}
b.Run("Writer", func(b *testing.B) { b.Run("Writer", func(b *testing.B) {
for _, v := range vectors { for _, v := range vectors {
b.Run(v.label, func(b *testing.B) { b.Run(v.label, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
// Writing to ioutil.Discard because we w ant to // Writing to io.Discard because we want to
// test purely the writer code and not br ing in disk performance into this. // test purely the writer code and not br ing in disk performance into this.
tw := NewWriter(ioutil.Discard) tw := NewWriter(io.Discard)
for _, file := range v.files { for _, file := range v.files {
if err := tw.WriteHeader(file.hdr ); err != nil { if err := tw.WriteHeader(file.hdr ); err != nil {
b.Errorf("unexpected Writ eHeader error: %v", err) b.Errorf("unexpected Writ eHeader error: %v", err)
} }
if _, err := tw.Write(file.body); err != nil { if _, err := tw.Write(file.body); err != nil {
b.Errorf("unexpected Writ e error: %v", err) b.Errorf("unexpected Writ e error: %v", err)
} }
} }
if err := tw.Close(); err != nil { if err := tw.Close(); err != nil {
b.Errorf("unexpected Close error: %v", err) b.Errorf("unexpected Close error: %v", err)
skipping to change at line 847 skipping to change at line 847
tw.Close() tw.Close()
b.Run(v.label, func(b *testing.B) { b.Run(v.label, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
// Read from the byte buffer. // Read from the byte buffer.
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
r.Reset(buf.Bytes()) r.Reset(buf.Bytes())
tr := NewReader(&r) tr := NewReader(&r)
if _, err := tr.Next(); err != nil { if _, err := tr.Next(); err != nil {
b.Errorf("unexpected Next error: %v", err) b.Errorf("unexpected Next error: %v", err)
} }
if _, err := io.Copy(ioutil.Discard, tr); err != nil { if _, err := io.Copy(io.Discard, tr); err != nil {
b.Errorf("unexpected Copy error : %v", err) b.Errorf("unexpected Copy error : %v", err)
} }
} }
}) })
} }
}) })
} }
 End of changes. 15 change blocks. 
15 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)