From 61e2d7184df8ba0f1505b8cc3705ab4f705af450 Mon Sep 17 00:00:00 2001 From: kaichaosun Date: Tue, 11 Jun 2024 14:15:10 +0800 Subject: [PATCH] chore_: fix test --- .../common/raw_messages_persistence_test.go | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/protocol/common/raw_messages_persistence_test.go b/protocol/common/raw_messages_persistence_test.go index 5d6e8c7060b..563758855b9 100644 --- a/protocol/common/raw_messages_persistence_test.go +++ b/protocol/common/raw_messages_persistence_test.go @@ -54,18 +54,7 @@ func TestUpdateRawMessageSent(t *testing.T) { require.NoError(t, err) rawMessageID := "1" - err = p.SaveRawMessage(&RawMessage{ - ID: rawMessageID, - ResendType: ResendTypeRawMessage, - LocalChatID: "", - CommunityID: []byte("c1"), - CommunityKeyExMsgType: KeyExMsgRekey, - Sender: pk, - ResendMethod: ResendMethodSendPrivate, - Recipients: []*ecdsa.PublicKey{pk.Public().(*ecdsa.PublicKey)}, - Sent: true, - LastSent: uint64(time.Now().UnixNano() / int64(time.Millisecond)), - }) + err = p.SaveRawMessage(buildRawMessage(rawMessageID, pk)) require.NoError(t, err) rawMessage, err := p.RawMessageByID(rawMessageID) @@ -79,7 +68,6 @@ func TestUpdateRawMessageSent(t *testing.T) { m, err := p.RawMessageByID(rawMessageID) require.NoError(t, err) require.False(t, m.Sent) - require.Equal(t, m.LastSent, uint64(0)) } func TestUpdateRawMessageLastSent(t *testing.T) { @@ -92,18 +80,7 @@ func TestUpdateRawMessageLastSent(t *testing.T) { require.NoError(t, err) rawMessageID := "1" - err = p.SaveRawMessage(&RawMessage{ - ID: rawMessageID, - ResendType: ResendTypeRawMessage, - LocalChatID: "", - CommunityID: []byte("c1"), - CommunityKeyExMsgType: KeyExMsgRekey, - Sender: pk, - ResendMethod: ResendMethodSendPrivate, - Recipients: []*ecdsa.PublicKey{pk.Public().(*ecdsa.PublicKey)}, - Sent: true, - LastSent: uint64(time.Now().UnixNano() / int64(time.Millisecond)), - }) + err = p.SaveRawMessage(buildRawMessage(rawMessageID, pk)) require.NoError(t, err) rawMessage, err := p.RawMessageByID(rawMessageID) @@ -118,3 +95,18 @@ func TestUpdateRawMessageLastSent(t *testing.T) { require.NoError(t, err) require.Equal(t, m.LastSent, uint64(0)) } + +func buildRawMessage(rawMessageID string, pk *ecdsa.PrivateKey) *RawMessage { + return &RawMessage{ + ID: rawMessageID, + ResendType: ResendTypeRawMessage, + LocalChatID: "", + CommunityID: []byte("c1"), + CommunityKeyExMsgType: KeyExMsgRekey, + Sender: pk, + ResendMethod: ResendMethodSendPrivate, + Recipients: []*ecdsa.PublicKey{pk.Public().(*ecdsa.PublicKey)}, + Sent: true, + LastSent: uint64(time.Now().UnixNano() / int64(time.Millisecond)), + } +}