Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

74 lines
2.0 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package draft
import (
"testing"
)
func TestCheckLimit_LargeBodyDoesNotCountAsAttachment(t *testing.T) {
// A draft whose text/plain body is 20 MB should still allow adding a
// small attachment — the body is not an attachment.
snapshot := &DraftSnapshot{
Body: &Part{
MediaType: "multipart/mixed",
Children: []*Part{
{
MediaType: "text/plain",
Body: make([]byte, 20*1024*1024), // 20 MB body
},
},
},
}
if err := checkSnapshotAttachmentLimit(snapshot, 1024, nil); err != nil {
t.Fatalf("should allow adding a small attachment when only the body is large: %v", err)
}
}
func TestCheckLimit_ReplaceInlineDoesNotDoubleCount(t *testing.T) {
// An existing inline image is 10 MB. Replacing it with a 10 MB file
// should succeed because the old part's size is deducted.
oldInline := &Part{
MediaType: "image/png",
ContentDisposition: "inline",
ContentID: "img1",
Body: make([]byte, 10*1024*1024), // 10 MB
}
snapshot := &DraftSnapshot{
Body: &Part{
MediaType: "multipart/related",
Children: []*Part{
{MediaType: "text/html", Body: []byte("<img src='cid:img1'>")},
oldInline,
},
},
}
if err := checkSnapshotAttachmentLimit(snapshot, 10*1024*1024, oldInline); err != nil {
t.Fatalf("replace inline should not double-count: %v", err)
}
}
func TestCheckLimit_ExceedsSizeWithAttachments(t *testing.T) {
// Existing attachment is 20 MB. Adding a 6 MB file should exceed the 25 MB limit.
snapshot := &DraftSnapshot{
Body: &Part{
MediaType: "multipart/mixed",
Children: []*Part{
{MediaType: "text/plain", Body: []byte("hello")},
{
MediaType: "application/octet-stream",
ContentDisposition: "attachment",
Body: make([]byte, 20*1024*1024), // 20 MB
},
},
},
}
if err := checkSnapshotAttachmentLimit(snapshot, 6*1024*1024, nil); err == nil {
t.Fatal("should reject when total attachment size exceeds 25 MB")
}
}