29 lines
803 B
Go
29 lines
803 B
Go
package client
|
||
|
||
import (
|
||
"context"
|
||
"sync"
|
||
|
||
notifPb "github.com/topfans/backend/pkg/proto/notification"
|
||
)
|
||
|
||
// MockNotificationClient 通知客户端 mock(用于测试)
|
||
// 实现 NotificationClientInterface 约定,便于在单元测试中注入。
|
||
type MockNotificationClient struct {
|
||
mu sync.Mutex
|
||
CreateErr error
|
||
CreateCallCount int32
|
||
LastRequest *notifPb.CreateNotificationRequest
|
||
}
|
||
|
||
// CreateNotification 模拟调用
|
||
func (m *MockNotificationClient) CreateNotification(ctx context.Context, req *notifPb.CreateNotificationRequest) (*notifPb.CreateNotificationResponse, error) {
|
||
m.mu.Lock()
|
||
defer m.mu.Unlock()
|
||
m.CreateCallCount++
|
||
m.LastRequest = req
|
||
if m.CreateErr != nil {
|
||
return nil, m.CreateErr
|
||
}
|
||
return ¬ifPb.CreateNotificationResponse{Id: 1}, nil
|
||
} |