Skip to content

Commit 19b46a2

Browse files
Expose FakeSetup with created bindings
This allows FakeSetup to be passed into functions.
1 parent 68dfbe5 commit 19b46a2

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v0.0.51 Allow passing of Test Clients
4+
- Introduces `FakeSetup`, which allows for passing TestClients along.
5+
36
## v0.0.47 Fix accessing OrderingKey
47
**Bugfixes**
58
- Corrects implementation of function `ApplyCloudEventsPubSubOrderingKey`

pkg/gcp/services.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"cloud.google.com/go/errorreporting"
99
"cloud.google.com/go/logging"
10+
"cloud.google.com/go/pubsub"
1011
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
1112
"github.com/otto-de/sherlock-microservice/pkg/gke"
1213
"go.opentelemetry.io/otel/sdk/resource"
@@ -16,9 +17,11 @@ import (
1617

1718
// Services contains all Google Cloud Services that
1819
// we use
20+
// TODO: Spit non-Services to another struct
1921
type Services struct {
2022
Logging *logging.Client
2123
ErrorReporting *errorreporting.Client
24+
PubSub *pubsub.Client
2225
TracerProvider *sdktrace.TracerProvider
2326
MonitoredResource *monitoredres.MonitoredResource
2427
}
@@ -146,6 +149,7 @@ func DiscoverServices(project, serviceName string, tracerProviderOptions []sdktr
146149
// Does **not** handle errors in close since there usually
147150
// is not much that can be done on Close failure anyway.
148151
func (s *Services) Close() {
152+
s.PubSub.Close()
149153
s.TracerProvider.ForceFlush(context.Background()) // flushes any pending spans
150154
s.ErrorReporting.Close()
151155
s.Logging.Close()

pkg/gcp/test/test.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ import (
1717
"google.golang.org/grpc/credentials/insecure"
1818
)
1919

20+
type fakeServers struct {
21+
PubSub *pstest.Server
22+
}
23+
type FakeSetup struct {
24+
Servers fakeServers
25+
Services gcp.Services
26+
}
27+
2028
type server struct {
21-
gcp.Services
22-
PubSub *pubsub.Client
23-
PubSubServer *pstest.Server
29+
FakeSetup
2430

2531
listener net.Listener
2632
grpcServer *grpc.Server
@@ -124,13 +130,17 @@ func MustMakeTestServices(ctx context.Context, project, serviceName string, opts
124130
}()
125131

126132
return &server{
127-
Services: gcp.Services{
128-
ErrorReporting: errRep,
129-
Logging: lc,
130-
TracerProvider: tp,
133+
FakeSetup: FakeSetup{
134+
Servers: fakeServers{
135+
PubSub: psServer,
136+
},
137+
Services: gcp.Services{
138+
TracerProvider: tp,
139+
ErrorReporting: errRep,
140+
Logging: lc,
141+
PubSub: pubSub,
142+
},
131143
},
132-
PubSub: pubSub,
133-
PubSubServer: psServer,
134144
fes: fes,
135145
grpcServer: grpcServer,
136146
listener: l,
@@ -141,10 +151,9 @@ func MustMakeTestServices(ctx context.Context, project, serviceName string, opts
141151
func (s *server) Close() error {
142152
// Ignore close errors because usually
143153
// we are not that particular about testing
144-
s.PubSub.Close()
145154
s.Services.Close()
146155
s.grpcServer.GracefulStop()
147-
s.PubSubServer.Close()
156+
s.Servers.PubSub.Close()
148157
s.psServerConn.Close()
149158
s.listener.Close()
150159
return nil

0 commit comments

Comments
 (0)