X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/60ec6281e7a98cb268cf9a8ec7945069fe195cde..ea5d8c51c2ebfc3d9d26c1ba7123c35b49efcda6:/hotline/transaction_handlers_test.go?ds=sidebyside diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 06782a1..5136c7d 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -2810,3 +2810,80 @@ None. }) } } + +func TestHandleTranAgreed(t *testing.T) { + type args struct { + cc *ClientConn + t *Transaction + } + tests := []struct { + name string + args args + wantRes []Transaction + wantErr assert.ErrorAssertionFunc + }{ + { + name: "normal request flow", + args: args{ + cc: &ClientConn{ + Account: &Account{ + Access: func() *[]byte { + var bits accessBitmap + bits.Set(accessDisconUser) + bits.Set(accessAnyName) + access := bits[:] + return &access + }()}, + Icon: &[]byte{0, 1}, + Flags: &[]byte{0, 1}, + Version: &[]byte{0, 1}, + ID: &[]byte{0, 1}, + logger: NewTestLogger(), + Server: &Server{ + Config: &Config{ + BannerFile: "banner.jpg", + }, + }, + }, + t: NewTransaction( + tranAgreed, nil, + NewField(fieldUserName, []byte("username")), + NewField(fieldUserIconID, []byte{0, 1}), + NewField(fieldOptions, []byte{0, 0}), + ), + }, + wantRes: []Transaction{ + { + clientID: &[]byte{0, 1}, + Flags: 0x00, + IsReply: 0x00, + Type: []byte{0, 0x7a}, + ID: []byte{0, 0, 0, 0}, + ErrorCode: []byte{0, 0, 0, 0}, + Fields: []Field{ + NewField(fieldBannerType, []byte("JPEG")), + }, + }, + { + clientID: &[]byte{0, 1}, + Flags: 0x00, + IsReply: 0x01, + Type: []byte{0, 0x79}, + ID: []byte{0, 0, 0, 0}, + ErrorCode: []byte{0, 0, 0, 0}, + Fields: []Field{}, + }, + }, + wantErr: assert.NoError, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotRes, err := HandleTranAgreed(tt.args.cc, tt.args.t) + if !tt.wantErr(t, err, fmt.Sprintf("HandleTranAgreed(%v, %v)", tt.args.cc, tt.args.t)) { + return + } + tranAssertEqual(t, tt.wantRes, gotRes) + }) + } +}