func TestSuccessfulGetService(t *testing.T) { // setup testClient, testConverter, _, adapter := setup() resp := new(gomarathon.Response) resp.App = &gomarathon.Application{ID: "foo"} service := &api.Service{Id: "foo", Name: "foo"} // set expectations testClient.On("GetApp", "/foo").Return(resp) testConverter.On("convertToService", resp.App).Return(service) // call the code to be tested srvc, err := adapter.GetService("foo") // assert if expectations are met assert.NoError(t, err) assert.IsType(t, new(api.Service), srvc) assert.Equal(t, service, srvc) testClient.AssertExpectations(t) testConverter.AssertExpectations(t) }
func TestPostAction(t *testing.T) { client := new(mockClient) resp := new(gomarathon.Response) task := new(gomarathon.Task) var svc = api.Service{Name: "Foo", Command: "echo"} var ctx = NewContext() var app = setupTestApplication() app.TasksRunning = 1 deployment := createDeployment(&svc, client) task.Host = "1.2.3.4" task.Ports = []int{5555, 6666} resp.App = &app resp.Tasks = []*gomarathon.Task{task} deployment.name = "TestEmpty" client.On("GetApp", deployment.application.ID).Return(resp) postActionState(&deployment, &ctx) assert.Equal(t, OK, deployment.status.code) client.AssertExpectations(t) }
func TestSuccessfulGetServices(t *testing.T) { // setup testClient, testConverter, _, adapter := setup() resp := new(gomarathon.Response) resp.Apps = make([]*gomarathon.Application, 0) services := make([]*api.Service, 0) // set expectations testClient.On("ListApps").Return(resp) testConverter.On("convertToServices", resp.Apps).Return(services) // call the code to be tested srvcs, err := adapter.GetServices() // assert if expectations are met assert.NoError(t, err) assert.Len(t, srvcs, 0) testClient.AssertExpectations(t) testConverter.AssertExpectations(t) }