Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(471)

Delta Between Two Patch Sets: src/pkg/archive/tar/reader_test.go

Issue 6700047: code review 6700047: archive/tar: read/write extended pax/gnu tar archives (Closed)
Left Patch Set: diff -r 1399878c6731 https://code.google.com/p/go Created 12 years, 3 months ago
Right Patch Set: diff -r 439cb8bad388 https://code.google.com/p/go Created 12 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/archive/tar/reader.go ('k') | src/pkg/archive/tar/testdata/pax.tar » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package tar 5 package tar
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "crypto/md5" 9 "crypto/md5"
10 "fmt" 10 "fmt"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 t.Fatalf("Unexpected error: %v", err) 289 t.Fatalf("Unexpected error: %v", err)
290 } 290 }
291 } 291 }
292 292
293 if nread != len(test.headers) { 293 if nread != len(test.headers) {
294 t.Errorf("Didn't process all files\nexpected: %d\nprocessed %d\n ", len(test.headers), nread) 294 t.Errorf("Didn't process all files\nexpected: %d\nprocessed %d\n ", len(test.headers), nread)
295 } 295 }
296 } 296 }
297 297
298 func TestParsePAXHeader(t *testing.T) { 298 func TestParsePAXHeader(t *testing.T) {
299 » correctHeaders := []byte("30 mtime=1350244992.023960108\n") 299 » paxTests := [][3]string{
300 » reader := bytes.NewBuffer(correctHeaders) 300 » » {"a", "a=name", "10 a=name\n"}, // Test case involving multiple acceptable lengths
301 » headers, err := parsePAX(reader) 301 » » {"a", "a=name", "9 a=name\n"}, // Test case involving multiple acceptable length
302 » if err != nil { 302 » » {"mtime", "mtime=1350244992.023960108", "30 mtime=1350244992.023 960108\n"}}
303 » » t.Fatalf("Couldn't parse correctly formatted headers %s", err) 303 » for _, test := range paxTests {
304 » } 304 » » key, expected, raw := test[0], test[1], test[2]
305 » if strings.EqualFold(headers["mtime"], "mtime=1350244992.023960108") { 305 » » reader := bytes.NewBuffer([]byte(raw))
306 » » t.Fatalf("mtime header incorrectly parsed") 306 » » headers, err := parsePAX(reader)
307 » } 307 » » if err != nil {
308 » trailer := make([]byte, 100) 308 » » » t.Errorf("Couldn't parse correctly formatted headers: %v ", err)
309 » n, err := reader.Read(trailer) 309 » » » continue
310 » if err != io.EOF || n != 0 { 310 » » }
311 » » t.Fatal("Buffer wasn't consumed") 311 » » if strings.EqualFold(headers[key], expected) {
312 » » » t.Errorf("mtime header incorrectly parsed: got %s, wante d %s", headers[key], expected)
313 » » » continue
314 » » }
315 » » trailer := make([]byte, 100)
316 » » n, err := reader.Read(trailer)
317 » » if err != io.EOF || n != 0 {
318 » » » t.Error("Buffer wasn't consumed")
319 » » }
312 } 320 }
313 badHeader := bytes.NewBuffer([]byte("3 somelongkey=")) 321 badHeader := bytes.NewBuffer([]byte("3 somelongkey="))
314 if _, err := parsePAX(badHeader); err != ErrHeader { 322 if _, err := parsePAX(badHeader); err != ErrHeader {
315 t.Fatal("Unexpected success when parsing bad header") 323 t.Fatal("Unexpected success when parsing bad header")
316 } 324 }
317 } 325 }
318 326
319 func TestParsePAXTime(t *testing.T) { 327 func TestParsePAXTime(t *testing.T) {
320 // Some valid PAX time values 328 // Some valid PAX time values
321 timestamps := map[string]time.Time{ 329 timestamps := map[string]time.Time{
(...skipping 27 matching lines...) Expand all
349 } 357 }
350 want := &Header{ 358 want := &Header{
351 Name: "a/b/c", 359 Name: "a/b/c",
352 Uid: 1000, 360 Uid: 1000,
353 ModTime: time.Unix(1350244992, 23960108), 361 ModTime: time.Unix(1350244992, 23960108),
354 } 362 }
355 if !reflect.DeepEqual(hdr, want) { 363 if !reflect.DeepEqual(hdr, want) {
356 t.Errorf("incorrect merge: got %+v, want %+v", hdr, want) 364 t.Errorf("incorrect merge: got %+v, want %+v", hdr, want)
357 } 365 }
358 } 366 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b