@@ -45,6 +45,36 @@ func TestPartEncoding(t *testing.T) {
45
45
}
46
46
}
47
47
48
+ // TestPart_WithPartContentDescription tests the WithPartContentDescription method
49
+ func TestPart_WithPartContentDescription (t * testing.T ) {
50
+ tests := []struct {
51
+ name string
52
+ desc string
53
+ }{
54
+ {"Part description: test" , "test" },
55
+ {"Part description: empty" , "" },
56
+ }
57
+ for _ , tt := range tests {
58
+ m := NewMsg ()
59
+ t .Run (tt .name , func (t * testing.T ) {
60
+ part := m .newPart (TypeTextPlain , WithPartContentDescription (tt .desc ), nil )
61
+ if part == nil {
62
+ t .Errorf ("newPart() WithPartContentDescription() failed: no part returned" )
63
+ return
64
+ }
65
+ if part .desc != tt .desc {
66
+ t .Errorf ("newPart() WithPartContentDescription() failed: expected: %s, got: %s" , tt .desc ,
67
+ part .desc )
68
+ }
69
+ part .desc = ""
70
+ part .SetDescription (tt .desc )
71
+ if part .desc != tt .desc {
72
+ t .Errorf ("newPart() SetDescription() failed: expected: %s, got: %s" , tt .desc , part .desc )
73
+ }
74
+ })
75
+ }
76
+ }
77
+
48
78
// TestPartContentType tests Part.SetContentType
49
79
func TestPart_SetContentType (t * testing.T ) {
50
80
tests := []struct {
@@ -241,6 +271,31 @@ func TestPart_SetContent(t *testing.T) {
241
271
}
242
272
}
243
273
274
+ // TestPart_SetDescription tests Part.SetDescription
275
+ func TestPart_SetDescription (t * testing.T ) {
276
+ c := "This is a test"
277
+ d := "test-description"
278
+ m := NewMsg ()
279
+ m .SetBodyString (TypeTextPlain , c )
280
+ pl , err := getPartList (m )
281
+ if err != nil {
282
+ t .Errorf ("failed: %s" , err )
283
+ return
284
+ }
285
+ pd := pl [0 ].GetDescription ()
286
+ if pd != "" {
287
+ t .Errorf ("Part.GetDescription failed. Expected empty description but got: %s" , pd )
288
+ }
289
+ pl [0 ].SetDescription (d )
290
+ if pl [0 ].desc != d {
291
+ t .Errorf ("Part.SetDescription failed. Expected desc to be: %s, got: %s" , d , pd )
292
+ }
293
+ pd = pl [0 ].GetDescription ()
294
+ if pd != d {
295
+ t .Errorf ("Part.GetDescription failed. Expected: %s, got: %s" , d , pd )
296
+ }
297
+ }
298
+
244
299
// TestPart_Delete tests Part.Delete
245
300
func TestPart_Delete (t * testing.T ) {
246
301
c := "This is a test with ümläutß"
0 commit comments