diff --git a/commands/update_desired_lrp_test.go b/commands/update_desired_lrp_test.go index 1b96a78..e458fb4 100644 --- a/commands/update_desired_lrp_test.go +++ b/commands/update_desired_lrp_test.go @@ -41,7 +41,7 @@ var _ = Describe("UpdateDesiredLRP", func() { updatedInstanceCount := int32(4) dlu := models.DesiredLRPUpdate{} - dlu.SetInstances(updatedInstanceCount) + dlu.SetInstances(&updatedInstanceCount) updatedDesiredLRP = &dlu spec, err = json.Marshal(updatedDesiredLRP) diff --git a/integration/actual_lrp_groups_for_guid_test.go b/integration/actual_lrp_groups_for_guid_test.go index a964831..3662273 100644 --- a/integration/actual_lrp_groups_for_guid_test.go +++ b/integration/actual_lrp_groups_for_guid_test.go @@ -25,27 +25,29 @@ var _ = Describe("actual-lrp-groups-for-guid", func() { }) JustBeforeEach(func() { + //lint:ignore SA1019 - deprecated model used for testing deprecated functionality + request := &models.ActualLRPGroupsByProcessGuidRequest{ + ProcessGuid: "random-guid", + } + //lint:ignore SA1019 - deprecated model used for testing deprecated functionality + response := &models.ActualLRPGroupsResponse{ + //lint:ignore SA1019 - deprecated model used for testing deprecated functionality + ActualLrpGroups: []*models.ActualLRPGroup{ + { + Instance: &models.ActualLRP{ + State: "running", + }, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrp_groups/list_by_process_guid"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - //lint:ignore SA1019 - deprecated model used for testing deprecated functionality - ghttp.VerifyProtoRepresenting(&models.ActualLRPGroupsByProcessGuidRequest{ - ProcessGuid: "random-guid", - }), - //lint:ignore SA1019 - deprecated model used for testing deprecated functionality - ghttp.RespondWithProto(200, &models.ActualLRPGroupsResponse{ - //lint:ignore SA1019 - deprecated model used for testing deprecated functionality - ActualLrpGroups: []*models.ActualLRPGroup{ - { - Instance: &models.ActualLRP{ - State: "running", - }, - }, - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -81,16 +83,17 @@ var _ = Describe("actual-lrp-groups-for-guid", func() { Context("when the server returns an error", func() { BeforeEach(func() { + response := &models.DomainsResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "the request failed due to deadlock", + }, + Domains: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrp_groups/list_by_process_guid"), - ghttp.RespondWithProto(500, &models.DomainsResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "the request failed due to deadlock", - }, - Domains: nil, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) }) @@ -112,28 +115,30 @@ var _ = Describe("actual-lrp-groups-for-guid", func() { Context("when passing index as filter", func() { BeforeEach(func() { + //lint:ignore SA1019 - deprecated model used for testing deprecated functionality + request := &models.ActualLRPGroupByProcessGuidAndIndexRequest{ + ProcessGuid: "test-process-guid", + Index: 1, + } + //lint:ignore SA1019 - deprecated model used for testing deprecated functionality + response := &models.ActualLRPGroupsResponse{ + //lint:ignore SA1019 - deprecated model used for testing deprecated functionality + ActualLrpGroups: []*models.ActualLRPGroup{ + { + Instance: &models.ActualLRP{ + ActualLrpKey: models.ActualLRPKey{ + Index: 1, + }, + State: "running", + }, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrp_groups/get_by_process_guid_and_index"), - //lint:ignore SA1019 - deprecated model used for testing deprecated functionality - ghttp.VerifyProtoRepresenting(&models.ActualLRPGroupByProcessGuidAndIndexRequest{ - ProcessGuid: "test-process-guid", - Index: 1, - }), - //lint:ignore SA1019 - deprecated model used for testing deprecated functionality - ghttp.RespondWithProto(200, &models.ActualLRPGroupsResponse{ - //lint:ignore SA1019 - deprecated model used for testing deprecated functionality - ActualLrpGroups: []*models.ActualLRPGroup{ - { - Instance: &models.ActualLRP{ - ActualLRPKey: models.ActualLRPKey{ - Index: 1, - }, - State: "running", - }, - }, - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/actual_lrp_groups_test.go b/integration/actual_lrp_groups_test.go index 49cd0e4..beb9258 100644 --- a/integration/actual_lrp_groups_test.go +++ b/integration/actual_lrp_groups_test.go @@ -27,23 +27,24 @@ var _ = Describe("actual-lrp-groups", func() { }) JustBeforeEach(func() { + //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method + response := &models.ActualLRPGroupsResponse{ + //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method + ActualLrpGroups: []*models.ActualLRPGroup{ + { + Instance: &models.ActualLRP{ + State: "running", + }, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrp_groups/list"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method - ghttp.RespondWithProto(200, &models.ActualLRPGroupsResponse{ - //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method - ActualLrpGroups: []*models.ActualLRPGroup{ - { - Instance: &models.ActualLRP{ - State: "running", - }, - }, - }, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -79,25 +80,27 @@ var _ = Describe("actual-lrp-groups", func() { Context("when passing filters", func() { BeforeEach(func() { + //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method + request := &models.ActualLRPGroupsRequest{ + Domain: "cf-apps", + CellId: "cell_z1-0", + } + //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method + response := &models.ActualLRPGroupsResponse{ + //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method + ActualLrpGroups: []*models.ActualLRPGroup{ + { + Instance: &models.ActualLRP{ + State: "running", + }, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrp_groups/list"), - //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method - ghttp.VerifyProtoRepresenting(&models.ActualLRPGroupsRequest{ - Domain: "cf-apps", - CellId: "cell_z1-0", - }), - //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method - ghttp.RespondWithProto(200, &models.ActualLRPGroupsResponse{ - //lint:ignore SA1019 - calling deprecated model while unit testing deprecated method - ActualLrpGroups: []*models.ActualLRPGroup{ - { - Instance: &models.ActualLRP{ - State: "running", - }, - }, - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/actual_lrps_test.go b/integration/actual_lrps_test.go index 150029d..95f0833 100644 --- a/integration/actual_lrps_test.go +++ b/integration/actual_lrps_test.go @@ -26,20 +26,22 @@ var _ = Describe("actual-lrps", func() { }) JustBeforeEach(func() { + request := &models.ActualLRPsRequest{} + response := &models.ActualLRPsResponse{ + ActualLrps: []*models.ActualLRP{ + &models.ActualLRP{ + State: "running", + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrps/list"), - ghttp.VerifyProtoRepresenting(&models.ActualLRPsRequest{}), + ghttp.VerifyProtoRepresenting(request.ToProto()), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.ActualLRPsResponse{ - ActualLrps: []*models.ActualLRP{ - &models.ActualLRP{ - State: "running", - }, - }, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -75,24 +77,26 @@ var _ = Describe("actual-lrps", func() { Context("when passing filters", func() { BeforeEach(func() { - alr := models.ActualLRPsRequest{ + request := models.ActualLRPsRequest{ Domain: "cf-apps", CellId: "cell_z1-0", ProcessGuid: "pg-0", } - alr.SetIndex(int32(1)) + index := int32(1) + request.SetIndex(&index) + response := &models.ActualLRPsResponse{ + ActualLrps: []*models.ActualLRP{ + &models.ActualLRP{ + State: "running", + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrps/list"), - ghttp.VerifyProtoRepresenting(&alr), - ghttp.RespondWithProto(200, &models.ActualLRPsResponse{ - ActualLrps: []*models.ActualLRP{ - &models.ActualLRP{ - State: "running", - }, - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/cancel_task_test.go b/integration/cancel_task_test.go index 811df91..6de1943 100644 --- a/integration/cancel_task_test.go +++ b/integration/cancel_task_test.go @@ -25,13 +25,14 @@ var _ = Describe("cancel-task", func() { }) JustBeforeEach(func() { + request := &models.TaskGuidRequest{TaskGuid: "task-guid"} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/cancel"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.TaskGuidRequest{TaskGuid: "task-guid"}), + ghttp.VerifyProtoRepresenting(request.ToProto()), ghttp.RespondWith(200, nil), ), ) @@ -68,12 +69,13 @@ var _ = Describe("cancel-task", func() { Context("when the server responds with error", func() { It("exits with status code 4", func() { + response := &models.TaskResponse{ + Error: models.ErrUnknownError, + } bbsServer.RouteToHandler( "POST", "/v1/tasks/cancel", - ghttp.RespondWithProto(200, &models.TaskResponse{ - Error: models.ErrUnknownError, - }), + ghttp.RespondWithProto(200, response.ToProto()), ) sess := RunCFDot("cancel-task", "task-guid") diff --git a/integration/cell_state_test.go b/integration/cell_state_test.go index 6cde775..1dbc019 100644 --- a/integration/cell_state_test.go +++ b/integration/cell_state_test.go @@ -69,12 +69,14 @@ var _ = Describe("cell-state", func() { Tasks: []rep.Task{}, } + response := &models.CellsResponse{ + Cells: []*models.CellPresence{presence1, presence2}, + } + bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/cells/list.r1"), - ghttp.RespondWithProto(200, &models.CellsResponse{ - Cells: []*models.CellPresence{presence1, presence2}, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) rep1Server.RouteToHandler("GET", "/state", func(resp http.ResponseWriter, req *http.Request) { @@ -113,15 +115,16 @@ var _ = Describe("cell-state", func() { ) JustBeforeEach(func() { + response := &models.CellsResponse{ + Cells: []*models.CellPresence{presence1, presence2}, + } bbsServer.SetHandler(0, ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/cells/list.r1"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.CellsResponse{ - Cells: []*models.CellPresence{presence1, presence2}, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) @@ -189,15 +192,16 @@ var _ = Describe("cell-state", func() { ) JustBeforeEach(func() { + response := &models.CellsResponse{ + Cells: []*models.CellPresence{presence1, presence2}, + } bbsServer.SetHandler(0, ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/cells/list.r1"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.CellsResponse{ - Cells: []*models.CellPresence{presence1, presence2}, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) @@ -246,12 +250,13 @@ var _ = Describe("cell-state", func() { Context("when the BBS request fails", func() { BeforeEach(func() { + response := &models.CellsResponse{ + Error: models.ErrUnknownError, + } bbsServer.SetHandler(0, ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/cells/list.r1"), - ghttp.RespondWithProto(503, &models.CellsResponse{ - Error: models.ErrUnknownError, - }), + ghttp.RespondWithProto(503, response.ToProto()), ), ) }) diff --git a/integration/cell_test.go b/integration/cell_test.go index febe387..0a2aa19 100644 --- a/integration/cell_test.go +++ b/integration/cell_test.go @@ -32,15 +32,16 @@ var _ = Describe("cell", func() { }) JustBeforeEach(func() { + response := &models.CellsResponse{ + Cells: []*models.CellPresence{presence}, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/cells/list.r1"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.CellsResponse{ - Cells: []*models.CellPresence{presence}, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/cells_test.go b/integration/cells_test.go index 72db304..8708afe 100644 --- a/integration/cells_test.go +++ b/integration/cells_test.go @@ -25,32 +25,33 @@ var _ = Describe("cells", func() { }) JustBeforeEach(func() { + response := &models.CellsResponse{ + Cells: []*models.CellPresence{ + { + CellId: "cell-1", + RepAddress: "rep-1", + Zone: "zone1", + Capacity: &models.CellCapacity{ + MemoryMb: 1024, + DiskMb: 1024, + Containers: 10, + }, + RootfsProviders: []*models.Provider{ + { + Name: "rootfs1", + }, + }, + RepUrl: "http://rep1.com", + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/cells/list.r1"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.CellsResponse{ - Cells: []*models.CellPresence{ - { - CellId: "cell-1", - RepAddress: "rep-1", - Zone: "zone1", - Capacity: &models.CellCapacity{ - MemoryMb: 1024, - DiskMb: 1024, - Containers: 10, - }, - RootfsProviders: []*models.Provider{ - { - Name: "rootfs1", - }, - }, - RepUrl: "http://rep1.com", - }, - }, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/create_desired_lrp_test.go b/integration/create_desired_lrp_test.go index c746593..ee8e958 100644 --- a/integration/create_desired_lrp_test.go +++ b/integration/create_desired_lrp_test.go @@ -42,18 +42,20 @@ var _ = Describe("create-desired-lrp", func() { }) JustBeforeEach(func() { + request := &models.DesireLRPRequest{ + DesiredLrp: lrp, + } + response := &models.DesiredLRPLifecycleResponse{ + Error: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp/desire.r2"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.DesireLRPRequest{ - DesiredLrp: lrp, - }), - ghttp.RespondWithProto(200, &models.DesiredLRPLifecycleResponse{ - Error: nil, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -142,15 +144,16 @@ var _ = Describe("create-desired-lrp", func() { Context("when bbs responds with non-200 status code", func() { JustBeforeEach(func() { + response := &models.DesiredLRPLifecycleResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "deadlock detected", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp/desire.r2"), - ghttp.RespondWithProto(500, &models.DesiredLRPLifecycleResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) }) diff --git a/integration/create_task_test.go b/integration/create_task_test.go index 35850c6..8de8b86 100644 --- a/integration/create_task_test.go +++ b/integration/create_task_test.go @@ -42,20 +42,22 @@ var _ = Describe("create-task", func() { }) JustBeforeEach(func() { + request := &models.DesireTaskRequest{ + TaskGuid: task.TaskGuid, + Domain: task.Domain, + TaskDefinition: task.TaskDefinition, + } + response := &models.TaskLifecycleResponse{ + Error: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/desire.r2"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.DesireTaskRequest{ - TaskGuid: task.TaskGuid, - Domain: task.Domain, - TaskDefinition: task.TaskDefinition, - }), - ghttp.RespondWithProto(200, &models.TaskLifecycleResponse{ - Error: nil, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -144,15 +146,16 @@ var _ = Describe("create-task", func() { Context("when bbs responds with non-200 status code", func() { JustBeforeEach(func() { + response := &models.TaskLifecycleResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "deadlock detected", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/desire.r2"), - ghttp.RespondWithProto(500, &models.TaskLifecycleResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) }) diff --git a/integration/delete_desired_lrp_test.go b/integration/delete_desired_lrp_test.go index 4ff4468..0a72689 100644 --- a/integration/delete_desired_lrp_test.go +++ b/integration/delete_desired_lrp_test.go @@ -47,16 +47,18 @@ var _ = Describe("delete-desired-lrp", func() { }) JustBeforeEach(func() { + request := &models.RemoveDesiredLRPRequest{ + ProcessGuid: processGuid, + } + response := &models.DesiredLRPLifecycleResponse{} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp/remove"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.RemoveDesiredLRPRequest{ - ProcessGuid: processGuid, - }), - ghttp.RespondWithProto(200, &models.DesiredLRPLifecycleResponse{}), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -94,15 +96,16 @@ var _ = Describe("delete-desired-lrp", func() { Context("when bbs responds with non-200 status code", func() { BeforeEach(func() { + response := &models.DesiredLRPLifecycleResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "deadlock detected", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp/remove"), - ghttp.RespondWithProto(500, &models.DesiredLRPLifecycleResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) }) diff --git a/integration/delete_task_test.go b/integration/delete_task_test.go index 0936db0..da00512 100644 --- a/integration/delete_task_test.go +++ b/integration/delete_task_test.go @@ -47,23 +47,23 @@ var _ = Describe("delete-task", func() { }) JustBeforeEach(func() { + request := &models.TaskGuidRequest{ + TaskGuid: taskGuid, + } + response := &models.TaskLifecycleResponse{} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/resolving"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.TaskGuidRequest{ - TaskGuid: taskGuid, - }), - ghttp.RespondWithProto(200, &models.TaskLifecycleResponse{}), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/delete"), - ghttp.VerifyProtoRepresenting(&models.TaskGuidRequest{ - TaskGuid: taskGuid, - }), - ghttp.RespondWithProto(200, &models.TaskLifecycleResponse{}), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -101,24 +101,20 @@ var _ = Describe("delete-task", func() { Context("when bbs responds with non-200 status code", func() { BeforeEach(func() { + response := &models.TaskLifecycleResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "deadlock detected", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/resolving"), - ghttp.RespondWithProto(500, &models.TaskLifecycleResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/delete"), - ghttp.RespondWithProto(500, &models.TaskLifecycleResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) }) diff --git a/integration/desired_lrp_scheduling_infos_test.go b/integration/desired_lrp_scheduling_infos_test.go index 00b28ad..5176a41 100644 --- a/integration/desired_lrp_scheduling_infos_test.go +++ b/integration/desired_lrp_scheduling_infos_test.go @@ -35,19 +35,20 @@ var _ = Describe("desired-lrp-scheduling-infos", func() { }) JustBeforeEach(func() { + response := &models.DesiredLRPSchedulingInfosResponse{ + DesiredLrpSchedulingInfos: []*models.DesiredLRPSchedulingInfo{ + { + Instances: 1, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp_scheduling_infos/list"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.DesiredLRPSchedulingInfosResponse{ - DesiredLrpSchedulingInfos: []*models.DesiredLRPSchedulingInfo{ - { - Instances: 1, - }, - }, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -87,19 +88,21 @@ var _ = Describe("desired-lrp-scheduling-infos", func() { Context("when passing filters", func() { BeforeEach(func() { + request := &models.DesiredLRPsRequest{ + Domain: "cf-apps", + } + response := &models.DesiredLRPSchedulingInfosResponse{ + DesiredLrpSchedulingInfos: []*models.DesiredLRPSchedulingInfo{ + { + Instances: 1, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp_scheduling_infos/list"), - ghttp.VerifyProtoRepresenting(&models.DesiredLRPsRequest{ - Domain: "cf-apps", - }), - ghttp.RespondWithProto(200, &models.DesiredLRPSchedulingInfosResponse{ - DesiredLrpSchedulingInfos: []*models.DesiredLRPSchedulingInfo{ - { - Instances: 1, - }, - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/desired_lrp_test.go b/integration/desired_lrp_test.go index 232d65c..7b2c803 100644 --- a/integration/desired_lrp_test.go +++ b/integration/desired_lrp_test.go @@ -61,6 +61,13 @@ var _ = Describe("desired-lrp", func() { ProcessGuid: "test-guid", Instances: 2, } + request := &models.DesiredLRPByProcessGuidRequest{ + ProcessGuid: "test-guid", + } + response := &models.DesiredLRPResponse{ + DesiredLrp: desiredLRP, + Error: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( @@ -68,13 +75,8 @@ var _ = Describe("desired-lrp", func() { func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.DesiredLRPByProcessGuidRequest{ - ProcessGuid: "test-guid", - }), - ghttp.RespondWithProto(200, &models.DesiredLRPResponse{ - DesiredLrp: desiredLRP, - Error: nil, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) @@ -96,6 +98,13 @@ var _ = Describe("desired-lrp", func() { ProcessGuid: "test-guid", Instances: 2, } + request := &models.DesiredLRPByProcessGuidRequest{ + ProcessGuid: "test-guid", + } + response := &models.DesiredLRPResponse{ + DesiredLrp: desiredLRP, + Error: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( @@ -103,13 +112,8 @@ var _ = Describe("desired-lrp", func() { func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.DesiredLRPByProcessGuidRequest{ - ProcessGuid: "test-guid", - }), - ghttp.RespondWithProto(200, &models.DesiredLRPResponse{ - DesiredLrp: desiredLRP, - Error: nil, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -140,15 +144,16 @@ var _ = Describe("desired-lrp", func() { Context("when bbs responds with non-200 status code", func() { BeforeEach(func() { + response := &models.DesiredLRPResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "deadlock detected", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrps/get_by_process_guid.r3"), - ghttp.RespondWithProto(500, &models.DesiredLRPResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) }) diff --git a/integration/desired_lrps_test.go b/integration/desired_lrps_test.go index 0425f0c..e36255a 100644 --- a/integration/desired_lrps_test.go +++ b/integration/desired_lrps_test.go @@ -27,19 +27,20 @@ var _ = Describe("desired-lrps", func() { }) JustBeforeEach(func() { + response := &models.DesiredLRPsResponse{ + DesiredLrps: []*models.DesiredLRP{ + { + Instances: 1, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrps/list.r3"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.DesiredLRPsResponse{ - DesiredLrps: []*models.DesiredLRP{ - { - Instances: 1, - }, - }, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -75,19 +76,21 @@ var _ = Describe("desired-lrps", func() { Context("when passing filters", func() { BeforeEach(func() { + request := &models.DesiredLRPsRequest{ + Domain: "cf-apps", + } + response := &models.DesiredLRPsResponse{ + DesiredLrps: []*models.DesiredLRP{ + { + Instances: 1, + }, + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrps/list.r3"), - ghttp.VerifyProtoRepresenting(&models.DesiredLRPsRequest{ - Domain: "cf-apps", - }), - ghttp.RespondWithProto(200, &models.DesiredLRPsResponse{ - DesiredLrps: []*models.DesiredLRP{ - { - Instances: 1, - }, - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/domains_test.go b/integration/domains_test.go index 343424f..03c628c 100644 --- a/integration/domains_test.go +++ b/integration/domains_test.go @@ -27,16 +27,17 @@ var _ = Describe("domains", func() { }) JustBeforeEach(func() { + response := &models.DomainsResponse{ + Error: nil, + Domains: []string{"domain-1", "domain-2"}, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/domains/list"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.DomainsResponse{ - Error: nil, - Domains: []string{"domain-1", "domain-2"}, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -85,16 +86,17 @@ var _ = Describe("domains", func() { Context("when the server returns an error", func() { BeforeEach(func() { + response := &models.DomainsResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "the request failed due to deadlock", + }, + Domains: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/domains/list"), - ghttp.RespondWithProto(200, &models.DomainsResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "the request failed due to deadlock", - }, - Domains: nil, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -116,10 +118,11 @@ var _ = Describe("domains", func() { Describe("flag parsing for bbsURL", func() { Context("when running domains", func() { BeforeEach(func() { + response := &models.DomainsResponse{} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/domains/list"), - ghttp.RespondWithProto(200, &models.DomainsResponse{}), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/lrp_events_test.go b/integration/lrp_events_test.go index 3d853d2..3887c7b 100644 --- a/integration/lrp_events_test.go +++ b/integration/lrp_events_test.go @@ -4,8 +4,8 @@ import ( "code.cloudfoundry.org/bbs/events" "code.cloudfoundry.org/bbs/models" "code.cloudfoundry.org/bbs/models/test/model_helpers" + "google.golang.org/protobuf/proto" - "github.com/gogo/protobuf/proto" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" @@ -21,7 +21,7 @@ var _ = Describe("lrp-events", func() { Context("when the cell id is specified", func() { BeforeEach(func() { expectedRequest := &models.EventsByCellId{CellId: "some-cell-id"} - expectedBody, err := proto.Marshal(expectedRequest) + expectedBody, err := proto.Marshal(expectedRequest.ToProto()) Expect(err).NotTo(HaveOccurred()) bbsServer.AppendHandlers( ghttp.CombineHandlers( @@ -45,7 +45,7 @@ var _ = Describe("lrp-events", func() { Context("when the cell id is not specified", func() { BeforeEach(func() { expectedRequest := &models.EventsByCellId{CellId: ""} - expectedBody, err := proto.Marshal(expectedRequest) + expectedBody, err := proto.Marshal(expectedRequest.ToProto()) Expect(err).NotTo(HaveOccurred()) bbsServer.AppendHandlers( ghttp.CombineHandlers( diff --git a/integration/retire_actual_lrp_test.go b/integration/retire_actual_lrp_test.go index 121848c..60ad97c 100644 --- a/integration/retire_actual_lrp_test.go +++ b/integration/retire_actual_lrp_test.go @@ -26,21 +26,23 @@ var _ = Describe("retire-actual-lrp", func() { }) JustBeforeEach(func() { + desiredLrpResponse := &models.DesiredLRPResponse{ + DesiredLrp: &models.DesiredLRP{ + Domain: "test-domain", + }, + } + actualLrpResponse := &models.ActualLRPLifecycleResponse{} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrps/get_by_process_guid.r3"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.DesiredLRPResponse{ - DesiredLrp: &models.DesiredLRP{ - Domain: "test-domain", - }, - }), + ghttp.RespondWithProto(200, desiredLrpResponse.ToProto()), ), ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/actual_lrps/retire"), - ghttp.RespondWithProto(200, &models.ActualLRPLifecycleResponse{}), + ghttp.RespondWithProto(200, actualLrpResponse.ToProto()), ), ) }) @@ -74,15 +76,16 @@ var _ = Describe("retire-actual-lrp", func() { Context("when the bbs returns an error", func() { BeforeEach(func() { + response := &models.DesiredLRPResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "the request failed due to deadlock", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrps/get_by_process_guid.r3"), - ghttp.RespondWithProto(200, &models.DesiredLRPResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "the request failed due to deadlock", - }, - }), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/set_domain_test.go b/integration/set_domain_test.go index 45e18f0..63ca476 100644 --- a/integration/set_domain_test.go +++ b/integration/set_domain_test.go @@ -27,13 +27,14 @@ var _ = Describe("set-domain", func() { }) JustBeforeEach(func() { + response := &models.UpsertDomainResponse{} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/domains/upsert"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.UpsertDomainResponse{}), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) diff --git a/integration/task_test.go b/integration/task_test.go index b25505b..63117e0 100644 --- a/integration/task_test.go +++ b/integration/task_test.go @@ -30,14 +30,16 @@ var _ = Describe("task", func() { }) JustBeforeEach(func() { + request := &models.TaskByGuidRequest{TaskGuid: "task-guid"} + response := &models.TaskResponse{Task: task} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/get_by_task_guid.r3"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.TaskByGuidRequest{TaskGuid: "task-guid"}), - ghttp.RespondWithProto(200, &models.TaskResponse{Task: task}), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -75,12 +77,13 @@ var _ = Describe("task", func() { Context("when the server responds with error", func() { It("exits with status code 4", func() { + response := &models.TaskResponse{ + Error: models.ErrUnknownError, + } bbsServer.RouteToHandler( "POST", "/v1/tasks/get_by_task_guid.r3", - ghttp.RespondWithProto(200, &models.TaskResponse{ - Error: models.ErrUnknownError, - }), + ghttp.RespondWithProto(200, response.ToProto()), ) sess := RunCFDot("task", "task-guid") diff --git a/integration/tasks_test.go b/integration/tasks_test.go index 19d0436..e5bf209 100644 --- a/integration/tasks_test.go +++ b/integration/tasks_test.go @@ -31,13 +31,14 @@ var _ = Describe("tasks", func() { }) JustBeforeEach(func() { + response := &models.TasksResponse{Tasks: []*models.Task{&task}} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/list.r3"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.RespondWithProto(200, &models.TasksResponse{Tasks: []*models.Task{&task}}), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -86,17 +87,19 @@ var _ = Describe("tasks", func() { Context("when there are filters for tasks", func() { Context("with domain filters", func() { BeforeEach(func() { + request := &models.TasksRequest{ + Domain: "domain", + } + response := &models.TaskResponse{ + Task: &models.Task{ + TaskGuid: "task-guid", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/list.r3"), - ghttp.VerifyProtoRepresenting(&models.TasksRequest{ - Domain: "domain", - }), - ghttp.RespondWithProto(200, &models.TaskResponse{ - Task: &models.Task{ - TaskGuid: "task-guid", - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -125,17 +128,19 @@ var _ = Describe("tasks", func() { Context("with cell filters", func() { BeforeEach(func() { + request := &models.TasksRequest{ + CellId: "cell-id", + } + response := &models.TaskResponse{ + Task: &models.Task{ + TaskGuid: "task-guid", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/list.r3"), - ghttp.VerifyProtoRepresenting(&models.TasksRequest{ - CellId: "cell-id", - }), - ghttp.RespondWithProto(200, &models.TaskResponse{ - Task: &models.Task{ - TaskGuid: "task-guid", - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -164,18 +169,20 @@ var _ = Describe("tasks", func() { Context("with cell and domain filters", func() { BeforeEach(func() { + request := &models.TasksRequest{ + Domain: "domain", + CellId: "cell-id", + } + response := &models.TaskResponse{ + Task: &models.Task{ + TaskGuid: "task-guid", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/list.r3"), - ghttp.VerifyProtoRepresenting(&models.TasksRequest{ - Domain: "domain", - CellId: "cell-id", - }), - ghttp.RespondWithProto(200, &models.TaskResponse{ - Task: &models.Task{ - TaskGuid: "task-guid", - }, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -197,10 +204,11 @@ var _ = Describe("tasks", func() { Context("when the bbs returns an error", func() { It("returns an error and exits with status 4", func() { + response := &models.TasksResponse{Error: models.ErrUnknownError} bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/tasks/list.r3"), - ghttp.RespondWithProto(200, &models.TasksResponse{Error: models.ErrUnknownError}), + ghttp.RespondWithProto(200, response.ToProto()), ), ) diff --git a/integration/update_desired_lrp_test.go b/integration/update_desired_lrp_test.go index c444972..e3f1a0e 100644 --- a/integration/update_desired_lrp_test.go +++ b/integration/update_desired_lrp_test.go @@ -35,24 +35,27 @@ var _ = Describe("update-desired-lrp", func() { BeforeEach(func() { lrpUpdate = &models.DesiredLRPUpdate{} - lrpUpdate.SetInstances(int32(5)) + instances := int32(5) + lrpUpdate.SetInstances(&instances) serverTimeout = 0 }) JustBeforeEach(func() { + request := &models.UpdateDesiredLRPRequest{ + Update: lrpUpdate, + ProcessGuid: "process-guid", + } + response := &models.DesiredLRPLifecycleResponse{ + Error: nil, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp/update"), func(w http.ResponseWriter, req *http.Request) { time.Sleep(time.Duration(serverTimeout) * time.Second) }, - ghttp.VerifyProtoRepresenting(&models.UpdateDesiredLRPRequest{ - Update: lrpUpdate, - ProcessGuid: "process-guid", - }), - ghttp.RespondWithProto(200, &models.DesiredLRPLifecycleResponse{ - Error: nil, - }), + ghttp.VerifyProtoRepresenting(request.ToProto()), + ghttp.RespondWithProto(200, response.ToProto()), ), ) }) @@ -137,15 +140,16 @@ var _ = Describe("update-desired-lrp", func() { Context("when bbs responds with non-200 status code", func() { JustBeforeEach(func() { + response := &models.DesiredLRPLifecycleResponse{ + Error: &models.Error{ + Type: models.Error_Deadlock, + Message: "deadlock detected", + }, + } bbsServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/desired_lrp/update"), - ghttp.RespondWithProto(500, &models.DesiredLRPLifecycleResponse{ - Error: &models.Error{ - Type: models.Error_Deadlock, - Message: "deadlock detected", - }, - }), + ghttp.RespondWithProto(500, response.ToProto()), ), ) })