Ejemplo n.º 1
0
func writer(t *testing.T, tname string, w io.Writer, atype string) archive.WriteCloser {
	switch atype {
	case gzipType:
		return gzip.NewWriter(w)
	case tarType:
		return tar.NewWriter(w)
	case zipType:
		return zip.NewWriter(w)
	}
	t.Fatalf("%s: unrecognized archive type: %s", tname, atype)
	panic("execution continued after (*testing.T).Fatalf")
}
Ejemplo n.º 2
0
// writeFiles iterates through the files we want and writes them as a tarred
// file.
func writeFiles(t *testing.T, f *os.File, tname string, want []file) {
	w := tar.NewWriter(f)
	defer w.Close()

	// Write zipped files
	for _, fwant := range want {
		fi := iotest.FileInfo(t, fwant.contents)

		// Write the file
		err := w.NextFile(fwant.name, fi)
		switch err {
		case io.EOF:
			break
		default:
			t.Fatalf("%s: write header for next file: %v", tname, err)
		case nil: // Proceed below
		}
		if _, err := io.Copy(w, bytes.NewReader(fwant.contents)); err != nil {
			t.Fatalf("%s: copy to writer: %v", tname, err)
		}
	}
}