Skip to content

Commit

Permalink
Increase plugin test coverage (#663)
Browse files Browse the repository at this point in the history
* add unit tests to plugins
  • Loading branch information
aphralG authored May 3, 2024
1 parent 01ef41d commit 545e0c6
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions internal/plugin/grpc_client_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/nginx/agent/v3/api/grpc/mpi/v1"

"github.com/nginx/agent/v3/test/helpers"
"github.com/nginx/agent/v3/test/protos"

Expand Down Expand Up @@ -155,6 +157,55 @@ func TestGrpcClient_Process_ResourceTopic(t *testing.T) {
assert.True(t, client.isConnected.Load())
}

func TestGrpcClient_ProcessRequest(t *testing.T) {
ctx := context.Background()

agentConfig := types.GetAgentConfig()
client := NewGrpcClient(agentConfig)
pipe := &bus.FakeMessagePipe{}
client.messagePipe = pipe
assert.NotNil(t, client)

tests := []struct {
name string
request *v1.ManagementPlaneRequest
expected *bus.Message
}{
{
name: "Test 1: Config Apply Request",
request: &v1.ManagementPlaneRequest{
Request: &v1.ManagementPlaneRequest_ConfigApplyRequest{
ConfigApplyRequest: &v1.ConfigApplyRequest{
ConfigVersion: protos.CreateConfigVersion(),
},
},
},
expected: &bus.Message{
Topic: bus.InstanceConfigUpdateRequestTopic,
Data: &v1.ManagementPlaneRequest_ConfigApplyRequest{
ConfigApplyRequest: &v1.ConfigApplyRequest{
ConfigVersion: protos.CreateConfigVersion(),
},
},
},
},
{
name: "Test 2: Invalid Request",
request: &v1.ManagementPlaneRequest{
Request: &v1.ManagementPlaneRequest_ActionRequest{},
},
expected: nil,
},
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
client.ProcessRequest(ctx, test.request)
pipe.GetMessages()
})
}
}

func TestGrpcClient_Close(t *testing.T) {
ctx := context.Background()
serverMockLock := sync.Mutex{}
Expand Down

0 comments on commit 545e0c6

Please sign in to comment.