Commit cf3a2812 authored by Alex Brainman's avatar Alex Brainman

archive/tar: extend TestFileInfoHeaderSymlink

For #17541.

Change-Id: I524ab194f32b8b061ce1c9c3e0cd34cc5539358e
Reviewed-on: https://go-review.googlesource.com/39410
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 4ee934ad
...@@ -6,10 +6,13 @@ package tar ...@@ -6,10 +6,13 @@ package tar
import ( import (
"bytes" "bytes"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"path/filepath"
"reflect" "reflect"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
...@@ -67,27 +70,43 @@ func TestFileInfoHeaderDir(t *testing.T) { ...@@ -67,27 +70,43 @@ func TestFileInfoHeaderDir(t *testing.T) {
} }
func TestFileInfoHeaderSymlink(t *testing.T) { func TestFileInfoHeaderSymlink(t *testing.T) {
h, err := FileInfoHeader(symlink{}, "some-target") testenv.MustHaveSymlink(t)
if runtime.GOOS == "windows" {
t.Skip("skipping broken test: see issue 17541")
}
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
link := filepath.Join(tmpdir, "link")
target := tmpdir
err = os.Symlink(target, link)
if err != nil {
t.Fatal(err)
}
fi, err := os.Lstat(link)
if err != nil {
t.Fatal(err)
}
h, err := FileInfoHeader(fi, target)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if g, e := h.Name, "some-symlink"; g != e { if g, e := h.Name, fi.Name(); g != e {
t.Errorf("Name = %q; want %q", g, e) t.Errorf("Name = %q; want %q", g, e)
} }
if g, e := h.Linkname, "some-target"; g != e { if g, e := h.Linkname, target; g != e {
t.Errorf("Linkname = %q; want %q", g, e) t.Errorf("Linkname = %q; want %q", g, e)
} }
if g, e := h.Typeflag, byte(TypeSymlink); g != e {
t.Errorf("Typeflag = %v; want %v", g, e)
}
} }
type symlink struct{}
func (symlink) Name() string { return "some-symlink" }
func (symlink) Size() int64 { return 0 }
func (symlink) Mode() os.FileMode { return os.ModeSymlink }
func (symlink) ModTime() time.Time { return time.Time{} }
func (symlink) IsDir() bool { return false }
func (symlink) Sys() interface{} { return nil }
func TestRoundTrip(t *testing.T) { func TestRoundTrip(t *testing.T) {
data := []byte("some file contents") data := []byte("some file contents")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment