package leaf import ( "testing" "github.com/stretchr/testify/assert" "go.mongodb.org/mongo-driver/bson/primitive" ) func TestObjectIDFromHex(t *testing.T) { t.Run("valid hex", func(t *testing.T) { hex := "507f1f77bcf86cd799439011" id, err := primitive.ObjectIDFromHex(hex) assert.NoError(t, err) assert.Equal(t, id, ObjectIDFromHex(hex)) }) t.Run("invalid hex", func(t *testing.T) { hex := "invalidhex" assert.Equal(t, primitive.NilObjectID, ObjectIDFromHex(hex)) }) } func TestObjectIDFromHexSlice(t *testing.T) { t.Run("valid hex slice", func(t *testing.T) { hex := []string{"507f1f77bcf86cd799439011", "507f1f77bcf86cd799439012"} ids := make([]primitive.ObjectID, len(hex)) for i := range hex { ids[i], _ = primitive.ObjectIDFromHex(hex[i]) } assert.Equal(t, ids, ObjectIDFromHexSlice(hex)) }) t.Run("invalid hex slice", func(t *testing.T) { hex := []string{"invalidhex", "invalidhex"} assert.Equal(t, []primitive.ObjectID{primitive.NilObjectID, primitive.NilObjectID}, ObjectIDFromHexSlice(hex)) }) }