From 6ea09741568843aa751680d165739d3a267349e9 Mon Sep 17 00:00:00 2001 From: theexiile1305 Date: Wed, 9 Oct 2024 14:43:43 +0200 Subject: [PATCH] feat: improved tests --- encoding.go | 5 +++++ encoding_test.go | 21 +++++++++++++++++++++ util_test.go | 1 + 3 files changed, 27 insertions(+) diff --git a/encoding.go b/encoding.go index dbe57ee..4be2e38 100644 --- a/encoding.go +++ b/encoding.go @@ -174,3 +174,8 @@ func (c ContentType) String() string { func (e Encoding) String() string { return string(e) } + +// String is a standard method to convert an MIMEType into a printable format +func (e MIMEType) String() string { + return string(e) +} diff --git a/encoding_test.go b/encoding_test.go index 11bf991..4c7778a 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -126,3 +126,24 @@ func TestCharset_String(t *testing.T) { }) } } + +// TestContentType_String tests the mime type method of the MIMEType object +func TestMimeType_String(t *testing.T) { + tests := []struct { + mt MIMEType + want string + }{ + {MIMEAlternative, "alternative"}, + {MIMEMixed, "mixed"}, + {MIMERelated, "related"}, + {MIMESMime, `signed; protocol="application/pkcs7-signature"; micalg=sha-256`}, + } + for _, tt := range tests { + t.Run(tt.mt.String(), func(t *testing.T) { + if tt.mt.String() != tt.want { + t.Errorf("wrong string for mime type returned. Expected: %s, got: %s", + tt.want, tt.mt.String()) + } + }) + } +} diff --git a/util_test.go b/util_test.go index 47bac43..7c54b7d 100644 --- a/util_test.go +++ b/util_test.go @@ -10,6 +10,7 @@ const ( keyFilePath = "dummy-child-key.pem" ) +// getDummyCertificate loads a certificate and a private key form local disk for testing purposes func getDummyCertificate() (*tls.Certificate, error) { keyPair, err := tls.LoadX509KeyPair(certFilePath, keyFilePath) if err != nil {