Skip to content

Commit 0bfa34f

Browse files
committed
add unit tests
1 parent b98b24b commit 0bfa34f

File tree

6 files changed

+35
-98
lines changed

6 files changed

+35
-98
lines changed

internal/command/command_plugin.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ func (cp *CommandPlugin) processConnectionReset(ctx context.Context, msg *bus.Me
189189
}
190190
cp.conn = newConnection
191191
cp.commandService.UpdateClient(cp.conn.CommandServiceClient())
192-
//go cp.monitorSubscribeChannel(ctx)
193-
//cp.createConnection(ctx, cp.commandService.Resource())
194192
slog.DebugContext(ctx, "Command plugin: client reset successfully")
195193
}
196194
}

internal/command/command_plugin_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func TestCommandPlugin_Process(t *testing.T) {
143143
})
144144
require.Equal(t, 1, fakeCommandService.UpdateDataPlaneHealthCallCount())
145145
require.Equal(t, 1, fakeCommandService.SendDataPlaneResponseCallCount())
146+
147+
commandPlugin.Process(ctx, &bus.Message{Topic: bus.ConnectionResetTopic, Data: &protos.)
148+
require.Equal(t, 1, fakeCommandService.UpdateClientCallCount())
146149
}
147150

148151
func TestCommandPlugin_monitorSubscribeChannel(t *testing.T) {

internal/command/command_service_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ func TestCommandService_CreateConnection(t *testing.T) {
198198
require.NoError(t, err)
199199
}
200200

201+
func TestCommandService_UpdateClient(t *testing.T) {
202+
//ctx := context.Background()
203+
commandServiceClient := &v1fakes.FakeCommandServiceClient{}
204+
205+
commandService := NewCommandService(
206+
commandServiceClient,
207+
types.AgentConfig(),
208+
make(chan *mpi.ManagementPlaneRequest),
209+
)
210+
assert.False(t, commandService.clientUpdated.Load())
211+
commandService.UpdateClient(commandServiceClient)
212+
assert.True(t, commandService.clientUpdated.Load())
213+
}
214+
201215
func TestCommandService_UpdateDataPlaneHealth(t *testing.T) {
202216
ctx := context.Background()
203217
commandServiceClient := &v1fakes.FakeCommandServiceClient{}

internal/grpc/grpc.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type (
4141
CommandServiceClient() mpi.CommandServiceClient
4242
FileServiceClient() mpi.FileServiceClient
4343
Close(ctx context.Context) error
44-
Restart(ctx context.Context) (*GrpcConnection, error)
4544
}
4645

4746
GrpcConnection struct {
@@ -132,22 +131,6 @@ func (gc *GrpcConnection) Close(ctx context.Context) error {
132131
return nil
133132
}
134133

135-
func (gc *GrpcConnection) Restart(ctx context.Context) (*GrpcConnection, error) {
136-
slog.InfoContext(ctx, "Restarting grpc connection")
137-
err := gc.Close(ctx)
138-
if err != nil {
139-
return nil, err
140-
}
141-
142-
slog.InfoContext(ctx, "Creating grpc connection")
143-
newConn, err := NewGrpcConnection(ctx, gc.config)
144-
if err != nil {
145-
return nil, err
146-
}
147-
148-
return newConn, nil
149-
}
150-
151134
func (w *wrappedStream) RecvMsg(message any) error {
152135
err := w.ClientStream.RecvMsg(message)
153136
if err == nil {

internal/grpc/grpcfakes/fake_grpc_connection_interface.go

Lines changed: 0 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/watcher/watcher_plugin_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ func TestWatcher_Info(t *testing.T) {
120120
assert.Equal(t, &bus.Info{Name: "watcher"}, watcherPlugin.Info())
121121
}
122122

123+
func TestWatcher_Process_CredentialUpdatedTopic(t *testing.T) {
124+
ctx := context.Background()
125+
126+
watcherPlugin := NewWatcher(types.AgentConfig())
127+
128+
messagePipe := busfakes.NewFakeMessagePipe()
129+
130+
err := watcherPlugin.Init(ctx, messagePipe)
131+
require.NoError(t, err)
132+
133+
message := &bus.Message{
134+
Topic: bus.CredentialUpdatedTopic,
135+
Data: nil,
136+
}
137+
138+
watcherPlugin.Process(ctx, message)
139+
}
140+
123141
func TestWatcher_Process_ConfigApplyRequestTopic(t *testing.T) {
124142
ctx := context.Background()
125143
data := &mpi.ManagementPlaneRequest{

0 commit comments

Comments
 (0)