github.com/openimsdk/tools@v0.0.49/utils/idutil/id_generator_test.go (about)

     1  package idutil
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  // TestGetMsgIDByMD5 checks if GetMsgIDByMD5 returns a valid MD5 hash string.
    11  func TestGetMsgIDByMD5(t *testing.T) {
    12  	sendID := "12345"
    13  	msgID := GetMsgIDByMD5(sendID)
    14  
    15  	// MD5 hash is a 32 character hexadecimal number.
    16  	assert.Regexp(t, regexp.MustCompile("^[a-fA-F0-9]{32}$"), msgID, "The returned msgID should be a valid MD5 hash")
    17  }
    18  
    19  // TestOperationIDGenerator checks if OperationIDGenerator returns a string that looks like a valid operation ID.
    20  func TestOperationIDGenerator(t *testing.T) {
    21  	opID := OperationIDGenerator()
    22  
    23  	// The operation ID should be a long number (timestamp + random number).
    24  	// Just check if it is numeric and has a reasonable length.
    25  	assert.Regexp(t, regexp.MustCompile("^[0-9]{13,}$"), opID, "The returned operation ID should be numeric and long")
    26  }