Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use filter in list instance api #1473

Merged
merged 1 commit into from
Nov 6, 2019
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
12 changes: 10 additions & 2 deletions e2e/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func testInstance(t *testing.T) {
})

t.Run("list", func(t *testing.T) {
resp, err := client.InstanceClient.List(context.Background(), &pb.ListInstanceRequest{ServiceHash: testServiceHash})
resp, err := client.InstanceClient.List(context.Background(), &pb.ListInstanceRequest{
Filter: &pb.ListInstanceRequest_Filter{
ServiceHash: testServiceHash,
},
})
require.NoError(t, err)
require.Len(t, resp.Instances, 1)
require.Equal(t, testServiceHash, resp.Instances[0].ServiceHash)
Expand All @@ -58,7 +62,11 @@ func testDeleteInstance(t *testing.T) {
_, err := client.InstanceClient.Delete(ctx, &pb.DeleteInstanceRequest{Hash: testInstanceHash})
require.NoError(t, err)

resp, err := client.InstanceClient.List(context.Background(), &pb.ListInstanceRequest{ServiceHash: testServiceHash})
resp, err := client.InstanceClient.List(context.Background(), &pb.ListInstanceRequest{
Filter: &pb.ListInstanceRequest_Filter{
ServiceHash: testServiceHash,
},
})
require.NoError(t, err)
require.Len(t, resp.Instances, 0)
}
108 changes: 76 additions & 32 deletions protobuf/api/instance.pb.go

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

16 changes: 11 additions & 5 deletions protobuf/api/instance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ message GetInstanceRequest {

// The request's data for the `List` API.
message ListInstanceRequest {
// Filter by Services' hash.
bytes serviceHash = 1 [
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];
// Filter contains filtering criteria.
message Filter {
// Service hash to filter executions.
bytes serviceHash = 1 [
(gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
(gogoproto.nullable) = false
];
}

// Filter used to filter a list of instance.
Filter filter = 1;
}

// The response's data for the `List` API.
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewInstanceServer(sdk *sdk.SDK) *InstanceServer {

// List instances.
func (s *InstanceServer) List(ctx context.Context, request *protobuf_api.ListInstanceRequest) (*protobuf_api.ListInstanceResponse, error) {
instances, err := s.sdk.Instance.List(&instancesdk.Filter{ServiceHash: request.ServiceHash})
instances, err := s.sdk.Instance.List(&instancesdk.Filter{ServiceHash: request.Filter.ServiceHash})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request.Filter should be nilable.
Should add a check if request.Filter is nil

if err != nil {
return nil, err
}
Expand Down