package ident_test import ( "encoding/base64" "strings" "testing" "time" "git.gensokyo.uk/cofront/cof-spec/ident" ) func TestPartM(t *testing.T) { t.Parallel() rTestCases[ident.PartM, *ident.PartM]{ {"short", ident.PartM{}, nil, &ident.UnexpectedSizeError{ Data: nil, Want: ident.EncodedSizeMember - ident.EncodedSizeSystem, }}, {"malformed", ident.PartM{}, []byte{ 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, }, base64.CorruptInputError(0)}, {"newline", ident.PartM{}, []byte( "AAAA" + strings.Repeat("\n", ident.EncodedSizeMember-ident.EncodedSizeSystem-4), ), ident.ErrNewline}, {"valid", ident.PartM{ Serial: 0xfdfdfdfdfdfdfdfd, Time: uint64(time.Date( 0xfd, 7, 15, 23, 59, 59, 0xcab, time.UTC, ).UnixNano()), ID: 0x2e736e64, }, base64.URLEncoding.AppendEncode(nil, []byte{ /* serial: */ 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, /* time: */ 0xab, 0x42, 0x42, 0xce, 0xf1, 0x92, 0x4a, 0x10, /* id: */ 0x64, 0x6e, 0x73, 0x2e, 0, 0, 0, 0, }), nil}, }.run(t) } func TestM(t *testing.T) { t.Parallel() rTestCases[ident.M, *ident.M]{ {"short", ident.M{}, nil, &ident.UnexpectedSizeError{ Data: nil, Want: ident.EncodedSizeMember, }}, {"malformed", ident.M{}, []byte{ 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, 0xfe, 0xe1, 0xde, 0xad, }, base64.CorruptInputError(0)}, {"newline", ident.M{}, []byte( "AAAA" + strings.Repeat("\n", ident.EncodedSizeMember-4), ), ident.ErrNewline}, {"valid", ident.M{ PartM: ident.PartM{ Serial: 0xfdfdfdfdfdfdfdfd, Time: uint64(time.Date( 0xfd, 7, 15, 23, 59, 59, 0xcab, time.UTC, ).UnixNano()), ID: 0x2e736e64, }, System: ident.S{ Site: ident.TrivialSite, Host: ident.TrivialHost, Time: uint64(time.Date( 0xfd, 7, 15, 23, 59, 59, 0xcafe, time.UTC, ).UnixNano()), ID: 0xfee1dead0badf00d, }, }, base64.URLEncoding.AppendEncode(nil, []byte{ /* member */ /* serial: */ 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, /* time: */ 0xab, 0x42, 0x42, 0xce, 0xf1, 0x92, 0x4a, 0x10, /* id: */ 0x64, 0x6e, 0x73, 0x2e, 0, 0, 0, 0, /* system */ /* site: */ 0xfe, 0xca, 0xed, 0xfe, /* host: */ 0xbe, 0xba, 0xfe, 0xca, /* time: */ 0xfe, 0, 0x43, 0xce, 0xf1, 0x92, 0x4a, 0x10, /* id: */ 0xd, 0xf0, 0xad, 0xb, 0xad, 0xde, 0xe1, 0xfe, }), nil}, }.run(t) }