|
| 1 | +// Copyright (c) F5, Inc. |
| 2 | +// |
| 3 | +// This source code is licensed under the Apache License, Version 2.0 license found in the |
| 4 | +// LICENSE file in the root directory of this source tree. |
| 5 | + |
| 6 | +package file |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "sync/atomic" |
| 11 | + |
| 12 | + mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1" |
| 13 | + "google.golang.org/grpc/metadata" |
| 14 | + "google.golang.org/protobuf/types/known/timestamppb" |
| 15 | +) |
| 16 | + |
| 17 | +type FakeClientStreamingClient struct { |
| 18 | + sendCount atomic.Int32 |
| 19 | +} |
| 20 | + |
| 21 | +func (f *FakeClientStreamingClient) Send(req *mpi.FileDataChunk) error { |
| 22 | + f.sendCount.Add(1) |
| 23 | + return nil |
| 24 | +} |
| 25 | + |
| 26 | +func (f *FakeClientStreamingClient) CloseAndRecv() (*mpi.UpdateFileResponse, error) { |
| 27 | + return &mpi.UpdateFileResponse{}, nil |
| 28 | +} |
| 29 | + |
| 30 | +func (f *FakeClientStreamingClient) Header() (metadata.MD, error) { |
| 31 | + return metadata.MD{}, nil |
| 32 | +} |
| 33 | + |
| 34 | +func (f *FakeClientStreamingClient) Trailer() metadata.MD { |
| 35 | + return nil |
| 36 | +} |
| 37 | + |
| 38 | +func (f *FakeClientStreamingClient) CloseSend() error { |
| 39 | + return nil |
| 40 | +} |
| 41 | + |
| 42 | +func (f *FakeClientStreamingClient) Context() context.Context { |
| 43 | + return context.Background() |
| 44 | +} |
| 45 | + |
| 46 | +func (f *FakeClientStreamingClient) SendMsg(m any) error { |
| 47 | + return nil |
| 48 | +} |
| 49 | + |
| 50 | +func (f *FakeClientStreamingClient) RecvMsg(m any) error { |
| 51 | + return nil |
| 52 | +} |
| 53 | + |
| 54 | +type FakeServerStreamingClient struct { |
| 55 | + chunks map[uint32][]byte |
| 56 | + fileName string |
| 57 | + currentChunkID uint32 |
| 58 | +} |
| 59 | + |
| 60 | +func (f *FakeServerStreamingClient) Recv() (*mpi.FileDataChunk, error) { |
| 61 | + fileDataChunk := &mpi.FileDataChunk{ |
| 62 | + Meta: &mpi.MessageMeta{ |
| 63 | + MessageId: "123", |
| 64 | + CorrelationId: "1234", |
| 65 | + Timestamp: timestamppb.Now(), |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + if f.currentChunkID == 0 { |
| 70 | + fileDataChunk.Chunk = &mpi.FileDataChunk_Header{ |
| 71 | + Header: &mpi.FileDataChunkHeader{ |
| 72 | + FileMeta: &mpi.FileMeta{ |
| 73 | + Name: f.fileName, |
| 74 | + Permissions: "666", |
| 75 | + }, |
| 76 | + Chunks: 52, |
| 77 | + ChunkSize: 1, |
| 78 | + }, |
| 79 | + } |
| 80 | + } else { |
| 81 | + fileDataChunk.Chunk = &mpi.FileDataChunk_Content{ |
| 82 | + Content: &mpi.FileDataChunkContent{ |
| 83 | + ChunkId: f.currentChunkID, |
| 84 | + Data: f.chunks[f.currentChunkID-1], |
| 85 | + }, |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + f.currentChunkID++ |
| 90 | + |
| 91 | + return fileDataChunk, nil |
| 92 | +} |
| 93 | + |
| 94 | +func (f *FakeServerStreamingClient) Header() (metadata.MD, error) { |
| 95 | + return metadata.MD{}, nil |
| 96 | +} |
| 97 | + |
| 98 | +func (f *FakeServerStreamingClient) Trailer() metadata.MD { |
| 99 | + return metadata.MD{} |
| 100 | +} |
| 101 | + |
| 102 | +func (f *FakeServerStreamingClient) CloseSend() error { |
| 103 | + return nil |
| 104 | +} |
| 105 | + |
| 106 | +func (f *FakeServerStreamingClient) Context() context.Context { |
| 107 | + return context.Background() |
| 108 | +} |
| 109 | + |
| 110 | +func (f *FakeServerStreamingClient) SendMsg(m any) error { |
| 111 | + return nil |
| 112 | +} |
| 113 | + |
| 114 | +func (f *FakeServerStreamingClient) RecvMsg(m any) error { |
| 115 | + return nil |
| 116 | +} |
0 commit comments