Skip to content

Commit

Permalink
Merge pull request #19 from HewlettPackard/removeNonUsefullCode
Browse files Browse the repository at this point in the history
DE9792: Removing the un-wanted code
  • Loading branch information
gandharvas authored Oct 19, 2021
2 parents 3541312 + 5471139 commit 8ddf035
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 2,937 deletions.
27 changes: 0 additions & 27 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,6 @@ func contains(haystack []string, needle string) bool {
return false
}

// parameterToString convert interface{} parameters to string, using a delimiter if format is provided.
func parameterToString(obj interface{}, collectionFormat string) string {
var delimiter string

switch collectionFormat {
case "pipes":
delimiter = "|"
case "ssv":
delimiter = " "
case "tsv":
delimiter = "\t"
case "csv":
delimiter = ","
}

if reflect.TypeOf(obj).Kind() == reflect.Slice {
return strings.Trim(strings.ReplaceAll(fmt.Sprint(obj), " ", delimiter), "[]")
}

return fmt.Sprintf("%v", obj)
}

// callAPI do the request.
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
return c.cfg.HTTPClient.Do(request)
Expand Down Expand Up @@ -346,11 +324,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error {
return err
}

// Prevent trying to import "fmt"
func reportError(format string, a ...interface{}) error {
return fmt.Errorf(format, a...)
}

// Set request body from an interface{}
func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) {
if bodyBuf == nil {
Expand Down
206 changes: 0 additions & 206 deletions pkg/client/clouds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"

consts "github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/common"
"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
Expand All @@ -20,209 +17,6 @@ type CloudsAPIService struct {
Cfg Configuration
}

/*
CloudsAPIService
Get a Specific Cloud
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc.
Passed from http.Request or context.Background().
* @param serviceInstanceID
* @param cloudID The cloud ID
*/
func (a *CloudsAPIService) GetASpecificCloud(ctx context.Context, cloudID int) (*http.Response, error) {
var (
localVarHTTPMethod = strings.ToUpper("Get")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
)

// create path and map variables
localVarPath := a.Cfg.BasePath + "/v1/zones/{cloud_id}"
localVarPath = strings.ReplaceAll(localVarPath, "{"+"cloud_id"+"}", fmt.Sprintf("%v", cloudID))

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if cloudID < 1 {
return nil, reportError("cloudID must be greater than 1")
}

// to determine the Content-Type header
localVarHTTPContentTypes := []string{}

// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}

// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}

// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}

r, err := a.Client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody,
localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return nil, err
}

localVarHTTPResponse, err := a.Client.callAPI(r)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
return localVarHTTPResponse, ParseError(localVarHTTPResponse)
}

return localVarHTTPResponse, nil
}

/*
CloudsAPIService
Get a Specific Cloud Data Store
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc.
Passed from http.Request or context.Background().
* @param serviceInstanceID
* @param cloudID The cloud ID
* @param datastoreID The cloud datastore ID
*/
func (a *CloudsAPIService) GetASpecificCloudDataStore(ctx context.Context, cloudID int,
datastoreID int) (*http.Response, error) {
var (
localVarHTTPMethod = strings.ToUpper("Get")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
)

// create path and map variables
localVarPath := a.Cfg.BasePath + "/v1/zones/{cloud_id}/data-stores/{datastore_id}"
localVarPath = strings.ReplaceAll(localVarPath, "{"+"cloud_id"+"}", fmt.Sprintf("%v", cloudID))
localVarPath = strings.ReplaceAll(localVarPath, "{"+"datastore_id"+"}", fmt.Sprintf("%v", datastoreID))

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if cloudID < 1 {
return nil, reportError("cloudID must be greater than 1")
}
if datastoreID < 1 {
return nil, reportError("datastoreID must be greater than 1")
}

// to determine the Content-Type header
localVarHTTPContentTypes := []string{}

// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}

// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}

// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}

r, err := a.Client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody,
localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return nil, err
}

localVarHTTPResponse, err := a.Client.callAPI(r)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
return localVarHTTPResponse, ParseError(localVarHTTPResponse)
}

return localVarHTTPResponse, nil
}

/*
CloudsAPIService
Get a Specific Cloud Resource Pool
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc.
Passed from http.Request or context.Background().
* @param serviceInstanceID
* @param cloudID The cloud ID
* @param funID The Cloud Resourcepool ID
*/
func (a *CloudsAPIService) GetASpecificCloudResourcePool(ctx context.Context, cloudID int,
resourcepoolID int) (*http.Response, error) {
var (
localVarHTTPMethod = strings.ToUpper("Get")
localVarPostBody interface{}
localVarFileName string
localVarFileBytes []byte
)

// create path and map variables
localVarPath := a.Cfg.BasePath + "/v1/zones/{cloud_id}/resource-pools/{resourcepool_id}"
localVarPath = strings.ReplaceAll(localVarPath, "{"+"cloud_id"+"}", fmt.Sprintf("%v", cloudID))
localVarPath = strings.ReplaceAll(localVarPath, "{"+"resourcepool_id"+"}", fmt.Sprintf("%v", resourcepoolID))

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if cloudID < 1 {
return nil, reportError("cloudID must be greater than 1")
}
if resourcepoolID < 1 {
return nil, reportError("resourcepoolID must be greater than 1")
}

// to determine the Content-Type header
localVarHTTPContentTypes := []string{}

// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}

// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}

// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}

r, err := a.Client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody,
localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return nil, err
}

localVarHTTPResponse, err := a.Client.callAPI(r)
if err != nil || localVarHTTPResponse == nil {
return localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
return localVarHTTPResponse, ParseError(localVarHTTPResponse)
}

return localVarHTTPResponse, nil
}

/*
CloudsAPIService
Get All Cloud Data Stores
Expand Down
23 changes: 0 additions & 23 deletions pkg/client/clouds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,8 @@ import (

"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/models"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)

func TestCloudsAPIService_GetASpecificCloud(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockStatusOk := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBufferString("{}")),
}

mockAPIClient := NewMockAPIClientHandler(ctrl)
mockAPIClient.EXPECT().prepareRequest(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
mockAPIClient.EXPECT().callAPI(gomock.Any()).Return(mockStatusOk, nil)
a := &CloudsAPIService{
Client: mockAPIClient,
Cfg: Configuration{},
}
_, err := a.GetASpecificCloud(context.Background(), 1)

assert.Nil(t, err)
}

func TestCloudsAPIService_GetAllCloudDataStores(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
Expand Down
Loading

0 comments on commit 8ddf035

Please sign in to comment.