func createTar(t *testing.T) io.Reader {
	t.Helper()
	b := &bytes.Buffer{}
	ta := tar.NewWriter(b)
	entries := []struct {
		hdr  *tar.Header
		body []byte
	}{{
		hdr: &tar.Header{
			Name: "dir1/",
			Mode: 0755,
		},
	}, {
		hdr: &tar.Header{
			Typeflag: tar.TypeSymlink,
			Name:     "dir1/symlink1",
			Linkname: "../symtarget",
		},
	}, {
		hdr: &tar.Header{
			Name: "dir1/testfile1.txt",
			Mode: 0644,
			Size: int64(len("content1")),
		},
		body: []byte("content1"),
	}}
	for _, e := range entries {
		if err := ta.WriteHeader(e.hdr); err != nil {
			t.Errorf("failed to write header %s: %v", e.hdr.Name, err)
		}
		if e.hdr.Size != 0 {
			if _, err := ta.Write(e.body); err != nil {
				t.Errorf("failed to write body %s: %v", e.hdr.Name, err)
			}
		}
	}
	return b
}
create a test tar file
package rpmpack
import (
	"archive/tar"
	"bytes"
	"io"
	"io/ioutil"
	"testing"
	"github.com/google/go-cmp/cmp"
)