Files
NixMsg/internal/app/port/stub.go
T

41 lines
1.1 KiB
Go

package port
import "context"
// StubDownlink 吞掉所有下行发布。
type StubDownlink struct {
Published int
}
func (s *StubDownlink) PublishDown(_ context.Context, _ string, _ ConnID, _ []byte, _ PublishOpts) error {
s.Published++
return nil
}
// StubConnControl 记录断开请求。
type StubConnControl struct {
Calls []string
}
func (s *StubConnControl) Disconnect(_ context.Context, endpointID string, _ ConnID, _ DisconnectReason) error {
s.Calls = append(s.Calls, endpointID)
return nil
}
// StubUplinkHandler 空实现,供 broker 接线测试。
type StubUplinkHandler struct{}
func (StubUplinkHandler) OnSessionEstablished(context.Context, ConnInfo) error { return nil }
func (StubUplinkHandler) OnHandshakeComplete(context.Context, HandshakeInfo) error { return nil }
func (StubUplinkHandler) OnDisconnect(context.Context, ConnInfo, DisconnectReason) {}
func (StubUplinkHandler) HandleUplink(context.Context, ConnInfo, []byte) error { return nil }
var (
_ Downlink = (*StubDownlink)(nil)
_ ConnControl = (*StubConnControl)(nil)
_ UplinkHandler = StubUplinkHandler{}
)