~chrisppy/go-barefeed

ref: 63fc114fd6c8a8779e44c7042a5c1a6f543a76fb go-barefeed/barefeed_test.go -rw-r--r-- 1.5 KiB
63fc114fChris Palmer updates from schema 5 months ago
                                                                                
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
59
60
61
62
63
64
65
66
67
68
69
70
package barefeed

import (
	"bytes"
	"testing"
)

func TestBytes(t *testing.T) {
	expected := getMessage()

	b, err := expected.Bytes()
	if err != nil {
		t.Errorf("Bytes should not have error: %e", err)
	} else if b == nil {
		t.Errorf("Bytes should not be nil: %e", err)
	} else if len(b) == 0 {
		t.Errorf("Bytes should not be empty: %e", err)
	}

	actual, err := FromBytes(b)
	if err != nil {
		t.Errorf("Message should not have error: %e", err)
	} else if actual == nil {
		t.Errorf("Message should not have been nil")
	}

	testMessage(t, expected, *actual)
}

func TestReader(t *testing.T) {
	expected := getMessage()

	b, err := expected.Bytes()
	if err != nil {
		t.Errorf("Bytes should not have error: %e", err)
	} else if b == nil {
		t.Errorf("Bytes should not be nil: %e", err)
	} else if len(b) == 0 {
		t.Errorf("Bytes should not be empty: %e", err)
	}

	actual, err := FromReader(bytes.NewReader(b))
	if err != nil {
		t.Errorf("Message should not have error: %e", err)
	} else if actual == nil {
		t.Errorf("Message should not have been nil")
	}

	testMessage(t, expected, *actual)
}

func TestFromBytesError(t *testing.T) {
	m, err := FromBytes([]byte("{"))
	if m != nil {
		t.Errorf("Message should have been nil: %v", m)
	}
	if err == nil {
		t.Errorf("error should not have been nil")
	}
}

func TestFromReaderError(t *testing.T) {
	m, err := FromReader(bytes.NewReader([]byte("{")))
	if m != nil {
		t.Errorf("Message should have been nil: %v", m)
	}
	if err == nil {
		t.Errorf("error should not have been nil")
	}
}