File: convert_test.go

package info (click to toggle)
golang-github-tinylib-msgp 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: makefile: 47
file content (60 lines) | stat: -rw-r--r-- 1,317 bytes parent folder | download | duplicates (3)
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
package _generated

import (
	"bytes"
	"testing"

	"github.com/tinylib/msgp/msgp"
)

func TestConvertFromEncodeError(t *testing.T) {
	e := ConvertErr{ConvertErrVal(fromFailStr)}
	var buf bytes.Buffer
	w := msgp.NewWriter(&buf)
	err := e.EncodeMsg(w)
	if msgp.Cause(err) != errConvertFrom {
		t.Fatalf("expected conversion error, found '%v'", err.Error())
	}
}

func TestConvertToEncodeError(t *testing.T) {
	var in, out ConvertErr
	in = ConvertErr{ConvertErrVal(toFailStr)}
	var buf bytes.Buffer
	w := msgp.NewWriter(&buf)
	err := in.EncodeMsg(w)
	if err != nil {
		t.FailNow()
	}
	w.Flush()

	r := msgp.NewReader(&buf)
	err = (&out).DecodeMsg(r)

	if msgp.Cause(err) != errConvertTo {
		t.Fatalf("expected conversion error, found %v", err.Error())
	}
}

func TestConvertFromMarshalError(t *testing.T) {
	e := ConvertErr{ConvertErrVal(fromFailStr)}
	var b []byte
	_, err := e.MarshalMsg(b)
	if msgp.Cause(err) != errConvertFrom {
		t.Fatalf("expected conversion error, found %v", err.Error())
	}
}

func TestConvertToMarshalError(t *testing.T) {
	var in, out ConvertErr
	in = ConvertErr{ConvertErrVal(toFailStr)}
	b, err := in.MarshalMsg(nil)
	if err != nil {
		t.FailNow()
	}

	_, err = (&out).UnmarshalMsg(b)
	if msgp.Cause(err) != errConvertTo {
		t.Fatalf("expected conversion error, found %v", err.Error())
	}
}