package email import ( "os" "path/filepath" "testing" ) // "An existing connection was forcibly closed" during DATA reads the same // whether the server refused the SIZE, hit a quota, or just dropped the socket // — and only the first is something the operator can act on. Naming the size in // the error rules it in or out without a second attempt. func TestDescribeSize(t *testing.T) { dir := t.TempDir() a := filepath.Join(dir, "card.jpg") if err := os.WriteFile(a, make([]byte, 2048), 0o644); err != nil { t.Fatal(err) } if got := describeSize(nil); got != "no attachment" { t.Errorf("no attachment = %q", got) } if got := describeSize([]string{""}); got != "no attachment" { t.Errorf("blank path = %q, want it ignored", got) } if got := describeSize([]string{a}); got != "1 attachment(s), 2 KB" { t.Errorf("one file = %q", got) } // A path that does not exist must not be counted — the mail library skips it, // so reporting it would describe a message that was never sent. if got := describeSize([]string{a, filepath.Join(dir, "gone.jpg")}); got != "1 attachment(s), 2 KB" { t.Errorf("missing file counted: %q", got) } }