|
| 1 | +package recorder_mock |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net" |
| 6 | + |
| 7 | + "google.golang.org/grpc" |
| 8 | + |
| 9 | + "github.com/cluttrdev/gitlab-exporter/protobuf/servicepb" |
| 10 | +) |
| 11 | + |
| 12 | +type Recorder struct { |
| 13 | + servicepb.UnimplementedGitLabExporterServer |
| 14 | + |
| 15 | + server *grpc.Server |
| 16 | + datastore *datastore |
| 17 | +} |
| 18 | + |
| 19 | +func New() *Recorder { |
| 20 | + return &Recorder{ |
| 21 | + server: grpc.NewServer(), |
| 22 | + datastore: &datastore{}, |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func (s *Recorder) Datastore() Datastore { |
| 27 | + return s.datastore |
| 28 | +} |
| 29 | + |
| 30 | +func (r *Recorder) Reset() { |
| 31 | + r.datastore = &datastore{} |
| 32 | +} |
| 33 | + |
| 34 | +func (r *Recorder) Serve(lis net.Listener) error { |
| 35 | + servicepb.RegisterGitLabExporterServer(r.server, r) |
| 36 | + return r.server.Serve(lis) |
| 37 | +} |
| 38 | + |
| 39 | +func (r *Recorder) GracefulStop() { |
| 40 | + r.server.GracefulStop() |
| 41 | +} |
| 42 | + |
| 43 | +func (r *Recorder) Stop() { |
| 44 | + r.server.Stop() |
| 45 | +} |
| 46 | + |
| 47 | +func (r *Recorder) RecordPipelines(ctx context.Context, req *servicepb.RecordPipelinesRequest) (*servicepb.RecordSummary, error) { |
| 48 | + r.datastore.pipelines = append(r.datastore.pipelines, req.Data...) |
| 49 | + var count int32 = int32(len(req.Data)) |
| 50 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 51 | +} |
| 52 | + |
| 53 | +func (r *Recorder) RecordJobs(ctx context.Context, req *servicepb.RecordJobsRequest) (*servicepb.RecordSummary, error) { |
| 54 | + r.datastore.jobs = append(r.datastore.jobs, req.Data...) |
| 55 | + var count int32 = int32(len(req.Data)) |
| 56 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 57 | +} |
| 58 | + |
| 59 | +func (r *Recorder) RecordSections(ctx context.Context, req *servicepb.RecordSectionsRequest) (*servicepb.RecordSummary, error) { |
| 60 | + r.datastore.sections = append(r.datastore.sections, req.Data...) |
| 61 | + var count int32 = int32(len(req.Data)) |
| 62 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 63 | +} |
| 64 | + |
| 65 | +func (r *Recorder) RecordBridges(ctx context.Context, req *servicepb.RecordBridgesRequest) (*servicepb.RecordSummary, error) { |
| 66 | + r.datastore.bridges = append(r.datastore.bridges, req.Data...) |
| 67 | + var count int32 = int32(len(req.Data)) |
| 68 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 69 | +} |
| 70 | + |
| 71 | +func (r *Recorder) RecordTraces(ctx context.Context, req *servicepb.RecordTracesRequest) (*servicepb.RecordSummary, error) { |
| 72 | + r.datastore.traces = append(r.datastore.traces, req.Data...) |
| 73 | + var count int32 = int32(len(req.Data)) |
| 74 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 75 | +} |
| 76 | + |
| 77 | +func (r *Recorder) RecordMetrics(ctx context.Context, req *servicepb.RecordMetricsRequest) (*servicepb.RecordSummary, error) { |
| 78 | + r.datastore.metrics = append(r.datastore.metrics, req.Data...) |
| 79 | + var count int32 = int32(len(req.Data)) |
| 80 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 81 | +} |
| 82 | + |
| 83 | +func (r *Recorder) RecordTestReports(ctx context.Context, req *servicepb.RecordTestReportsRequest) (*servicepb.RecordSummary, error) { |
| 84 | + r.datastore.testreports = append(r.datastore.testreports, req.Data...) |
| 85 | + var count int32 = int32(len(req.Data)) |
| 86 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 87 | +} |
| 88 | + |
| 89 | +func (r *Recorder) RecordTestSuites(ctx context.Context, req *servicepb.RecordTestSuitesRequest) (*servicepb.RecordSummary, error) { |
| 90 | + r.datastore.testsuites = append(r.datastore.testsuites, req.Data...) |
| 91 | + var count int32 = int32(len(req.Data)) |
| 92 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 93 | +} |
| 94 | + |
| 95 | +func (r *Recorder) RecordTestCases(ctx context.Context, req *servicepb.RecordTestCasesRequest) (*servicepb.RecordSummary, error) { |
| 96 | + r.datastore.testcases = append(r.datastore.testcases, req.Data...) |
| 97 | + var count int32 = int32(len(req.Data)) |
| 98 | + return &servicepb.RecordSummary{RecordedCount: count}, nil |
| 99 | +} |
0 commit comments