Skip to content

Commit 08dcc1a

Browse files
refactor: remove the helper function and mocks for http server
1 parent 9c287b0 commit 08dcc1a

2 files changed

Lines changed: 5 additions & 30 deletions

File tree

app/server_test.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ import (
1717
func TestShutDownServer(t *testing.T) {
1818
ctx, cancel := context.WithCancel(context.Background())
1919
defer cancel()
20-
mockSvc := &mockService{}
21-
mockServices := services.New(mockSvc)
2220
mockKafka := &mockKafkaClient{}
21+
2322
kp := publisher.NewKafkaFromClient(mockKafka, 50, "test")
2423

2524
shutdownCh := make(chan bool, 1)
2625
bufferCh := make(chan collection.CollectRequest, 1)
2726

27+
services := services.Create(bufferCh, ctx)
28+
2829
wp := worker.CreateWorkerPool(1, bufferCh, 1, kp)
2930

3031
// run shutdown in background
3132
sigCh := make(chan os.Signal, 1)
32-
go shutDownServer(ctx, cancel, mockServices, bufferCh, wp, kp, shutdownCh, sigCh)
33+
go shutDownServer(ctx, cancel, services, bufferCh, wp, kp, shutdownCh, sigCh)
3334

3435
// send a termination signal after short delay
3536
go func() {
@@ -44,11 +45,8 @@ func TestShutDownServer(t *testing.T) {
4445
t.Error("shutdown execution failed")
4546
}
4647

47-
if !mockSvc.shutdownCalled {
48-
t.Errorf("expected httpServices.Shutdown to be called")
49-
}
5048
if !isClosed(bufferCh) {
51-
t.Errorf("expected shutdown channel to be closed")
49+
t.Errorf("expected buffer channel to be closed")
5250
}
5351
if !mockKafka.FlushCalled {
5452
t.Errorf("expected Kafka.FlushCalled to be called")
@@ -68,24 +66,6 @@ func isClosed(ch <-chan collection.CollectRequest) bool {
6866
}
6967

7068
// ---- Mocks ----
71-
// mockKafkaClient is a mock for the Client interface
72-
type mockService struct {
73-
shutdownCalled bool
74-
}
75-
76-
func (m *mockService) Init(context.Context) error {
77-
return nil
78-
}
79-
80-
func (*mockService) Name() string {
81-
return "mock server"
82-
}
83-
84-
func (m *mockService) Shutdown(ctx context.Context) error {
85-
m.shutdownCalled = true
86-
return nil
87-
}
88-
8969
// mockKafkaClient is a mock for the Client interface
9070
type mockKafkaClient struct {
9171
// Tracking flags

services/services.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,3 @@ func Create(b chan collection.CollectRequest, ctx context.Context) Services {
5353
},
5454
}
5555
}
56-
57-
// New creates a Services with custom bootstrappers (for testing/mocking).
58-
func New(service bootstrapper) Services {
59-
return Services{b: []bootstrapper{service}}
60-
}

0 commit comments

Comments
 (0)