diff --git a/cmd/rove-reverse-proxy/http_test.go b/cmd/rove-reverse-proxy/http_test.go index 4f6b5ce..7fe55a2 100644 --- a/cmd/rove-reverse-proxy/http_test.go +++ b/cmd/rove-reverse-proxy/http_test.go @@ -13,7 +13,9 @@ import ( "os" "testing" + "github.com/google/uuid" "github.com/mdiluz/rove/pkg/rove" + "github.com/stretchr/testify/assert" ) // Server is a simple wrapper to a server path @@ -68,13 +70,59 @@ func TestServer_Status(t *testing.T) { } func TestServer_Register(t *testing.T) { + req := &rove.RegisterRequest{Name: uuid.New().String()} + resp := &rove.RegisterResponse{} + err := serv.Request("POST", "register", req, resp) + assert.NoError(t, err, "First register attempt should pass") + err = serv.Request("POST", "register", req, resp) + assert.Error(t, err, "Second identical register attempt should fail") } func TestServer_Command(t *testing.T) { + acc := uuid.New().String() + err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &rove.RegisterResponse{}) + assert.NoError(t, err, "First register attempt should pass") + + err = serv.Request("POST", "commands", &rove.CommandsRequest{ + Account: acc, + Commands: []*rove.Command{ + { + Command: "move", + Bearing: "NE", + Duration: 1, + }, + }, + }, &rove.CommandsResponse{}) + assert.NoError(t, err, "Commands should should pass") } func TestServer_Radar(t *testing.T) { + acc := uuid.New().String() + err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &rove.RegisterResponse{}) + assert.NoError(t, err, "First register attempt should pass") + + resp := &rove.RadarResponse{} + err = serv.Request("POST", "radar", &rove.RadarRequest{ + Account: acc, + }, resp) + assert.NoError(t, err, "Radar sould pass should pass") + assert.NotZero(t, resp.Range, "Radar should return valid range") + w := int(resp.Range*2 + 1) + assert.Equal(t, w*w, len(resp.Tiles), "radar should return correct number of tiles") } func TestServer_Rover(t *testing.T) { + acc := uuid.New().String() + err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &rove.RegisterResponse{}) + assert.NoError(t, err, "First register attempt should pass") + + resp := &rove.RoverResponse{} + err = serv.Request("POST", "rover", &rove.RoverRequest{ + Account: acc, + }, resp) + assert.NoError(t, err, "Rover sould pass should pass") + assert.NotZero(t, resp.Range, "Rover should return valid range") + assert.NotZero(t, len(resp.Name), "Rover should return valid name") + assert.NotZero(t, resp.Speed, "Rover should return valid speed") + assert.NotZero(t, resp.Position, "Rover should return valid position") } diff --git a/cmd/rove-server/internal/routes.go b/cmd/rove-server/internal/routes.go index 911de92..14eddf9 100644 --- a/cmd/rove-server/internal/routes.go +++ b/cmd/rove-server/internal/routes.go @@ -69,6 +69,8 @@ func (s *Server) Rover(ctx context.Context, req *rove.RoverRequest) (*rove.Rover X: int32(attrib.Pos.X), Y: int32(attrib.Pos.Y), }, + Speed: int32(attrib.Speed), + Range: int32(attrib.Range), } } return response, nil diff --git a/pkg/rove/rove.pb.go b/pkg/rove/rove.pb.go index 8a790ca..67c5b11 100644 --- a/pkg/rove/rove.pb.go +++ b/pkg/rove/rove.pb.go @@ -775,7 +775,7 @@ var file_rove_rove_proto_rawDesc = []byte{ 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x24, 0x0a, 0x06, 0x56, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, - 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x32, 0xf2, 0x02, 0x0a, + 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x32, 0xf8, 0x02, 0x0a, 0x04, 0x52, 0x6f, 0x76, 0x65, 0x12, 0x44, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x13, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, @@ -790,18 +790,19 @@ var file_rove_rove_proto_rawDesc = []byte{ 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x22, - 0x09, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x3a, 0x01, 0x2a, 0x12, 0x40, 0x0a, + 0x09, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x3a, 0x01, 0x2a, 0x12, 0x43, 0x0a, 0x05, 0x52, 0x61, 0x64, 0x61, 0x72, 0x12, 0x12, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, 0x52, 0x61, 0x64, 0x61, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, 0x52, 0x61, 0x64, 0x61, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x0e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x08, 0x12, 0x06, 0x2f, 0x72, 0x61, 0x64, 0x61, 0x72, 0x12, - 0x40, 0x0a, 0x05, 0x52, 0x6f, 0x76, 0x65, 0x72, 0x12, 0x12, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, - 0x52, 0x6f, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x72, - 0x6f, 0x76, 0x65, 0x2e, 0x52, 0x6f, 0x76, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x0e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x08, 0x12, 0x06, 0x2f, 0x72, 0x6f, 0x76, 0x65, - 0x72, 0x42, 0x21, 0x5a, 0x1f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x6d, 0x64, 0x69, 0x6c, 0x75, 0x7a, 0x2f, 0x72, 0x6f, 0x76, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, - 0x72, 0x6f, 0x76, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x22, 0x06, 0x2f, 0x72, 0x61, 0x64, 0x61, 0x72, 0x3a, + 0x01, 0x2a, 0x12, 0x43, 0x0a, 0x05, 0x52, 0x6f, 0x76, 0x65, 0x72, 0x12, 0x12, 0x2e, 0x72, 0x6f, + 0x76, 0x65, 0x2e, 0x52, 0x6f, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x13, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x2e, 0x52, 0x6f, 0x76, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x22, 0x06, 0x2f, 0x72, + 0x6f, 0x76, 0x65, 0x72, 0x3a, 0x01, 0x2a, 0x42, 0x21, 0x5a, 0x1f, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x64, 0x69, 0x6c, 0x75, 0x7a, 0x2f, 0x72, 0x6f, 0x76, + 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x72, 0x6f, 0x76, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/pkg/rove/rove.pb.gw.go b/pkg/rove/rove.pb.gw.go index f22b6a0..0d19891 100644 --- a/pkg/rove/rove.pb.gw.go +++ b/pkg/rove/rove.pb.gw.go @@ -117,18 +117,15 @@ func local_request_Rove_Commands_0(ctx context.Context, marshaler runtime.Marsha } -var ( - filter_Rove_Radar_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - func request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq RadarRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Rove_Radar_0); err != nil { + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -141,10 +138,11 @@ func local_request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler var protoReq RadarRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Rove_Radar_0); err != nil { + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -153,18 +151,15 @@ func local_request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler } -var ( - filter_Rove_Rover_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - func request_Rove_Rover_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq RoverRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Rove_Rover_0); err != nil { + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -177,10 +172,11 @@ func local_request_Rove_Rover_0(ctx context.Context, marshaler runtime.Marshaler var protoReq RoverRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Rove_Rover_0); err != nil { + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -254,7 +250,7 @@ func RegisterRoveHandlerServer(ctx context.Context, mux *runtime.ServeMux, serve }) - mux.Handle("GET", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -274,7 +270,7 @@ func RegisterRoveHandlerServer(ctx context.Context, mux *runtime.ServeMux, serve }) - mux.Handle("GET", pattern_Rove_Rover_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Rove_Rover_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -395,7 +391,7 @@ func RegisterRoveHandlerClient(ctx context.Context, mux *runtime.ServeMux, clien }) - mux.Handle("GET", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -415,7 +411,7 @@ func RegisterRoveHandlerClient(ctx context.Context, mux *runtime.ServeMux, clien }) - mux.Handle("GET", pattern_Rove_Rover_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Rove_Rover_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) diff --git a/pkg/rove/rove.swagger.json b/pkg/rove/rove.swagger.json index 3b46b33..6969424 100644 --- a/pkg/rove/rove.swagger.json +++ b/pkg/rove/rove.swagger.json @@ -46,7 +46,7 @@ } }, "/radar": { - "get": { + "post": { "summary": "Get radar information", "description": "Gets the radar output for the given rover", "operationId": "Rove_Radar", @@ -66,11 +66,12 @@ }, "parameters": [ { - "name": "account", - "description": "The account for this request.", - "in": "query", - "required": false, - "type": "string" + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/roveRadarRequest" + } } ], "tags": [ @@ -113,7 +114,7 @@ } }, "/rover": { - "get": { + "post": { "summary": "Get rover information", "description": "Gets information for the account's rover", "operationId": "Rove_Rover", @@ -133,11 +134,12 @@ }, "parameters": [ { - "name": "account", - "description": "The account for this request.", - "in": "query", - "required": false, - "type": "string" + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/roveRoverRequest" + } } ], "tags": [ @@ -242,6 +244,15 @@ "type": "object", "title": "Empty placeholder" }, + "roveRadarRequest": { + "type": "object", + "properties": { + "account": { + "type": "string", + "title": "The account for this request" + } + } + }, "roveRadarResponse": { "type": "object", "properties": { @@ -270,6 +281,15 @@ "type": "object", "title": "Empty placeholder" }, + "roveRoverRequest": { + "type": "object", + "properties": { + "account": { + "type": "string", + "title": "The account for this request" + } + } + }, "roveRoverResponse": { "type": "object", "properties": { diff --git a/proto/rove/rove.proto b/proto/rove/rove.proto index d40bed0..d492671 100644 --- a/proto/rove/rove.proto +++ b/proto/rove/rove.proto @@ -41,7 +41,8 @@ service Rove { // Gets the radar output for the given rover rpc Radar(RadarRequest) returns (RadarResponse) { option (google.api.http) = { - get: "/radar" + post: "/radar" + body: "*" }; } @@ -50,7 +51,8 @@ service Rove { // Gets information for the account's rover rpc Rover(RoverRequest) returns (RoverResponse) { option (google.api.http) = { - get: "/rover" + post: "/rover" + body: "*" }; } }