AdGuardDNS/internal/backendpb/backendpb_test.go

104 lines
3.0 KiB
Go
Raw Normal View History

2023-09-06 08:22:07 +03:00
package backendpb_test
2024-07-10 19:49:07 +03:00
import (
"context"
"time"
"github.com/AdguardTeam/AdGuardDNS/internal/backendpb"
2024-10-14 17:44:24 +03:00
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
2024-07-10 19:49:07 +03:00
)
// testTimeout is the common timeout for tests.
const testTimeout = 1 * time.Second
2023-09-06 08:22:07 +03:00
// testDNSServiceServer is the [backendpb.DNSServiceServer] for tests.
//
// TODO(d.kolyshev): Use this to remove as much as possible from the internal
// test.
type testDNSServiceServer struct {
backendpb.UnimplementedDNSServiceServer
2024-07-10 19:49:07 +03:00
//lint:ignore ST1003 Keep in sync with the generated code.
OnCreateDeviceByHumanId func(
ctx context.Context,
req *backendpb.CreateDeviceRequest,
) (resp *backendpb.CreateDeviceResponse, err error)
2023-09-06 08:22:07 +03:00
OnGetDNSProfiles func(
req *backendpb.DNSProfilesRequest,
2024-10-14 17:44:24 +03:00
srv grpc.ServerStreamingServer[backendpb.DNSProfile],
2023-09-06 08:22:07 +03:00
) (err error)
2024-07-10 19:49:07 +03:00
2023-09-06 08:22:07 +03:00
OnSaveDevicesBillingStat func(
2024-10-14 17:44:24 +03:00
srv grpc.ClientStreamingServer[backendpb.DeviceBillingStat, emptypb.Empty],
2023-09-06 08:22:07 +03:00
) (err error)
}
// type check
var _ backendpb.DNSServiceServer = (*testDNSServiceServer)(nil)
2024-07-10 19:49:07 +03:00
// CreateDeviceByHumanId implements the [backendpb.DNSServiceServer] interface
// for *testDNSServiceServer.
//
//lint:ignore ST1003 Keep in sync with the generated code.
func (s *testDNSServiceServer) CreateDeviceByHumanId(
ctx context.Context,
req *backendpb.CreateDeviceRequest,
) (resp *backendpb.CreateDeviceResponse, err error) {
return s.OnCreateDeviceByHumanId(ctx, req)
}
2023-09-06 08:22:07 +03:00
// GetDNSProfiles implements the [backendpb.DNSServiceServer] interface for
// *testDNSServiceServer
func (s *testDNSServiceServer) GetDNSProfiles(
req *backendpb.DNSProfilesRequest,
2024-10-14 17:44:24 +03:00
srv grpc.ServerStreamingServer[backendpb.DNSProfile],
2023-09-06 08:22:07 +03:00
) (err error) {
return s.OnGetDNSProfiles(req, srv)
}
// SaveDevicesBillingStat implements the [backendpb.DNSServiceServer] interface
// for *testDNSServiceServer
func (s *testDNSServiceServer) SaveDevicesBillingStat(
2024-10-14 17:44:24 +03:00
srv grpc.ClientStreamingServer[backendpb.DeviceBillingStat, emptypb.Empty],
2023-09-06 08:22:07 +03:00
) (err error) {
return s.OnSaveDevicesBillingStat(srv)
}
2024-11-08 16:26:22 +03:00
// testRemoteKVServiceServer is the [backendpb.RemoteKVServiceServer] for tests.
type testRemoteKVServiceServer struct {
backendpb.UnimplementedRemoteKVServiceServer
OnGet func(
ctx context.Context,
req *backendpb.RemoteKVGetRequest,
) (resp *backendpb.RemoteKVGetResponse, err error)
OnSet func(
ctx context.Context,
req *backendpb.RemoteKVSetRequest,
) (resp *backendpb.RemoteKVSetResponse, err error)
}
// type check
var _ backendpb.RemoteKVServiceServer = (*testRemoteKVServiceServer)(nil)
// Get implements the [backendpb.RemoteKVServiceServer] interface for
// *testRemoteKVServiceServer.
func (s *testRemoteKVServiceServer) Get(
ctx context.Context,
req *backendpb.RemoteKVGetRequest,
) (resp *backendpb.RemoteKVGetResponse, err error) {
return s.OnGet(ctx, req)
}
// Set implements the [backendpb.RemoteKVServiceServer] interface for
// *testRemoteKVServiceServer.
func (s *testRemoteKVServiceServer) Set(
ctx context.Context,
req *backendpb.RemoteKVSetRequest,
) (resp *backendpb.RemoteKVSetResponse, err error) {
return s.OnSet(ctx, req)
}