From c76e42010eb78200c826024cff1d7bba76082715 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 14 Aug 2015 07:55:18 -0400 Subject: [PATCH] tar/asm: additional GNU LongLink testcase Adding a minimal test case for GNU @LongLink. Tested that it fails on v0.9.5, but now passes on v0.9.6 and master. --- tar/asm/assemble_test.go | 187 ++++++++++------------------ tar/asm/testdata/fatlonglink.tar.gz | Bin 0 -> 26402 bytes 2 files changed, 63 insertions(+), 124 deletions(-) create mode 100644 tar/asm/testdata/fatlonglink.tar.gz diff --git a/tar/asm/assemble_test.go b/tar/asm/assemble_test.go index e37d7f3..da515f2 100644 --- a/tar/asm/assemble_test.go +++ b/tar/asm/assemble_test.go @@ -113,137 +113,76 @@ func TestTarStreamMangledGetterPutter(t *testing.T) { } func TestTarStream(t *testing.T) { - var ( - expectedSHA1Sum = "1eb237ff69bca6e22789ecb05b45d35ca307adbd" - expectedSize int64 = 10240 - ) - - fh, err := os.Open("./testdata/t.tar.gz") - if err != nil { - t.Fatal(err) - } - defer fh.Close() - gzRdr, err := gzip.NewReader(fh) - if err != nil { - t.Fatal(err) - } - defer gzRdr.Close() - - // Setup where we'll store the metadata - w := bytes.NewBuffer([]byte{}) - sp := storage.NewJSONPacker(w) - fgp := storage.NewBufferFileGetPutter() - - // wrap the disassembly stream - tarStream, err := NewInputTarStream(gzRdr, sp, fgp) - if err != nil { - t.Fatal(err) + testCases := []struct { + path string + expectedSHA1Sum string + expectedSize int64 + }{ + {"./testdata/t.tar.gz", "1eb237ff69bca6e22789ecb05b45d35ca307adbd", 10240}, + {"./testdata/longlink.tar.gz", "d9f6babe107b7247953dff6b5b5ae31a3a880add", 20480}, + {"./testdata/fatlonglink.tar.gz", "8537f03f89aeef537382f8b0bb065d93e03b0be8", 26234880}, } - // get a sum of the stream after it has passed through to ensure it's the same. - h0 := sha1.New() - tRdr0 := io.TeeReader(tarStream, h0) + for _, tc := range testCases { + fh, err := os.Open(tc.path) + if err != nil { + t.Fatal(err) + } + defer fh.Close() + gzRdr, err := gzip.NewReader(fh) + if err != nil { + t.Fatal(err) + } + defer gzRdr.Close() - // read it all to the bit bucket - i, err := io.Copy(ioutil.Discard, tRdr0) - if err != nil { - t.Fatal(err) - } + // Setup where we'll store the metadata + w := bytes.NewBuffer([]byte{}) + sp := storage.NewJSONPacker(w) + fgp := storage.NewBufferFileGetPutter() - if i != expectedSize { - t.Errorf("size of tar: expected %d; got %d", expectedSize, i) - } - if fmt.Sprintf("%x", h0.Sum(nil)) != expectedSHA1Sum { - t.Fatalf("checksum of tar: expected %s; got %x", expectedSHA1Sum, h0.Sum(nil)) - } + // wrap the disassembly stream + tarStream, err := NewInputTarStream(gzRdr, sp, fgp) + if err != nil { + t.Fatal(err) + } - t.Logf("%s", w.String()) // if we fail, then show the packed info + // get a sum of the stream after it has passed through to ensure it's the same. + h0 := sha1.New() + tRdr0 := io.TeeReader(tarStream, h0) - // If we've made it this far, then we'll turn it around and create a tar - // stream from the packed metadata and buffered file contents. - r := bytes.NewBuffer(w.Bytes()) - sup := storage.NewJSONUnpacker(r) - // and reuse the fgp that we Put the payloads to. + // read it all to the bit bucket + i, err := io.Copy(ioutil.Discard, tRdr0) + if err != nil { + t.Fatal(err) + } - rc := NewOutputTarStream(fgp, sup) - h1 := sha1.New() - i, err = io.Copy(h1, rc) - if err != nil { - t.Fatal(err) - } + if i != tc.expectedSize { + t.Errorf("size of tar: expected %d; got %d", tc.expectedSize, i) + } + if fmt.Sprintf("%x", h0.Sum(nil)) != tc.expectedSHA1Sum { + t.Fatalf("checksum of tar: expected %s; got %x", tc.expectedSHA1Sum, h0.Sum(nil)) + } - if i != expectedSize { - t.Errorf("size of output tar: expected %d; got %d", expectedSize, i) - } - if fmt.Sprintf("%x", h1.Sum(nil)) != expectedSHA1Sum { - t.Fatalf("checksum of output tar: expected %s; got %x", expectedSHA1Sum, h1.Sum(nil)) - } -} - -func TestTarGNUTar(t *testing.T) { - var ( - expectedSHA1Sum = "d9f6babe107b7247953dff6b5b5ae31a3a880add" - expectedSize int64 = 20480 - ) - - fh, err := os.Open("./testdata/longlink.tar.gz") - if err != nil { - t.Fatal(err) - } - defer fh.Close() - gzRdr, err := gzip.NewReader(fh) - if err != nil { - t.Fatal(err) - } - defer gzRdr.Close() - - // Setup where we'll store the metadata - w := bytes.NewBuffer([]byte{}) - sp := storage.NewJSONPacker(w) - fgp := storage.NewBufferFileGetPutter() - - // wrap the disassembly stream - tarStream, err := NewInputTarStream(gzRdr, sp, fgp) - if err != nil { - t.Fatal(err) - } - - // get a sum of the stream after it has passed through to ensure it's the same. - h0 := sha1.New() - tRdr0 := io.TeeReader(tarStream, h0) - - // read it all to the bit bucket - i, err := io.Copy(ioutil.Discard, tRdr0) - if err != nil { - t.Fatal(err) - } - - if i != expectedSize { - t.Errorf("size of tar: expected %d; got %d", expectedSize, i) - } - if fmt.Sprintf("%x", h0.Sum(nil)) != expectedSHA1Sum { - t.Fatalf("checksum of tar: expected %s; got %x", expectedSHA1Sum, h0.Sum(nil)) - } - - t.Logf("%s", w.String()) // if we fail, then show the packed info - - // If we've made it this far, then we'll turn it around and create a tar - // stream from the packed metadata and buffered file contents. - r := bytes.NewBuffer(w.Bytes()) - sup := storage.NewJSONUnpacker(r) - // and reuse the fgp that we Put the payloads to. - - rc := NewOutputTarStream(fgp, sup) - h1 := sha1.New() - i, err = io.Copy(h1, rc) - if err != nil { - t.Fatal(err) - } - - if i != expectedSize { - t.Errorf("size of output tar: expected %d; got %d", expectedSize, i) - } - if fmt.Sprintf("%x", h1.Sum(nil)) != expectedSHA1Sum { - t.Fatalf("checksum of output tar: expected %s; got %x", expectedSHA1Sum, h1.Sum(nil)) + t.Logf("%s", w.String()) // if we fail, then show the packed info + + // If we've made it this far, then we'll turn it around and create a tar + // stream from the packed metadata and buffered file contents. + r := bytes.NewBuffer(w.Bytes()) + sup := storage.NewJSONUnpacker(r) + // and reuse the fgp that we Put the payloads to. + + rc := NewOutputTarStream(fgp, sup) + h1 := sha1.New() + i, err = io.Copy(h1, rc) + if err != nil { + t.Fatal(err) + } + + if i != tc.expectedSize { + t.Errorf("size of output tar: expected %d; got %d", tc.expectedSize, i) + } + if fmt.Sprintf("%x", h1.Sum(nil)) != tc.expectedSHA1Sum { + t.Fatalf("checksum of output tar: expected %s; got %x", tc.expectedSHA1Sum, h1.Sum(nil)) + } } } diff --git a/tar/asm/testdata/fatlonglink.tar.gz b/tar/asm/testdata/fatlonglink.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..0d8ed148ff12cfeb30fab84c35735c31e6a4c326 GIT binary patch literal 26402 zcmeI(e=yr;90zdL?a&$RZavm@akc7})DSDZq3GFmn?tp##VBgpBclw>tR&8q>AGgU zIbl)EE$Ny}P(_6%epPN9j!1`ylvHRF`O!2YiR4+f+wI@>U+d@l=kvVp`~5tx`~LO5 zd)&Uax4%9$7W>k+{Pethul&@nY!tJEsHJGvl0`52fs(vO8Hi)!f6T)*&Aqa*cGit2Cva|LHaVy&7|rW{A{LbCfl>{jH=^ge$p_iqmm8#ulUL%?O9pzh% znKnkXBnwfy%DO>~PB8Osqj#P91C7L_`$%pgkMFpml3c*AlHJWALDmQ{3ukONjwp`( zs}^k4umwFe^78D5^_0jq6f$X%R-_c6sz4KpQHEq%mnS})Lk&f!%c+0E5*faZRwmJF zVLn`PrxdoOL63<5d6dg`Q3;mRxdw<0BVC-N?cx!QBgsWm%;X8$xmOtLPD0orfkvKIBDB~)Qd$4+MBa%Lrpj>uM#W6J)B-n6fV}t z(SKblW~*_*ydVGqAOHd&00JNY0w4ea{|J;cCpv zsKe2hHt->9{F>vmWw9UTLGEc|TKzeGMgo^93P5yY;hqr^W>~KjJh>>=uKBRrn@{d@ z*fb$tIVX$eC(We}6b7YpGskNwv6=FKdpL&Yw2&PYk73uM8^t_N?J}o1?}avp!-D__ zfB*=900@8p2!H?xfB*=900@8p2!OyA6|m5oJV$8R0rLg=iV8Q*JH6cp%W*>#Lq^DO z)tsk_t+AnKr`)tbfl-1dvEus%Z{dVAdR^HB-`vT1-1}&q%{I2!O!