Skip to content

Commit

Permalink
Use filter in list instace api
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Nov 5, 2019
1 parent caeaa28 commit a09e07d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 40 deletions.
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})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a09e07d

Please sign in to comment.