msgpack-go

Message Pack Encoder/Decoder for Golang
git clone git://git.lair.cx/msgpack-go
Log | Files | Refs | LICENSE

uuid_test.go (1029B)


      1 package msgpack
      2 
      3 import (
      4 	"bytes"
      5 	"testing"
      6 
      7 	"github.com/google/uuid"
      8 )
      9 
     10 type uuidTestCase struct {
     11 	in  string
     12 	out []byte
     13 }
     14 
     15 var tests = []uuidTestCase{
     16 	{"f47ac10b-58cc-4372-8567-0e02b2c3d479", []byte{
     17 		0xd8, 0x7f, // header
     18 		0xf4, 0x7a, 0xc1, 0x0b, 0x58, 0xcc, 0x43, 0x72,
     19 		0x85, 0x67, 0x0e, 0x02, 0xb2, 0xc3, 0xd4, 0x79,
     20 	}},
     21 }
     22 
     23 func TestUUIDMarshal(t *testing.T) {
     24 	for _, test := range tests {
     25 		raw, err := uuid.Parse(test.in)
     26 		if err != nil {
     27 			t.Errorf("parse failed: %s, %s", test.in, err.Error())
     28 			continue
     29 		}
     30 
     31 		wrapped := &UUID{raw}
     32 		got := Marshal(wrapped)
     33 		if !bytes.Equal(got, test.out) {
     34 			t.Errorf("marshal failed; got: %v, want: %v", got, test.out)
     35 		}
     36 	}
     37 }
     38 
     39 func TestUUIDUnmarshal(t *testing.T) {
     40 	for _, test := range tests {
     41 		wrapped := &UUID{}
     42 
     43 		err := Unmarshal(test.out, wrapped)
     44 		if err != nil {
     45 			t.Errorf("marshal failed; err: %s", err.Error())
     46 			continue
     47 		}
     48 
     49 		if wrapped.String() != test.in {
     50 			t.Errorf("marshal failed; got: %v, want: %v", wrapped.String(), test.in)
     51 		}
     52 	}
     53 }