Skip to content

Commit

Permalink
Introduce WithErrorReportChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBergmeier6176 committed Nov 8, 2023
1 parent e5d77ac commit 0b60926
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.0.36 Ease for ErrorReporting
- Add WithErrorReportChannel for testing Services.

## v0.0.34 Ease testing of PubSub
- Add function `gcp.pubsubcmp.DiffMessages`.

Expand Down
9 changes: 4 additions & 5 deletions pkg/gcp/test/errorreporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test

import (
"context"
"testing"

"cloud.google.com/go/errorreporting/apiv1beta1/errorreportingpb"
)
Expand All @@ -12,13 +11,13 @@ var (
)

type fakeErrorreportingServer struct {
tForFailOnEvent *testing.T
ReportedEvents []*errorreportingpb.ReportedErrorEvent
c chan<- *errorreportingpb.ReportedErrorEvent
ReportedEvents []*errorreportingpb.ReportedErrorEvent
}

func (s *fakeErrorreportingServer) ReportErrorEvent(ctx context.Context, req *errorreportingpb.ReportErrorEventRequest) (*errorreportingpb.ReportErrorEventResponse, error) {
if s.tForFailOnEvent != nil {
s.tForFailOnEvent.Fatal("Unexpected ErrorEvent reported:", req.Event)
if s.c != nil {
s.c <- req.Event
}
s.ReportedEvents = append(s.ReportedEvents, req.Event)
return &errorreportingpb.ReportErrorEventResponse{}, nil
Expand Down
13 changes: 6 additions & 7 deletions pkg/gcp/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package test
import (
"context"
"net"
"testing"

"cloud.google.com/go/errorreporting"
"cloud.google.com/go/errorreporting/apiv1beta1/errorreportingpb"
Expand All @@ -30,22 +29,22 @@ type server struct {
}

type testServicesOption struct {
failOnErrorReports bool
c chan<- *errorreportingpb.ReportedErrorEvent
}

func WithFailOnErrorReports() testServicesOption {
func WithErrorReportChannel(evs chan<- *errorreportingpb.ReportedErrorEvent) testServicesOption {
return testServicesOption{
failOnErrorReports: true,
c: evs,
}
}

func MustMakeTestServices(t *testing.T, ctx context.Context, project, serviceName string, opts ...testServicesOption) *server {
func MustMakeTestServices(ctx context.Context, project, serviceName string, opts ...testServicesOption) *server {

var fes *fakeErrorreportingServer
for _, opt := range opts {
if opt.failOnErrorReports {
if opt.c != nil {
fes = &fakeErrorreportingServer{
tForFailOnEvent: t,
c: opt.c,
}
}
}
Expand Down

0 comments on commit 0b60926

Please sign in to comment.