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 {