Esempio n. 1
0
// UserHomeDir returns current user home directory including ending path separator, for example, "/Users/johndoe/" on Mac.
func UserHomeDir(t *testing.T) string {
	curUser, err := user.Current()
	if err != nil {
		t.Error(fmt.Errorf("Failed to get current user: '******'", err.Error()))
	}
	return misc.Strcat(curUser.HomeDir, string(os.PathSeparator))
}
Esempio n. 2
0
func (databaseService Service) buildRequestURL(suffixes ...string) (string, error) {
	serviceURL, err := databaseService.authenticator.GetServiceURL("database", "1")
	if err != nil {
		return "", err
	}
	urlPaths := append([]string{serviceURL}, suffixes...)
	return misc.Strcat(urlPaths...), nil
}
Esempio n. 3
0
func (blockStorageService Service) buildRequestURL(suffixes ...string) (string, error) {
	serviceURL, err := blockStorageService.serviceURL()
	if err != nil {
		return "", err
	}

	urlPaths := append([]string{serviceURL}, suffixes...)
	return misc.Strcat(urlPaths...), nil
}
func TestGetFlavorWithInvalidPayload(t *testing.T) {

	flavorID := "101"
	mockResponseObject := FlavorContainer{Flavor: sampleFlavor}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObjectAndStatus(t, tokn, testUtil.InvalidJSONPayload, mockResponseObject, misc.Strcat("/flavors/", flavorID))
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	_, err := service.Flavor(flavorID)
	if err == nil {
		t.Error(errors.New("Error: Expected error was not returned."))
	}
}
func TestGetFlavor(t *testing.T) {

	flavorID := "101"
	mockResponseObject := FlavorContainer{Flavor: sampleFlavor}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, misc.Strcat("/flavors/", flavorID))
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	result, err := service.Flavor(flavorID)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, sampleFlavor, result)
}
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 := CreateDatabaseService(apiServer.URL)
	_, err := service.Flavor(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)
	}
}