Skip to content

Commit 6c0e358

Browse files
committed
fix(client): adapt to regenerated stream bindings
Use the named MaliceRPC_SyncStreamClient interface and record the new artifact RPCs.
1 parent 52ddfe5 commit 6c0e358

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

client/command/context/context_command_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99

1010
"github.com/chainreactors/IoM-go/consts"
1111
"github.com/chainreactors/IoM-go/proto/client/clientpb"
12+
"github.com/chainreactors/IoM-go/proto/services/clientrpc"
1213
"github.com/chainreactors/malice-network/client/assets"
1314
"github.com/chainreactors/malice-network/client/command/testsupport"
1415
"github.com/chainreactors/malice-network/helper/utils/output"
15-
"google.golang.org/grpc"
1616
)
1717

1818
func TestContextCommandConformance(t *testing.T) {
@@ -42,7 +42,7 @@ func TestContextCommandConformance(t *testing.T) {
4242
Argv: []string{consts.CommandSync, "ctx-1"},
4343
WantErr: "sync context failed",
4444
Setup: func(t testing.TB, h *testsupport.Harness) {
45-
h.Recorder.OnContextStream("SyncStream", func(ctx context.Context, request any) (grpc.ServerStreamingClient[clientpb.ContextChunk], error) {
45+
h.Recorder.OnContextStream("SyncStream", func(ctx context.Context, request any) (clientrpc.MaliceRPC_SyncStreamClient, error) {
4646
return nil, context.DeadlineExceeded
4747
})
4848
},
@@ -58,7 +58,7 @@ func TestContextCommandConformance(t *testing.T) {
5858
Name: "sync streams file-backed context content",
5959
Argv: []string{consts.CommandSync, "ctx-1"},
6060
Setup: func(t testing.TB, h *testsupport.Harness) {
61-
h.Recorder.OnContextStream("SyncStream", func(ctx context.Context, request any) (grpc.ServerStreamingClient[clientpb.ContextChunk], error) {
61+
h.Recorder.OnContextStream("SyncStream", func(ctx context.Context, request any) (clientrpc.MaliceRPC_SyncStreamClient, error) {
6262
header := &clientpb.Context{
6363
Id: "ctx-1",
6464
Type: consts.ContextDownload,
@@ -119,7 +119,7 @@ func TestContextCommandConformance(t *testing.T) {
119119
Argv: []string{consts.CommandSync, "ctx-1"},
120120
WantErr: "unexpected stream offset",
121121
Setup: func(t testing.TB, h *testsupport.Harness) {
122-
h.Recorder.OnContextStream("SyncStream", func(ctx context.Context, request any) (grpc.ServerStreamingClient[clientpb.ContextChunk], error) {
122+
h.Recorder.OnContextStream("SyncStream", func(ctx context.Context, request any) (clientrpc.MaliceRPC_SyncStreamClient, error) {
123123
header := downloadContext("ctx-1", "broken.bin", nil)
124124
return contextChunkStream(
125125
&clientpb.ContextChunk{Header: header, TotalSize: 4},
@@ -137,7 +137,7 @@ func TestContextCommandConformance(t *testing.T) {
137137
})
138138
}
139139

140-
func contextChunkStream(chunks ...*clientpb.ContextChunk) grpc.ServerStreamingClient[clientpb.ContextChunk] {
140+
func contextChunkStream(chunks ...*clientpb.ContextChunk) clientrpc.MaliceRPC_SyncStreamClient {
141141
index := 0
142142
return &testsupport.ContextChunkStream{RecvFunc: func() (*clientpb.ContextChunk, error) {
143143
if index == len(chunks) {

client/command/context/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"path/filepath"
99

1010
"github.com/chainreactors/IoM-go/proto/client/clientpb"
11+
"github.com/chainreactors/IoM-go/proto/services/clientrpc"
1112
"github.com/chainreactors/malice-network/client/assets"
1213
"github.com/chainreactors/malice-network/client/core"
1314
"github.com/chainreactors/malice-network/helper/utils/fileutils"
1415
"github.com/chainreactors/malice-network/helper/utils/output"
1516
"github.com/spf13/cobra"
16-
"google.golang.org/grpc"
1717
"google.golang.org/grpc/codes"
1818
"google.golang.org/grpc/status"
1919
)
@@ -67,7 +67,7 @@ func syncContextUnary(con *core.Console, req *clientpb.Sync) error {
6767
return nil
6868
}
6969

70-
func receiveContextStream(con *core.Console, stream grpc.ServerStreamingClient[clientpb.ContextChunk]) error {
70+
func receiveContextStream(con *core.Console, stream clientrpc.MaliceRPC_SyncStreamClient) error {
7171
first, err := stream.Recv()
7272
if err != nil {
7373
return err

client/command/testsupport/recorder.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type RecorderRPC struct {
3939
artifactsResponders map[string]func(context.Context, any) (*clientpb.Artifacts, error)
4040
buildConfigResponders map[string]func(context.Context, any) (*clientpb.BuildConfig, error)
4141
contextResponders map[string]func(context.Context, any) (*clientpb.Context, error)
42-
contextStreamResponders map[string]func(context.Context, any) (grpc.ServerStreamingClient[clientpb.ContextChunk], error)
42+
contextStreamResponders map[string]func(context.Context, any) (clientrpc.MaliceRPC_SyncStreamClient, error)
4343
taskContextResponders map[string]func(context.Context, any) (*clientpb.TaskContext, error)
4444
taskContextsResponders map[string]func(context.Context, any) (*clientpb.TaskContexts, error)
4545
tasksResponders map[string]func(context.Context, any) (*clientpb.Tasks, error)
@@ -71,7 +71,7 @@ func NewRecorderRPC() *RecorderRPC {
7171
artifactsResponders: map[string]func(context.Context, any) (*clientpb.Artifacts, error){},
7272
buildConfigResponders: map[string]func(context.Context, any) (*clientpb.BuildConfig, error){},
7373
contextResponders: map[string]func(context.Context, any) (*clientpb.Context, error){},
74-
contextStreamResponders: map[string]func(context.Context, any) (grpc.ServerStreamingClient[clientpb.ContextChunk], error){},
74+
contextStreamResponders: map[string]func(context.Context, any) (clientrpc.MaliceRPC_SyncStreamClient, error){},
7575
taskContextResponders: map[string]func(context.Context, any) (*clientpb.TaskContext, error){},
7676
taskContextsResponders: map[string]func(context.Context, any) (*clientpb.TaskContexts, error){},
7777
tasksResponders: map[string]func(context.Context, any) (*clientpb.Tasks, error){},
@@ -150,7 +150,7 @@ func (r *RecorderRPC) OnContext(method string, fn func(context.Context, any) (*c
150150
r.contextResponders[method] = fn
151151
}
152152

153-
func (r *RecorderRPC) OnContextStream(method string, fn func(context.Context, any) (grpc.ServerStreamingClient[clientpb.ContextChunk], error)) {
153+
func (r *RecorderRPC) OnContextStream(method string, fn func(context.Context, any) (clientrpc.MaliceRPC_SyncStreamClient, error)) {
154154
r.contextStreamResponders[method] = fn
155155
}
156156

@@ -491,7 +491,7 @@ func (r *RecorderRPC) Sync(ctx context.Context, in *clientpb.Sync, opts ...grpc.
491491
return &clientpb.Context{Id: in.GetContextId()}, nil
492492
}
493493

494-
func (r *RecorderRPC) SyncStream(ctx context.Context, in *clientpb.Sync, opts ...grpc.CallOption) (grpc.ServerStreamingClient[clientpb.ContextChunk], error) {
494+
func (r *RecorderRPC) SyncStream(ctx context.Context, in *clientpb.Sync, opts ...grpc.CallOption) (clientrpc.MaliceRPC_SyncStreamClient, error) {
495495
r.recordPrimary(ctx, "SyncStream", in)
496496
if responder, ok := r.contextStreamResponders["SyncStream"]; ok {
497497
return responder(ctx, in)
@@ -919,6 +919,10 @@ func (r *RecorderRPC) SyncBuild(ctx context.Context, in *clientpb.BuildConfig, o
919919
return r.artifactResponse(ctx, "SyncBuild", in)
920920
}
921921

922+
func (r *RecorderRPC) ReplayArtifact(ctx context.Context, in *clientpb.Artifact, opts ...grpc.CallOption) (*clientpb.Artifact, error) {
923+
return r.artifactResponse(ctx, "ReplayArtifact", in)
924+
}
925+
922926
func (r *RecorderRPC) ListArtifact(ctx context.Context, in *clientpb.Empty, opts ...grpc.CallOption) (*clientpb.Artifacts, error) {
923927
r.recordPrimary(ctx, "ListArtifact", in)
924928
if responder, ok := r.artifactsResponders["ListArtifact"]; ok {
@@ -946,6 +950,10 @@ func (r *RecorderRPC) DownloadArtifact(ctx context.Context, in *clientpb.Artifac
946950
return r.artifactResponse(ctx, "DownloadArtifact", in)
947951
}
948952

953+
func (r *RecorderRPC) GetArtifactProfile(ctx context.Context, in *clientpb.Artifact, opts ...grpc.CallOption) (*clientpb.Artifact, error) {
954+
return r.artifactResponse(ctx, "GetArtifactProfile", in)
955+
}
956+
949957
func (r *RecorderRPC) UpdateArtifact(ctx context.Context, in *clientpb.Artifact, opts ...grpc.CallOption) (*clientpb.Artifact, error) {
950958
return r.artifactResponse(ctx, "UpdateArtifact", in)
951959
}

0 commit comments

Comments
 (0)