Skip to content

Commit e1aac81

Browse files
committed
Add more unit tests to UpdateOverview
1 parent c5ff4bc commit e1aac81

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

internal/controller/nginx/agent/file_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,100 @@ func TestUpdateOverview(t *testing.T) {
441441
g.Expect(resp).To(Equal(&pb.UpdateOverviewResponse{}))
442442
}
443443

444+
func TestUpdateOverview_InvalidConnection(t *testing.T) {
445+
t.Parallel()
446+
g := NewWithT(t)
447+
448+
fs := newFileService(logr.Discard(), nil, nil)
449+
450+
req := &pb.UpdateOverviewRequest{
451+
Overview: &pb.FileOverview{
452+
Files: []*pb.File{
453+
{
454+
FileMeta: &pb.FileMeta{
455+
Name: "nginx.conf",
456+
Hash: "abc123",
457+
},
458+
},
459+
},
460+
},
461+
}
462+
463+
// Use regular context without GrpcInfo to trigger invalid connection
464+
resp, err := fs.UpdateOverview(t.Context(), req)
465+
466+
g.Expect(err).To(Equal(agentgrpc.ErrStatusInvalidConnection))
467+
g.Expect(resp).To(Equal(&pb.UpdateOverviewResponse{}))
468+
}
469+
470+
func TestUpdateOverview_ConnectionNotFound(t *testing.T) {
471+
t.Parallel()
472+
g := NewWithT(t)
473+
474+
fs := newFileService(logr.Discard(), nil, &agentgrpcfakes.FakeConnectionsTracker{})
475+
476+
req := &pb.UpdateOverviewRequest{
477+
Overview: &pb.FileOverview{
478+
Files: []*pb.File{
479+
{
480+
FileMeta: &pb.FileMeta{
481+
Name: "nginx.conf",
482+
Hash: "abc123",
483+
},
484+
},
485+
},
486+
},
487+
}
488+
489+
ctx := grpcContext.NewGrpcContext(t.Context(), grpcContext.GrpcInfo{
490+
IPAddress: "127.0.0.1",
491+
})
492+
493+
resp, err := fs.UpdateOverview(ctx, req)
494+
495+
g.Expect(err).To(Equal(status.Errorf(codes.NotFound, "connection not found")))
496+
g.Expect(resp).To(Equal(&pb.UpdateOverviewResponse{}))
497+
}
498+
499+
func TestUpdateOverview_DeploymentNotFound(t *testing.T) {
500+
t.Parallel()
501+
g := NewWithT(t)
502+
503+
deploymentName := types.NamespacedName{Name: "nginx-deployment", Namespace: "default"}
504+
505+
connTracker := &agentgrpcfakes.FakeConnectionsTracker{}
506+
conn := agentgrpc.Connection{
507+
PodName: "nginx-pod",
508+
InstanceID: "12345",
509+
Parent: deploymentName,
510+
}
511+
connTracker.GetConnectionReturns(conn)
512+
513+
fs := newFileService(logr.Discard(), NewDeploymentStore(connTracker), connTracker)
514+
515+
req := &pb.UpdateOverviewRequest{
516+
Overview: &pb.FileOverview{
517+
Files: []*pb.File{
518+
{
519+
FileMeta: &pb.FileMeta{
520+
Name: "nginx.conf",
521+
Hash: "abc123",
522+
},
523+
},
524+
},
525+
},
526+
}
527+
528+
ctx := grpcContext.NewGrpcContext(t.Context(), grpcContext.GrpcInfo{
529+
IPAddress: "127.0.0.1",
530+
})
531+
532+
resp, err := fs.UpdateOverview(ctx, req)
533+
534+
g.Expect(err).To(Equal(status.Errorf(codes.NotFound, "deployment not found in store")))
535+
g.Expect(resp).To(Equal(&pb.UpdateOverviewResponse{}))
536+
}
537+
444538
func TestUpdateFile(t *testing.T) {
445539
t.Parallel()
446540
g := NewWithT(t)

0 commit comments

Comments
 (0)