File: writer_test.go

package info (click to toggle)
golang-github-mkrautz-goar 0.0~git20150919.282caa8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 112 kB
  • sloc: makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2011 Mikkel Krautz
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.

package ar

import (
	"bytes"
	"testing"
)

func TestLongWrite(t *testing.T) {
	buf := new(bytes.Buffer)
	w := NewWriter(buf)
	err := w.WriteHeader(&Header{
			Name:  "/",
			Mode:  0,
			Mtime: 1315607407,
			Uid:   0,
			Gid:   0,
			Size:  4,
	})
	if err != nil {
		t.Fatal(err)
	}
	_, err = w.Write([]byte{1, 2, 3, 4, 5})
	if err != ErrWriteTooLong {
		t.Fatalf("expected ErrWriteTooLong, got %v", err)
	}
}

func TestWriteAfterClose(t *testing.T) {
	buf := new(bytes.Buffer)
	w := NewWriter(buf)
	err := w.WriteHeader(&Header{
			Name:  "/",
			Mode:  0,
			Mtime: 1315607407,
			Uid:   0,
			Gid:   0,
			Size:  4,
	})
	if err != nil {
		t.Fatal(err)
	}
	_, err = w.Write([]byte{1, 2, 3})
	if err != nil {
		t.Fatal(err)
	}
	err = w.Close()
	if err != nil {
		t.Fatal(err)
	}
	_, err = w.Write([]byte{4})
	if err != ErrWriteAfterClose {
		t.Fatalf("expected ErrWriteAfterClose, got %v", err)
	}
}