LEFT | RIGHT |
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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 func TestParsePAXHeader(t *testing.T) { | 298 func TestParsePAXHeader(t *testing.T) { |
299 paxTests := [][3]string{ | 299 paxTests := [][3]string{ |
300 {"a", "a=name", "10 a=name\n"}, // Test case involving multiple
acceptable lengths | 300 {"a", "a=name", "10 a=name\n"}, // Test case involving multiple
acceptable lengths |
301 {"a", "a=name", "9 a=name\n"}, // Test case involving multiple
acceptable length | 301 {"a", "a=name", "9 a=name\n"}, // Test case involving multiple
acceptable length |
302 {"mtime", "mtime=1350244992.023960108", "30 mtime=1350244992.023
960108\n"}} | 302 {"mtime", "mtime=1350244992.023960108", "30 mtime=1350244992.023
960108\n"}} |
303 for _, test := range paxTests { | 303 for _, test := range paxTests { |
304 key, expected, raw := test[0], test[1], test[2] | 304 key, expected, raw := test[0], test[1], test[2] |
305 reader := bytes.NewBuffer([]byte(raw)) | 305 reader := bytes.NewBuffer([]byte(raw)) |
306 headers, err := parsePAX(reader) | 306 headers, err := parsePAX(reader) |
307 if err != nil { | 307 if err != nil { |
308 » » » t.Errorf("Couldn't parse correctly formatted headers %v"
, err) | 308 » » » t.Errorf("Couldn't parse correctly formatted headers: %v
", err) |
309 continue | 309 continue |
310 } | 310 } |
311 if strings.EqualFold(headers[key], expected) { | 311 if strings.EqualFold(headers[key], expected) { |
312 t.Errorf("mtime header incorrectly parsed: got %s, wante
d %s", headers[key], expected) | 312 t.Errorf("mtime header incorrectly parsed: got %s, wante
d %s", headers[key], expected) |
313 continue | 313 continue |
314 } | 314 } |
315 trailer := make([]byte, 100) | 315 trailer := make([]byte, 100) |
316 n, err := reader.Read(trailer) | 316 n, err := reader.Read(trailer) |
317 if err != io.EOF || n != 0 { | 317 if err != io.EOF || n != 0 { |
318 t.Error("Buffer wasn't consumed") | 318 t.Error("Buffer wasn't consumed") |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 357 } |
358 want := &Header{ | 358 want := &Header{ |
359 Name: "a/b/c", | 359 Name: "a/b/c", |
360 Uid: 1000, | 360 Uid: 1000, |
361 ModTime: time.Unix(1350244992, 23960108), | 361 ModTime: time.Unix(1350244992, 23960108), |
362 } | 362 } |
363 if !reflect.DeepEqual(hdr, want) { | 363 if !reflect.DeepEqual(hdr, want) { |
364 t.Errorf("incorrect merge: got %+v, want %+v", hdr, want) | 364 t.Errorf("incorrect merge: got %+v, want %+v", hdr, want) |
365 } | 365 } |
366 } | 366 } |
LEFT | RIGHT |