Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/plugin-protocol/tfplugin6.proto
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ service Provider {
rpc ConfigureStateStore(ConfigureStateStore.Request) returns (ConfigureStateStore.Response);

// ReadStateBytes streams byte chunks of a given state file from a state store
rpc ReadStateBytes(ReadStateBytes.Request) returns (stream ReadStateBytes.ResponseChunk);
rpc ReadStateBytes(ReadStateBytes.Request) returns (stream ReadStateBytes.Response);
// WriteStateBytes streams byte chunks of a given state file into a state store
rpc WriteStateBytes(stream WriteStateBytes.RequestChunk) returns (WriteStateBytes.Response);

Expand Down Expand Up @@ -923,7 +923,6 @@ message ValidateListResourceConfig {
}
}


message ValidateStateStore {
message Request {
string type_name = 1;
Expand All @@ -949,7 +948,7 @@ message ReadStateBytes {
string type_name = 1;
string state_id = 2;
}
message ResponseChunk {
message Response {
bytes bytes = 1;
int64 total_length = 2;
StateRange range = 3;
Expand All @@ -959,9 +958,11 @@ message ReadStateBytes {

message WriteStateBytes {
message RequestChunk {
// TODO: Can we decouple this outside of the stream?
string type_name = 1;
bytes bytes = 2;
string state_id = 3;

bytes bytes = 2;
int64 total_length = 4;
StateRange range = 5;
}
Expand Down
1 change: 1 addition & 0 deletions internal/plugin6/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ func (p *GRPCProvider) ReadStateBytes(r providers.ReadStateBytesRequest) (resp p
chunk, err := client.Recv()
if err == io.EOF {
// End of stream, we're done
resp.Diagnostics = resp.Diagnostics.Append(convert.ProtoToDiagnostics(chunk.Diagnostics))
break
}
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions internal/plugin6/grpc_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3519,11 +3519,11 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
chunks := []string{"hello", "world"}
totalLength := len(chunks[0]) + len(chunks[1])
mockResp := map[int]struct {
resp *proto.ReadStateBytes_ResponseChunk
resp *proto.ReadStateBytes_Response
err error
}{
0: {
resp: &proto.ReadStateBytes_ResponseChunk{
resp: &proto.ReadStateBytes_Response{
Bytes: []byte(chunks[0]),
TotalLength: int64(totalLength),
Range: &proto.StateRange{
Expand All @@ -3534,7 +3534,7 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
err: nil,
},
1: {
resp: &proto.ReadStateBytes_ResponseChunk{
resp: &proto.ReadStateBytes_Response{
Bytes: []byte(chunks[1]),
TotalLength: int64(totalLength),
Range: &proto.StateRange{
Expand All @@ -3545,12 +3545,12 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
err: nil,
},
2: {
resp: nil,
resp: &proto.ReadStateBytes_Response{},
err: io.EOF,
},
}
var count int
mockReadBytesClient.EXPECT().Recv().DoAndReturn(func() (*proto.ReadStateBytes_ResponseChunk, error) {
mockReadBytesClient.EXPECT().Recv().DoAndReturn(func() (*proto.ReadStateBytes_Response, error) {
ret := mockResp[count]
count++
return ret.resp, ret.err
Expand Down Expand Up @@ -3595,11 +3595,11 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
var incorrectLength int64 = 999
correctLength := len(chunks[0]) + len(chunks[1])
mockResp := map[int]struct {
resp *proto.ReadStateBytes_ResponseChunk
resp *proto.ReadStateBytes_Response
err error
}{
0: {
resp: &proto.ReadStateBytes_ResponseChunk{
resp: &proto.ReadStateBytes_Response{
Bytes: []byte(chunks[0]),
TotalLength: incorrectLength,
Range: &proto.StateRange{
Expand All @@ -3610,7 +3610,7 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
err: nil,
},
1: {
resp: &proto.ReadStateBytes_ResponseChunk{
resp: &proto.ReadStateBytes_Response{
Bytes: []byte(chunks[1]),
TotalLength: incorrectLength,
Range: &proto.StateRange{
Expand All @@ -3621,12 +3621,12 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
err: nil,
},
2: {
resp: nil,
resp: &proto.ReadStateBytes_Response{},
err: io.EOF,
},
}
var count int
mockReadBytesClient.EXPECT().Recv().DoAndReturn(func() (*proto.ReadStateBytes_ResponseChunk, error) {
mockReadBytesClient.EXPECT().Recv().DoAndReturn(func() (*proto.ReadStateBytes_Response, error) {
ret := mockResp[count]
count++
return ret.resp, ret.err
Expand Down Expand Up @@ -3702,7 +3702,7 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
).Return(mockReadBytesClient, nil)

// Define what will be returned by each call to Recv
mockReadBytesClient.EXPECT().Recv().Return(&proto.ReadStateBytes_ResponseChunk{
mockReadBytesClient.EXPECT().Recv().Return(&proto.ReadStateBytes_Response{
Diagnostics: []*proto.Diagnostic{
&proto.Diagnostic{
Severity: proto.Diagnostic_ERROR,
Expand Down Expand Up @@ -3752,15 +3752,15 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
).Return(mockReadBytesClient, nil)

// Define what will be returned by each call to Recv
mockReadBytesClient.EXPECT().Recv().Return(&proto.ReadStateBytes_ResponseChunk{
mockReadBytesClient.EXPECT().Recv().Return(&proto.ReadStateBytes_Response{
Diagnostics: []*proto.Diagnostic{
&proto.Diagnostic{
Severity: proto.Diagnostic_WARNING,
Summary: "Warning from test",
Detail: "This warning is forced by the test case",
},
},
}, nil)
}, io.EOF)

// Act
request := providers.ReadStateBytesRequest{
Expand Down Expand Up @@ -3801,7 +3801,7 @@ func TestGRPCProvider_ReadStateBytes(t *testing.T) {
).Return(mockClient, nil)

mockError := errors.New("grpc error forced in test")
mockClient.EXPECT().Recv().Return(&proto.ReadStateBytes_ResponseChunk{}, mockError)
mockClient.EXPECT().Recv().Return(&proto.ReadStateBytes_Response{}, mockError)

// Act
request := providers.ReadStateBytesRequest{
Expand Down
4 changes: 2 additions & 2 deletions internal/plugin6/mock_proto/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading