From bfcd52b9f0925a2b1ce9945a1d72ef22ea868f3d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 18 Mar 2022 10:35:51 +0100 Subject: [PATCH] Added String() methods for AddrHeader and Header (incl. tests) --- header.go | 10 ++++++++ header_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/header.go b/header.go index 5975000..46cd00b 100644 --- a/header.go +++ b/header.go @@ -152,3 +152,13 @@ func (i Importance) String() string { return "" } } + +// String returns the header string based on the given Header +func (h Header) String() string { + return string(h) +} + +// String returns the address header string based on the given AddrHeader +func (a AddrHeader) String() string { + return string(a) +} diff --git a/header_test.go b/header_test.go index 59a627d..c9d6dd0 100644 --- a/header_test.go +++ b/header_test.go @@ -37,3 +37,65 @@ func TestImportance_StringFuncs(t *testing.T) { }) } } + +// TestAddrHeader_String tests the string method of the AddrHeader object +func TestAddrHeader_String(t *testing.T) { + tests := []struct { + name string + ah AddrHeader + want string + }{ + {"Address header: From", HeaderFrom, "From"}, + {"Address header: To", HeaderTo, "To"}, + {"Address header: Cc", HeaderCc, "Cc"}, + {"Address header: Bcc", HeaderBcc, "Bcc"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.ah.String() != tt.want { + t.Errorf("wrong string for AddrHeader returned. Expected: %s, got: %s", + tt.want, tt.ah.String()) + } + }) + } +} + +// TestHeader_String tests the string method of the Header object +func TestHeader_String(t *testing.T) { + tests := []struct { + name string + h Header + want string + }{ + {"Header: Content-Disposition", HeaderContentDisposition, "Content-Disposition"}, + {"Header: Content-ID", HeaderContentID, "Content-ID"}, + {"Header: Content-Language", HeaderContentLang, "Content-Language"}, + {"Header: Content-Location", HeaderContentLocation, "Content-Location"}, + {"Header: Content-Transfer-Encoding", HeaderContentTransferEnc, "Content-Transfer-Encoding"}, + {"Header: Content-Type", HeaderContentType, "Content-Type"}, + {"Header: Date", HeaderDate, "Date"}, + {"Header: Importance", HeaderImportance, "Importance"}, + {"Header: In-Reply-To", HeaderInReplyTo, "In-Reply-To"}, + {"Header: List-Unsubscribe", HeaderListUnsubscribe, "List-Unsubscribe"}, + {"Header: List-Unsubscribe-Post", HeaderListUnsubscribePost, "List-Unsubscribe-Post"}, + {"Header: Message-ID", HeaderMessageID, "Message-ID"}, + {"Header: MIME-Version", HeaderMIMEVersion, "MIME-Version"}, + {"Header: Organization", HeaderOrganization, "Organization"}, + {"Header: Precedence", HeaderPrecedence, "Precedence"}, + {"Header: Priority", HeaderPriority, "Priority"}, + {"Header: Reply-To", HeaderReplyTo, "Reply-To"}, + {"Header: Subject", HeaderSubject, "Subject"}, + {"Header: User-Agent", HeaderUserAgent, "User-Agent"}, + {"Header: X-Mailer", HeaderXMailer, "X-Mailer"}, + {"Header: X-MSMail-Priority", HeaderXMSMailPriority, "X-MSMail-Priority"}, + {"Header: X-Priority", HeaderXPriority, "X-Priority"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.h.String() != tt.want { + t.Errorf("wrong string for Header returned. Expected: %s, got: %s", + tt.want, tt.h.String()) + } + }) + } +}