Пример #1
0
func TestGetFlavorWithInvalidPayload(t *testing.T) {
	flavorID := "101"
	mockResponseObject := FlavorDetailContainer{FlavorDetail: sampleFlavorDetail}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObjectAndStatus(t, tokn, testUtil.InvalidJSONPayload, mockResponseObject, misc.Strcat("/flavors/", flavorID))
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	_, err := service.FlavorDetail(flavorID)
	if err == nil {
		t.Error(errors.New("Error: Expected error was not returned."))
	}
}
Пример #2
0
func TestGetFlavorsInvalid(t *testing.T) {
	mockResponseObject := FlavorsContainer{
		Flavors: []Flavor{sampleFlavor, sampleFlavor2}}

	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObjectAndStatus(t, tokn, testUtil.InvalidJSONPayload, mockResponseObject, "/flavors?limit=21")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	_, err := service.Flavors()
	if err == nil {
		t.Error(errors.New("Error: Expected error was not returned."))
	}
}
Пример #3
0
func TestGetUsersInvalid(t *testing.T) {

	mockResponseObject := UsersContainer{
		Users: []User{sampleUser1, sampleUser2}}

	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObjectAndStatus(t, tokn, testUtil.InvalidJSONPayload, mockResponseObject, "/users")
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	_, err := service.Users(instanceID)
	if err == nil {
		t.Error(errors.New("Error: Expected error was not returned."))
	}
}
Пример #4
0
func TestGetFlavorWithInvalidFlavorID(t *testing.T) {
	invalidFlavorID := "999"
	mockResponseObject := FlavorContainer{Flavor: sampleFlavor}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObjectAndStatus(t, tokn, http.StatusNotFound, mockResponseObject, misc.Strcat("/flavors/", invalidFlavorID))
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	_, err := service.FlavorDetail(invalidFlavorID)
	if err == nil {
		t.Error(errors.New("Error: Expected error was not returned."))
	}
	status, ok := err.(misc.HTTPStatus)
	if ok {
		testUtil.Equals(t, http.StatusNotFound, status.StatusCode)
	}
}