Skip to content

Commit aa857a0

Browse files
committed
add unit tests
1 parent b1d0a6c commit aa857a0

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

api/grpc/mpi/v1/command.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/common.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/resource/resource_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (r *Resource) handleGetStreamUpstreams(ctx context.Context, action *mpi.NGI
236236
correlationID := logger.GetCorrelationID(ctx)
237237
instanceID := instance.GetInstanceMeta().GetInstanceId()
238238

239-
slog.DebugContext(ctx, "Getting Stream Upstreams", "request", action.GetUpdateStreamServers())
239+
slog.DebugContext(ctx, "Getting stream upstreams", "request", action.GetGetStreamUpstreams())
240240

241241
streamUpstreams, err := r.resourceService.GetStreamUpstreams(ctx, instance)
242242
if err != nil {

internal/resource/resource_service_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,42 @@ func TestResourceService_DeleteInstance(t *testing.T) {
147147
}
148148
}
149149

150+
func TestResourceService_Instance(t *testing.T) {
151+
ctx := context.Background()
152+
153+
tests := []struct {
154+
result *v1.Instance
155+
name string
156+
instances []*v1.Instance
157+
}{
158+
{
159+
name: "Test 1: instance found",
160+
instances: []*v1.Instance{
161+
protos.GetNginxOssInstance([]string{}),
162+
protos.GetNginxPlusInstance([]string{}),
163+
},
164+
result: protos.GetNginxPlusInstance([]string{}),
165+
},
166+
{
167+
name: "Test 2: instance not found",
168+
instances: []*v1.Instance{
169+
protos.GetNginxOssInstance([]string{}),
170+
},
171+
result: nil,
172+
},
173+
}
174+
175+
for _, test := range tests {
176+
t.Run(test.name, func(tt *testing.T) {
177+
resourceService := NewResourceService(ctx, types.AgentConfig())
178+
resourceService.resource.Instances = test.instances
179+
instance := resourceService.Instance(protos.GetNginxPlusInstance([]string{}).
180+
GetInstanceMeta().GetInstanceId())
181+
assert.Equal(tt, test.result, instance)
182+
})
183+
}
184+
}
185+
150186
func TestResourceService_GetResource(t *testing.T) {
151187
ctx := context.Background()
152188

0 commit comments

Comments
 (0)