-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_cache_test.go
More file actions
105 lines (87 loc) · 2.87 KB
/
Copy pathmessage_cache_test.go
File metadata and controls
105 lines (87 loc) · 2.87 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2026 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Tests for message deduplication cache.
package main
import (
"net/mail"
"strings"
"testing"
"github.com/jhillyerd/enmime"
)
func TestMessageCache_IsDuplicate(t *testing.T) {
cache := NewMessageCache()
// First occurrence should not be duplicate
if cache.IsDuplicate("key1") {
t.Error("First occurrence of key1 should not be duplicate")
}
// Second occurrence should be duplicate
if !cache.IsDuplicate("key1") {
t.Error("Second occurrence of key1 should be duplicate")
}
// Different key should not be duplicate
if cache.IsDuplicate("key2") {
t.Error("First occurrence of key2 should not be duplicate")
}
// Original key should still be duplicate
if !cache.IsDuplicate("key1") {
t.Error("Third occurrence of key1 should still be duplicate")
}
}
func TestMailMessage_GetDeduplicationKey_WithMessageID(t *testing.T) {
message := &MailMessage{
from: &mail.Address{Address: "test@example.com"},
subject: "Test Subject",
body: &enmime.Envelope{HTML: "<p>Test body</p>"},
messageId: "<abc123@example.com>",
}
key := message.GetDeduplicationKey()
expected := "msgid:<abc123@example.com>"
if key != expected {
t.Errorf("Expected key %q, got %q", expected, key)
}
}
func TestMailMessage_GetDeduplicationKey_WithoutMessageID(t *testing.T) {
message := &MailMessage{
from: &mail.Address{Address: "test@example.com"},
subject: "Test Subject",
body: &enmime.Envelope{HTML: "<p>Test body</p>"},
}
key := message.GetDeduplicationKey()
if len(key) <= 5 {
t.Error("Key should be longer than 5 characters")
}
if !strings.HasPrefix(key, "hash:") {
t.Errorf("Key should start with 'hash:', got %q", key)
}
}
func TestMailMessage_GetDeduplicationKey_SameContentSameHash(t *testing.T) {
message1 := &MailMessage{
from: &mail.Address{Address: "test@example.com"},
subject: "Test Subject",
body: &enmime.Envelope{HTML: "<p>Test body</p>"},
}
message2 := &MailMessage{
from: &mail.Address{Address: "test@example.com"},
subject: "Test Subject",
body: &enmime.Envelope{HTML: "<p>Test body</p>"},
}
if message1.GetDeduplicationKey() != message2.GetDeduplicationKey() {
t.Error("Messages with same content should have same deduplication key")
}
}
func TestMailMessage_GetDeduplicationKey_DifferentContentDifferentHash(t *testing.T) {
message1 := &MailMessage{
from: &mail.Address{Address: "test@example.com"},
subject: "Test Subject",
body: &enmime.Envelope{HTML: "<p>Test body</p>"},
}
message2 := &MailMessage{
from: &mail.Address{Address: "test@example.com"},
subject: "Different Subject",
body: &enmime.Envelope{HTML: "<p>Test body</p>"},
}
if message1.GetDeduplicationKey() == message2.GetDeduplicationKey() {
t.Error("Messages with different content should have different deduplication keys")
}
}