@@ -1601,6 +1601,67 @@ func TestMsg_Subject(t *testing.T) {
16011601 }
16021602}
16031603
1604+ func TestMsg_SetMessageID (t * testing.T ) {
1605+ t .Run ("SetMessageID randomness" , func (t * testing.T ) {
1606+ var mids []string
1607+ message := NewMsg ()
1608+ if message == nil {
1609+ t .Fatal ("message is nil" )
1610+ }
1611+ for i := 0 ; i < 50_000 ; i ++ {
1612+ message .SetMessageID ()
1613+ mid := message .GetMessageID ()
1614+ mids = append (mids , mid )
1615+ }
1616+ c := make (map [string ]int )
1617+ for i := range mids {
1618+ c [mids [i ]]++
1619+ }
1620+ for k , v := range c {
1621+ if v > 1 {
1622+ t .Errorf ("MessageID randomness not given. MessageID %q was generated %d times" , k , v )
1623+ }
1624+ }
1625+ })
1626+ }
1627+ func TestMsg_GetMessageID (t * testing.T ) {
1628+ t .Run ("GetMessageID with normal IDs" , func (t * testing.T ) {
1629+ tests := []struct {
1630+ msgid string
1631+ want string
1632+ }{
1633+ {"this.is.a.test" , "<this.is.a.test>" },
1634+ 1635+ 1636+ 1637+ 1638+ }
1639+ for _ , tt := range tests {
1640+ t .Run (tt .msgid , func (t * testing.T ) {
1641+ message := NewMsg ()
1642+ if message == nil {
1643+ t .Fatal ("message is nil" )
1644+ }
1645+ message .SetMessageIDWithValue (tt .msgid )
1646+ msgid := message .GetMessageID ()
1647+ if ! strings .EqualFold (tt .want , msgid ) {
1648+ t .Errorf ("GetMessageID() failed. Want: %s, got: %s" , tt .want , msgid )
1649+ }
1650+ })
1651+ }
1652+ })
1653+ t .Run ("GetMessageID no messageID set should return an empty string" , func (t * testing.T ) {
1654+ message := NewMsg ()
1655+ if message == nil {
1656+ t .Fatal ("message is nil" )
1657+ }
1658+ msgid := message .GetMessageID ()
1659+ if msgid != "" {
1660+ t .Errorf ("GetMessageID() failed. Want: empty string, got: %s" , msgid )
1661+ }
1662+ })
1663+ }
1664+
16041665// checkAddrHeader verifies the correctness of an AddrHeader in a Msg based on the provided criteria.
16051666// It checks whether the AddrHeader contains the correct address, name, and number of fields.
16061667func checkAddrHeader (t * testing.T , message * Msg , header AddrHeader , fn string , field , wantFields int ,
0 commit comments