From 6a788340b6b8138f37083d7b527c3cda39166b93 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Mon, 4 Mar 2024 03:38:53 -0500 Subject: [PATCH 01/24] Update workflows to allow manual trigger --- .github/workflows/actions.yml | 5 +++-- .github/workflows/linters.yaml | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 6b29448..813c993 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -1,9 +1,10 @@ name: Workflow on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] + workflow_dispatch: jobs: code-check: name: Check Go formatting, linting, vetting diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index e7aad32..d1eb955 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -5,6 +5,7 @@ on: branches: [main] pull_request: branches: ["**"] + workflow_dispatch: permissions: contents: read @@ -14,17 +15,17 @@ jobs: name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" cache: false - name: Checkout the code - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v4.1.0 - name: Vendor packages run: | go mod vendor - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: - version: v1.53 + version: latest skip-cache: true From bc619c83d1586235a8a1e7e5edd11f7ec8d80499 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Mon, 4 Mar 2024 03:39:34 -0500 Subject: [PATCH 02/24] Fix gofumpt warnings --- api.go | 26 +++++------- api/api.go | 41 +++++++++---------- api/api_logging.go | 9 ++-- api_test.go | 3 +- deploy.go | 37 +---------------- deploy_test.go | 6 --- device.go | 11 ++--- drv_cfg.go | 4 +- fault_set_test.go | 4 -- fs.go | 4 -- fs_test.go | 19 ++------- instance.go | 17 ++++---- inttests/device_test.go | 4 -- inttests/fs_test.go | 7 +--- inttests/init_client.go | 1 - inttests/nfs_export_test.go | 8 ++-- inttests/nfs_test.go | 3 +- inttests/protectiondomain_test.go | 1 - inttests/replication_test.go | 1 - inttests/sdc_test.go | 3 -- inttests/sds_test.go | 2 - inttests/storagepool_test.go | 68 +++++++++++++++---------------- inttests/system_limit_test.go | 1 - inttests/tree_quota_test.go | 16 ++++---- inttests/user_test.go | 6 +-- inttests/volume_test.go | 6 +-- nfs.go | 7 ---- nfs_export.go | 2 - nfs_export_test.go | 9 ++-- nfs_test.go | 12 ++---- protectiondomain.go | 6 ++- sdc.go | 11 ++--- sdc_test.go | 13 ++---- sds.go | 9 ++-- service.go | 8 +--- snapshot_policy_test.go | 1 - sso_user.go | 1 - storagepool.go | 17 ++------ system.go | 6 ++- system_limit.go | 3 -- system_limit_test.go | 2 +- system_test.go | 10 ----- tree_quota_test.go | 7 +--- types/v1/types.go | 14 +++---- user.go | 5 +-- volume.go | 9 ++-- vtree_test.go | 2 - 47 files changed, 157 insertions(+), 305 deletions(-) diff --git a/api.go b/api.go index 1bc98bb..08e2bd9 100644 --- a/api.go +++ b/api.go @@ -53,8 +53,7 @@ type Client struct { } // Cluster defines struct for Cluster -type Cluster struct { -} +type Cluster struct{} // ConfigConnect defines struct for ConfigConnect type ConfigConnect struct { @@ -73,7 +72,6 @@ type ClientPersistent struct { // GetVersion returns version func (c *Client) GetVersion() (string, error) { - resp, err := c.api.DoAndGetResponseBody( context.Background(), http.MethodGet, "/api/version", nil, nil, c.configConnect.Version) if err != nil { @@ -108,7 +106,6 @@ func (c *Client) GetVersion() (string, error) { // updateVersion updates version func (c *Client) updateVersion() error { - version, err := c.GetVersion() if err != nil { return err @@ -132,7 +129,6 @@ func updateHeaders(version string) { // Authenticate controls authentication to client func (c *Client) Authenticate(configConnect *ConfigConnect) (Cluster, error) { - configConnect.Version = c.configConnect.Version c.configConnect = configConnect @@ -187,8 +183,8 @@ func basicAuth(username, password string) string { func (c *Client) getJSONWithRetry( method, uri string, - body, resp interface{}) error { - + body, resp interface{}, +) error { headers := make(map[string]string, 2) headers[api.HeaderKeyAccept] = accHeader headers[api.HeaderKeyContentType] = conHeader @@ -240,8 +236,8 @@ func extractString(resp *http.Response) (string, error) { func (c *Client) getStringWithRetry( method, uri string, - body interface{}) (string, error) { - + body interface{}, +) (string, error) { headers := make(map[string]string, 2) headers[api.HeaderKeyAccept] = accHeader headers[api.HeaderKeyContentType] = conHeader @@ -333,8 +329,8 @@ func NewClientWithArgs( version string, timeout int64, insecure, - useCerts bool) (client *Client, err error) { - + useCerts bool, +) (client *Client, err error) { if showHTTP { debug = true } @@ -401,8 +397,8 @@ func withFields(fields map[string]interface{}, message string) error { } func withFieldsE( - fields map[string]interface{}, message string, inner error) error { - + fields map[string]interface{}, message string, inner error, +) error { if fields == nil { fields = make(map[string]interface{}) } @@ -429,8 +425,8 @@ func withFieldsE( func doLog( l func(args ...interface{}), - msg string) { - + msg string, +) { if debug { l(msg) } diff --git a/api/api.go b/api/api.go index 3c4d339..b3cc665 100644 --- a/api/api.go +++ b/api/api.go @@ -50,7 +50,6 @@ var ( // Client is an API client. type Client interface { - // Do sends an HTTP request to the API. Do( ctx context.Context, @@ -139,8 +138,8 @@ func New( ctx context.Context, host string, opts ClientOptions, - debug bool) (Client, error) { - + debug bool, +) (Client, error) { if host == "" { return nil, errNewClient } @@ -193,8 +192,8 @@ func (c *client) Get( ctx context.Context, path string, headers map[string]string, - resp interface{}) error { - + resp interface{}, +) error { return c.DoWithHeaders( ctx, http.MethodGet, path, headers, nil, resp, "") } @@ -203,8 +202,8 @@ func (c *client) Post( ctx context.Context, path string, headers map[string]string, - body, resp interface{}) error { - + body, resp interface{}, +) error { return c.DoWithHeaders( ctx, http.MethodPost, path, headers, body, resp, "") } @@ -213,8 +212,8 @@ func (c *client) Put( ctx context.Context, path string, headers map[string]string, - body, resp interface{}) error { - + body, resp interface{}, +) error { return c.DoWithHeaders( ctx, http.MethodPut, path, headers, body, resp, "") } @@ -223,8 +222,8 @@ func (c *client) Delete( ctx context.Context, path string, headers map[string]string, - resp interface{}) error { - + resp interface{}, +) error { return c.DoWithHeaders( ctx, http.MethodDelete, path, headers, nil, resp, "") } @@ -232,8 +231,8 @@ func (c *client) Delete( func (c *client) Do( ctx context.Context, method, path string, - body, resp interface{}) error { - + body, resp interface{}, +) error { return c.DoWithHeaders(ctx, method, path, nil, body, resp, "") } @@ -249,8 +248,8 @@ func (c *client) DoWithHeaders( ctx context.Context, method, uri string, headers map[string]string, - body, resp interface{}, version string) error { - + body, resp interface{}, version string, +) error { res, err := c.DoAndGetResponseBody( ctx, method, uri, headers, body, version) if err != nil { @@ -289,8 +288,8 @@ func (c *client) DoAndGetResponseBody( ctx context.Context, method, uri string, headers map[string]string, - body interface{}, version string) (*http.Response, error) { - + body interface{}, version string, +) (*http.Response, error) { var ( err error req *http.Request @@ -388,7 +387,6 @@ func (c *client) DoAndGetResponseBody( } else { req.SetBasicAuth("", c.token) } - } } else { @@ -423,10 +421,9 @@ func (c *client) GetToken() string { } func (c *client) ParseJSONError(r *http.Response) error { - jsonError := &types.Error{} - //Starting in 4.0, response may be in html; so we cannot always use a json decoder + // Starting in 4.0, response may be in html; so we cannot always use a json decoder if strings.Contains(r.Header.Get("Content-Type"), "html") { jsonError.HTTPStatusCode = r.StatusCode jsonError.Message = r.Status @@ -447,8 +444,8 @@ func (c *client) ParseJSONError(r *http.Response) error { func (c *client) doLog( l func(args ...interface{}), - msg string) { - + msg string, +) { if c.debug { l(msg) } diff --git a/api/api_logging.go b/api/api_logging.go index e8f012c..02d1c4c 100644 --- a/api/api_logging.go +++ b/api/api_logging.go @@ -32,8 +32,8 @@ func isBinOctetBody(h http.Header) bool { func logRequest( ctx context.Context, req *http.Request, - lf func(func(args ...interface{}), string)) { - + lf func(func(args ...interface{}), string), +) { log.SetLevel(log.DebugLevel) w := &bytes.Buffer{} @@ -44,7 +44,6 @@ func logRequest( fmt.Fprintln(w, " -------------------------") buf, err := dumpRequest(req, !isBinOctetBody(req.Header)) - if err != nil { return } @@ -61,8 +60,8 @@ func logRequest( func logResponse( ctx context.Context, res *http.Response, - lf func(func(args ...interface{}), string)) { - + lf func(func(args ...interface{}), string), +) { log.SetLevel(log.DebugLevel) w := &bytes.Buffer{} diff --git a/api_test.go b/api_test.go index 648d447..c073e92 100644 --- a/api_test.go +++ b/api_test.go @@ -122,7 +122,6 @@ func TestClientLogin(t *testing.T) { default: t.Fatal("Expecting endpoint /api/login got", req.RequestURI) } - }, )) defer server.Close() @@ -167,7 +166,7 @@ func (s stubTypeWithMetaData) MetaData() http.Header { } func Test_addMetaData(t *testing.T) { - var tests = []struct { + tests := []struct { name string givenHeader map[string]string expectedHeader map[string]string diff --git a/deploy.go b/deploy.go index 4d3bcd1..7c4d47d 100644 --- a/deploy.go +++ b/deploy.go @@ -43,7 +43,6 @@ type GatewayClient struct { // NewGateway returns a new gateway client. func NewGateway(host string, username, password string, insecure, useCerts bool) (*GatewayClient, error) { - if host == "" { return nil, errNewClient } @@ -86,7 +85,7 @@ func NewGateway(host string, username, password string, insecure, useCerts bool) if version == "3.5" { gc.version = version - //No need to create token + // No need to create token } else { bodyData := map[string]interface{}{ "username": username, @@ -150,7 +149,6 @@ func NewGateway(host string, username, password string, insecure, useCerts bool) // GetVersion returns version func (gc *GatewayClient) GetVersion() (string, error) { - req, httpError := http.NewRequest("GET", gc.host+"/api/version", nil) if httpError != nil { return "", httpError @@ -198,7 +196,6 @@ func (gc *GatewayClient) UploadPackages(filePaths []string) (*types.GatewayRespo for _, filePath := range filePaths { info, err := os.Stat(filePath) - if err != nil { return &gatewayResponse, err } @@ -254,7 +251,6 @@ func (gc *GatewayClient) UploadPackages(filePaths []string) (*types.GatewayRespo responseString, _ := extractString(response) err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Uploading Package: %s", err) } @@ -328,7 +324,6 @@ func (gc *GatewayClient) ParseCSV(filePath string) (*types.GatewayResponse, erro var parseCSVData map[string]interface{} err := json.Unmarshal([]byte(responseString), &parseCSVData) - if err != nil { return &gatewayResponse, fmt.Errorf("Error While Parsing Response Data For CSV: %s", err) } @@ -348,7 +343,6 @@ func (gc *GatewayClient) ParseCSV(filePath string) (*types.GatewayResponse, erro } err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error While Parsing Response Data For CSV: %s", err) } @@ -358,7 +352,6 @@ func (gc *GatewayClient) ParseCSV(filePath string) (*types.GatewayResponse, erro // GetPackageDetails used for get package details func (gc *GatewayClient) GetPackageDetails() ([]*types.PackageDetails, error) { - var packageParam []*types.PackageDetails req, httpError := http.NewRequest("GET", gc.host+"/im/types/installationPackages/instances?onlyLatest=false&_search=false", nil) @@ -401,7 +394,6 @@ func (gc *GatewayClient) GetPackageDetails() ([]*types.PackageDetails, error) { } err := json.Unmarshal([]byte(responseString), &packageParam) - if err != nil { return packageParam, fmt.Errorf("Error For Get Package Details: %s", err) } @@ -446,7 +438,6 @@ func (gc *GatewayClient) ValidateMDMDetails(mdmTopologyParam []byte) (*types.Gat if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error Validating MDM Details: %s", err) } @@ -468,7 +459,6 @@ func (gc *GatewayClient) ValidateMDMDetails(mdmTopologyParam []byte) (*types.Gat var mdmTopologyDetails types.MDMTopologyDetails err := json.Unmarshal([]byte(responseString), &mdmTopologyDetails) - if err != nil { return &gatewayResponse, fmt.Errorf("Error Validating MDM Details: %s", err) } @@ -514,7 +504,6 @@ func (gc *GatewayClient) GetClusterDetails(mdmTopologyParam []byte, requireJSONO if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error Validating MDM Details: %s", err) } @@ -544,7 +533,6 @@ func (gc *GatewayClient) GetClusterDetails(mdmTopologyParam []byte, requireJSONO var mdmTopologyDetails types.MDMTopologyDetails err := json.Unmarshal([]byte(responseString), &mdmTopologyDetails) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Get Cluster Details: %s", err) } @@ -558,7 +546,6 @@ func (gc *GatewayClient) GetClusterDetails(mdmTopologyParam []byte, requireJSONO // DeletePackage used for delete packages from gateway server func (gc *GatewayClient) DeletePackage(packageName string) (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse req, httpError := http.NewRequest("DELETE", gc.host+"/im/types/installationPackages/instances/actions/delete::"+packageName, nil) @@ -591,7 +578,6 @@ func (gc *GatewayClient) DeletePackage(packageName string) (*types.GatewayRespon if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Delete Package: %s", err) } @@ -613,7 +599,6 @@ func (gc *GatewayClient) DeletePackage(packageName string) (*types.GatewayRespon // BeginInstallation used for start installation func (gc *GatewayClient) BeginInstallation(jsonStr, mdmUsername, mdmPassword, liaPassword string, allowNonSecureCommunicationWithMdm, allowNonSecureCommunicationWithLia, disableNonMgmtComponentsAuth, expansion bool) (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse mapData, jsonParseError := jsonToMap(jsonStr) @@ -685,7 +670,6 @@ func (gc *GatewayClient) BeginInstallation(jsonStr, mdmUsername, mdmPassword, li } err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Begin Installation: %s", err) } @@ -700,7 +684,6 @@ func (gc *GatewayClient) BeginInstallation(jsonStr, mdmUsername, mdmPassword, li // MoveToNextPhase used for move to next phases in installation func (gc *GatewayClient) MoveToNextPhase() (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse req, httpError := http.NewRequest("POST", gc.host+"/im/types/ProcessPhase/actions/moveToNextPhase", nil) @@ -734,7 +717,6 @@ func (gc *GatewayClient) MoveToNextPhase() (*types.GatewayResponse, error) { if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Move To Next Phase: %s", err) } @@ -756,7 +738,6 @@ func (gc *GatewayClient) MoveToNextPhase() (*types.GatewayResponse, error) { // RetryPhase used for re run to failed phases in installation func (gc *GatewayClient) RetryPhase() (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse req, httpError := http.NewRequest("POST", gc.host+"/im/types/Command/instances/actions/retry/", nil) @@ -790,7 +771,6 @@ func (gc *GatewayClient) RetryPhase() (*types.GatewayResponse, error) { if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Retry Phase: %s", err) } @@ -812,7 +792,6 @@ func (gc *GatewayClient) RetryPhase() (*types.GatewayResponse, error) { // AbortOperation used for abort installation operation func (gc *GatewayClient) AbortOperation() (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse req, httpError := http.NewRequest("POST", gc.host+"/im/types/Command/instances/actions/abort", nil) @@ -846,7 +825,6 @@ func (gc *GatewayClient) AbortOperation() (*types.GatewayResponse, error) { if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Abort Operation: %s", err) } @@ -868,7 +846,6 @@ func (gc *GatewayClient) AbortOperation() (*types.GatewayResponse, error) { // ClearQueueCommand used for clear all commands in queue func (gc *GatewayClient) ClearQueueCommand() (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse req, httpError := http.NewRequest("POST", gc.host+"/im/types/Command/instances/actions/clear", nil) @@ -902,7 +879,6 @@ func (gc *GatewayClient) ClearQueueCommand() (*types.GatewayResponse, error) { if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Clear Queue Commands: %s", err) } @@ -924,7 +900,6 @@ func (gc *GatewayClient) ClearQueueCommand() (*types.GatewayResponse, error) { // MoveToIdlePhase used for move gateway installer to idle state func (gc *GatewayClient) MoveToIdlePhase() (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse req, httpError := http.NewRequest("POST", gc.host+"/im/types/ProcessPhase/actions/moveToIdlePhase", nil) @@ -958,7 +933,6 @@ func (gc *GatewayClient) MoveToIdlePhase() (*types.GatewayResponse, error) { if httpResp.StatusCode != 200 { err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Move To Ideal Phase: %s", err) } @@ -980,7 +954,6 @@ func (gc *GatewayClient) MoveToIdlePhase() (*types.GatewayResponse, error) { // GetInQueueCommand used for get in queue commands func (gc *GatewayClient) GetInQueueCommand() ([]types.MDMQueueCommandDetails, error) { - var mdmQueueCommandDetails []types.MDMQueueCommandDetails req, httpError := http.NewRequest("GET", gc.host+"/im/types/Command/instances", nil) @@ -1022,7 +995,6 @@ func (gc *GatewayClient) GetInQueueCommand() ([]types.MDMQueueCommandDetails, er var queueCommandDetails map[string][]interface{} err := json.Unmarshal([]byte(responseString), &queueCommandDetails) - if err != nil { return mdmQueueCommandDetails, fmt.Errorf("Error For Get In Queue Commands: %s", err) } @@ -1052,7 +1024,6 @@ func (gc *GatewayClient) CheckForCompletionQueueCommands(currentPhase string) (* var gatewayResponse types.GatewayResponse mdmQueueCommandDetails, err := gc.GetInQueueCommand() - if err != nil { return &gatewayResponse, err } @@ -1062,7 +1033,6 @@ func (gc *GatewayClient) CheckForCompletionQueueCommands(currentPhase string) (* var errMsg bytes.Buffer for _, mdmQueueCommandDetail := range mdmQueueCommandDetails { - if currentPhase == mdmQueueCommandDetail.AllowedPhase && (mdmQueueCommandDetail.CommandState == "pending" || mdmQueueCommandDetail.CommandState == "running") { checkCompleted = "Running" break @@ -1085,7 +1055,6 @@ func (gc *GatewayClient) CheckForCompletionQueueCommands(currentPhase string) (* // UninstallCluster used for uninstallation of cluster func (gc *GatewayClient) UninstallCluster(jsonStr, mdmUsername, mdmPassword, liaPassword string, allowNonSecureCommunicationWithMdm, allowNonSecureCommunicationWithLia, disableNonMgmtComponentsAuth, expansion bool) (*types.GatewayResponse, error) { - var gatewayResponse types.GatewayResponse clusterData, jsonParseError := jsonToMap(jsonStr) @@ -1140,7 +1109,6 @@ func (gc *GatewayClient) UninstallCluster(jsonStr, mdmUsername, mdmPassword, lia } err := json.Unmarshal([]byte(responseString), &gatewayResponse) - if err != nil { return &gatewayResponse, fmt.Errorf("Error For Uninstall Cluster: %s", err) } @@ -1218,7 +1186,6 @@ func storeCookie(header http.Header, host string) error { } func setCookie(header http.Header, host string) error { - if globalCookie != "" { header.Set("Cookie", "LEGACYGWCOOKIE="+strings.ReplaceAll(globalCookie, "_", "|")) } else { @@ -1265,7 +1232,7 @@ func writeConfig(config *CookieConfig) error { return err } // #nosec G306 - err = ioutil.WriteFile(configFile, data, 0644) + err = ioutil.WriteFile(configFile, data, 0o644) if err != nil { return err } diff --git a/deploy_test.go b/deploy_test.go index e0f86e1..68e015c 100644 --- a/deploy_test.go +++ b/deploy_test.go @@ -38,7 +38,6 @@ func TestMoveToNextPhase(t *testing.T) { for _, tc := range cases { tc := tc t.Run("", func(ts *testing.T) { - GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) @@ -54,7 +53,6 @@ func TestMoveToNextPhase(t *testing.T) { } } } - }) } } @@ -85,7 +83,6 @@ func TestUninstallCluster(t *testing.T) { for _, tc := range cases { tc := tc t.Run("", func(ts *testing.T) { - GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) @@ -101,7 +98,6 @@ func TestUninstallCluster(t *testing.T) { } } } - }) } } @@ -128,7 +124,6 @@ func TestGetClusterDetails(t *testing.T) { for _, tc := range cases { tc := tc t.Run("", func(ts *testing.T) { - GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) @@ -159,7 +154,6 @@ func TestGetClusterDetails(t *testing.T) { } } } - }) } } diff --git a/device.go b/device.go index 8fd9e9f..e92b60f 100644 --- a/device.go +++ b/device.go @@ -79,7 +79,8 @@ func (sp *StoragePool) GetDevice() ([]types.Device, error) { // FindDevice returns a Device func (sp *StoragePool) FindDevice( - field, value string) (*types.Device, error) { + field, value string, +) (*types.Device, error) { defer TimeSpent("FindDevice", time.Now()) devices, err := sp.GetDevice() @@ -117,7 +118,8 @@ func (sds *Sds) GetDevice() ([]types.Device, error) { // FindDevice returns a Device func (sds *Sds) FindDevice( - field, value string) (*types.Device, error) { + field, value string, +) (*types.Device, error) { defer TimeSpent("FindDevice", time.Now()) devices, err := sds.GetDevice() @@ -138,7 +140,6 @@ func (sds *Sds) FindDevice( // GetAllDevice returns all device in the system func (system *System) GetAllDevice() ([]types.Device, error) { - defer TimeSpent("GetAllDevice", time.Now()) path := "/api/types/Device/instances" @@ -155,7 +156,8 @@ func (system *System) GetAllDevice() ([]types.Device, error) { // GetDeviceByField returns a Device list filter by the field func (system *System) GetDeviceByField( - field, value string) ([]types.Device, error) { + field, value string, +) ([]types.Device, error) { defer TimeSpent("GetDeviceByField", time.Now()) devices, err := system.GetAllDevice() @@ -179,7 +181,6 @@ func (system *System) GetDeviceByField( // GetDevice returns a device using Device ID func (system *System) GetDevice(id string) (*types.Device, error) { - defer TimeSpent("GetDevice", time.Now()) path := fmt.Sprintf( diff --git a/drv_cfg.go b/drv_cfg.go index ef779e9..47f66d0 100644 --- a/drv_cfg.go +++ b/drv_cfg.go @@ -13,6 +13,7 @@ package goscaleio import ( + "encoding/hex" "fmt" "os" "os/exec" @@ -22,8 +23,6 @@ import ( "syscall" "unsafe" - "encoding/hex" - "github.com/google/uuid" ) @@ -103,7 +102,6 @@ func DrvCfgQueryGUID() (string, error) { // DrvCfgQueryRescan preforms a rescan func DrvCfgQueryRescan() (string, error) { - f, err := os.Open(SDCDevice) if err != nil { return "", fmt.Errorf("Powerflex SDC is not installed") diff --git a/fault_set_test.go b/fault_set_test.go index 4f54f64..fb11045 100644 --- a/fault_set_test.go +++ b/fault_set_test.go @@ -129,7 +129,6 @@ func TestModifyFaultSetName(t *testing.T) { } cases := []testCase{ { - id: ID, name: "renameFaultSet", expected: nil, @@ -177,19 +176,16 @@ func TestModifyFaultPerfProfile(t *testing.T) { } cases := []testCase{ { - id: ID, perfProfile: "Compact", expected: nil, }, { - id: ID, perfProfile: "HighPerformance", expected: nil, }, { - id: ID, perfProfile: "Invalid", expected: errors.New("perfProfile should get one of the following values: Compact, HighPerformance, but its value is Invalid."), diff --git a/fs.go b/fs.go index fba250f..f90dbcc 100644 --- a/fs.go +++ b/fs.go @@ -55,9 +55,7 @@ func (s *System) GetFileSystemByIDName(id string, name string) (*types.FileSyste defer TimeSpent("GetFileSystemByIDName", time.Now()) if id == "" && name == "" { - return nil, errors.New("file system name or ID is mandatory, please enter a valid value") - } else if id != "" { path := fmt.Sprintf("/rest/v1/file-systems/%v?select=*", id) var fs types.FileSystem @@ -83,7 +81,6 @@ func (s *System) GetFileSystemByIDName(id string, name string) (*types.FileSyste return nil, errors.New("couldn't find file system by name") } - } // CreateFileSystem creates a file system @@ -199,5 +196,4 @@ func (s *System) ModifyFileSystem(modifyFsParam *types.FSModify, id string) erro } return nil - } diff --git a/fs_test.go b/fs_test.go index c6bbc55..a9029c1 100644 --- a/fs_test.go +++ b/fs_test.go @@ -164,12 +164,12 @@ func TestGetFileSystemByIDName(t *testing.T) { }, } - var testCaseFSNames = map[string]string{ + testCaseFSNames := map[string]string{ "success": "fs-test-2", "not found": "fs-test-3", } - var testCaseFSIds = map[string]string{ + testCaseFSIds := map[string]string{ "success": "64366a19-54e8-1544-f3d7-2a50fb1ccff3", "not found": "6436aa58-e6a1-a4e2-de7b-2a50fb1ccff3", } @@ -243,7 +243,6 @@ func TestCreateFileSystem(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-systems") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -311,7 +310,6 @@ func TestCreateFileSystem(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } @@ -340,7 +338,6 @@ func TestCreateFileSystemSnapshot(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-systems/%v/snapshot", "64366a19-54e8-1544-f3d7-2a50fb1ccff3") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -407,7 +404,6 @@ func TestCreateFileSystemSnapshot(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } @@ -436,7 +432,6 @@ func TestGetFsSnapshotsByVolumeID(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := "/rest/v1/file-systems" var resp []types.FileSystem @@ -465,7 +460,6 @@ func TestGetFsSnapshotsByVolumeID(t *testing.T) { t.Fatal(err) } fmt.Fprintln(w, string(respData)) - })) return ts, check(hasNoError, checkResp(len(resp))) }, @@ -509,7 +503,6 @@ func TestGetFsSnapshotsByVolumeID(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } @@ -538,7 +531,6 @@ func TestRestoreFileSystemFromSnapshot(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "successNoContent": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-systems/%v/restore", "64366a19-54e8-1544-f3d7-2a50fb1ccff3") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -556,7 +548,6 @@ func TestRestoreFileSystemFromSnapshot(t *testing.T) { }, "successWithContent": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-systems/%v/restore", "64366a19-54e8-1544-f3d7-2a50fb1ccff3") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -631,7 +622,7 @@ func TestRestoreFileSystemFromSnapshot(t *testing.T) { } fsID := "64366a19-54e8-1544-f3d7-2a50fb1ccff3" - var restoreSnapshotRequest = new(types.RestoreFsSnapParam) + restoreSnapshotRequest := new(types.RestoreFsSnapParam) if name == "successWithContent" { restoreSnapshotRequest = &types.RestoreFsSnapParam{ SnapshotID: "64366a19-54e8-1544-f3d7-2a50fb1ccdd3", @@ -641,19 +632,17 @@ func TestRestoreFileSystemFromSnapshot(t *testing.T) { restoreSnapshotRequest = &types.RestoreFsSnapParam{ SnapshotID: "64366a19-54e8-1544-f3d7-2a50fb1ccdd3", } - } resp, err := s.RestoreFileSystemFromSnapshot(restoreSnapshotRequest, fsID) for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } -func TestDeleteFileSystem(t *testing.T) { +func TestDeleteFileSystem(t *testing.T) { name := "new-fs" svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/instance.go b/instance.go index 62e2f5d..f619e41 100644 --- a/instance.go +++ b/instance.go @@ -52,7 +52,8 @@ func (c *Client) GetInstance(systemhref string) ([]*types.System, error) { // GetVolume returns a volume func (c *Client) GetVolume( volumehref, volumeid, ancestorvolumeid, volumename string, - getSnapshots bool) ([]*types.Volume, error) { + getSnapshots bool, +) ([]*types.Volume, error) { defer TimeSpent("GetVolume", time.Now()) var ( @@ -86,7 +87,6 @@ func (c *Client) GetVolume( } else { err = c.getJSONWithRetry( http.MethodGet, path, nil, volume) - } if err != nil { return nil, err @@ -129,7 +129,8 @@ func (c *Client) FindVolumeID(volumename string) (string, error) { // CreateVolume creates a volume func (c *Client) CreateVolume( volume *types.VolumeParam, - storagePoolName, protectionDomain string) (*types.VolumeResp, error) { + storagePoolName, protectionDomain string, +) (*types.VolumeResp, error) { defer TimeSpent("CreateVolume", time.Now()) path := "/api/types/Volume/instances" @@ -154,7 +155,8 @@ func (c *Client) CreateVolume( // GetStoragePool returns a storagepool func (c *Client) GetStoragePool( - storagepoolhref string) ([]*types.StoragePool, error) { + storagepoolhref string, +) ([]*types.StoragePool, error) { defer TimeSpent("GetStoragePool", time.Now()) var ( @@ -183,7 +185,8 @@ func (c *Client) GetStoragePool( // FindStoragePool returns a StoragePool func (c *Client) FindStoragePool( - id, name, href, protectionDomain string) (*types.StoragePool, error) { + id, name, href, protectionDomain string, +) (*types.StoragePool, error) { defer TimeSpent("FindStoragePool", time.Now()) storagePools, err := c.GetStoragePool(href) @@ -237,7 +240,8 @@ func (c *Client) FindSnapshotPolicyID(spname string) (string, error) { // GetSnapshotPolicy returns a list of snapshot policy func (c *Client) GetSnapshotPolicy( - spname, spid string) ([]*types.SnapshotPolicy, error) { + spname, spid string, +) ([]*types.SnapshotPolicy, error) { defer TimeSpent("GetSnapshotPolicy", time.Now()) var ( @@ -269,7 +273,6 @@ func (c *Client) GetSnapshotPolicy( } else { err = c.getJSONWithRetry( http.MethodGet, path, nil, sp) - } if err != nil { return nil, err diff --git a/inttests/device_test.go b/inttests/device_test.go index f006a9b..78ab746 100644 --- a/inttests/device_test.go +++ b/inttests/device_test.go @@ -44,7 +44,6 @@ func getAllDevices(t *testing.T) []*goscaleio.Device { assert.Equal(t, outDevice.Device.ID, tempDevice.Device.ID) } return allDevice - } func getAllDevicesFromSystem(t *testing.T) []goscaleio.Device { @@ -87,7 +86,6 @@ func getAllSdsDevices(t *testing.T) []*goscaleio.Device { assert.Equal(t, outDevice.Device.ID, tempDevice.Device.ID) } return allDevice - } // TestGetDevices will return all Device instances @@ -181,7 +179,6 @@ func TestAddDeviceInvalid(t *testing.T) { deviceID, err := pool.AttachDevice(dev) assert.NotNil(t, err) assert.Equal(t, "", deviceID) - } func getSdsID() string { @@ -383,7 +380,6 @@ func TestDeviceUpdateOriginalPathways(t *testing.T) { } func TestGetDeviceByDeviceID(t *testing.T) { - system := getSystem() device, _ := system.GetDevice("c7fc68a200000000") diff --git a/inttests/fs_test.go b/inttests/fs_test.go index 009f0b3..6dff567 100644 --- a/inttests/fs_test.go +++ b/inttests/fs_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/dell/goscaleio" - //log "github.com/sirupsen/logrus" + // log "github.com/sirupsen/logrus" types "github.com/dell/goscaleio/types/v1" "github.com/stretchr/testify/assert" ) @@ -123,7 +123,6 @@ func TestCreateFileSystemSnapshot(t *testing.T) { assert.Nil(t, err) err = system.DeleteFileSystem(fs.Name) assert.Nil(t, err) - } func TestRestoreFileSystemSnapshot(t *testing.T) { @@ -207,7 +206,6 @@ func TestRestoreFileSystemSnapshot(t *testing.T) { assert.Nil(t, err) err = system.DeleteFileSystem(fs.Name) assert.Nil(t, err) - } func TestGetFsSnapshotsByVolumeID(t *testing.T) { @@ -275,7 +273,6 @@ func TestGetFsSnapshotsByVolumeID(t *testing.T) { // TestGetFileSystemByIDName will return specific filesystem by name or ID func TestGetFileSystemByIDName(t *testing.T) { - system := getSystem() assert.NotNil(t, system) @@ -367,7 +364,6 @@ func TestCreateDeleteFileSystem(t *testing.T) { // delete the file system err = system.DeleteFileSystem(fsName) assert.NotNil(t, err) - } // TestModifyFileSystem attempts to create then delete a file system @@ -423,5 +419,4 @@ func TestModifyFileSystem(t *testing.T) { // negative case err = system.ModifyFileSystem(modifyParam, "") assert.NotNil(t, err) - } diff --git a/inttests/init_client.go b/inttests/init_client.go index 1a0ac0b..b159b61 100644 --- a/inttests/init_client.go +++ b/inttests/init_client.go @@ -101,7 +101,6 @@ func initGatewayClient() { if err != nil { panic(err) } - } func init() { diff --git a/inttests/nfs_export_test.go b/inttests/nfs_export_test.go index 66827dd..16ff2ab 100644 --- a/inttests/nfs_export_test.go +++ b/inttests/nfs_export_test.go @@ -53,6 +53,7 @@ func TestNFSExportByIDName(t *testing.T) { assert.Equal(t, nfsName, nfs.Name) } } + func TestNFSExportByIDNameInvalid(t *testing.T) { nfs, err := C.GetNFSExportByIDName(invalidIdentifier, "") assert.NotNil(t, err) @@ -80,7 +81,7 @@ func TestCreateModifyDeleteNFSExport(t *testing.T) { Path: "/" + filesystemname, } - //create nfs export + // create nfs export nfs, err := C.CreateNFSExport(nfsexport) fsID := nfs.ID assert.Nil(t, err) @@ -90,15 +91,14 @@ func TestCreateModifyDeleteNFSExport(t *testing.T) { nfs, err = C.CreateNFSExport(nfsexport) assert.NotNil(t, err) - //Modify NFS export proprties + // Modify NFS export proprties nfsexportmodify := &types.NFSExportModify{ Description: nfsmodify, AddReadWriteRootHosts: []string{"192.168.100.10", "192.168.100.11"}, } err = C.ModifyNFSExport(nfsexportmodify, fsID) - //delete the NFS export + // delete the NFS export err = C.DeleteNFSExport(fsID) assert.Nil(t, err) - } diff --git a/inttests/nfs_test.go b/inttests/nfs_test.go index a75a20f..fdfbd4d 100644 --- a/inttests/nfs_test.go +++ b/inttests/nfs_test.go @@ -73,8 +73,8 @@ func TestGetNasByIDNameInvalid(t *testing.T) { nasName, err := system.GetNASByIDName("", invalidIdentifier) assert.NotNil(t, err) assert.Nil(t, nasName) - } + func TestCreateDeleteNAS(t *testing.T) { system := getSystem() assert.NotNil(t, system) @@ -109,7 +109,6 @@ func TestCreateDeleteNAS(t *testing.T) { // try to delete non-existent NAS Server err = system.DeleteNAS(nasID.ID) assert.NotNil(t, err) - } func TestGetFileInterfaceById(t *testing.T) { diff --git a/inttests/protectiondomain_test.go b/inttests/protectiondomain_test.go index 97855b2..f4e1af2 100644 --- a/inttests/protectiondomain_test.go +++ b/inttests/protectiondomain_test.go @@ -164,7 +164,6 @@ func TestCreateDeleteProtectionDomain(t *testing.T) { // delete the pool err = system.DeleteProtectionDomain(domainName) assert.NotNil(t, err) - } func TestCRUDProtectionDomain(t *testing.T) { diff --git a/inttests/replication_test.go b/inttests/replication_test.go index dbf4679..d314361 100644 --- a/inttests/replication_test.go +++ b/inttests/replication_test.go @@ -408,7 +408,6 @@ func TestExecuteFailoverOnReplicationGroup(t *testing.T) { err := rep.rcg.ExecuteFailoverOnReplicationGroup() assert.Nil(t, err) - } // Test ExecuteRestoreOnReplicationGroup diff --git a/inttests/sdc_test.go b/inttests/sdc_test.go index 02526be..ea8866e 100644 --- a/inttests/sdc_test.go +++ b/inttests/sdc_test.go @@ -71,7 +71,6 @@ func TestGetSdcByAttribute(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, found) assert.Equal(t, Sdc[0].Sdc.SdcGUID, found.Sdc.SdcGUID) - } // TestGetSdcByAttributeInvalid fails to get a single specific Sdc by attribute @@ -141,7 +140,6 @@ func TestFindSdcVolumes(t *testing.T) { // TestChangeSdcName function tests Change name functionality of SDC. func TestChangeSdcName(t *testing.T) { - system := getSystem() assert.NotNil(t, system) @@ -160,7 +158,6 @@ func TestChangeSdcName(t *testing.T) { // TestChangeSdcPerfProfile function tests Change PerfProfile functionality of SDC. func TestChangeSdcPerfProfile(t *testing.T) { - system := getSystem() assert.NotNil(t, system) diff --git a/inttests/sds_test.go b/inttests/sds_test.go index b1a1273..9b98656 100644 --- a/inttests/sds_test.go +++ b/inttests/sds_test.go @@ -122,7 +122,6 @@ func TestCreateSdsInvalid(t *testing.T) { sdsID, err := pd.CreateSds(sdsName, sdsIPList) assert.NotNil(t, err) assert.Equal(t, "", sdsID) - } // TestCreateSdsInvalid will attempt to add an SDS, which results in failure @@ -144,7 +143,6 @@ func TestCreateSdsParamsInvalid(t *testing.T) { sdsID, err := pd.CreateSdsWithParams(sdsParam) assert.NotNil(t, err) assert.Equal(t, "", sdsID) - } // TestCompareSdsIDApi checks if all fields for the SDS are same for fetching by ID and Protection Domain diff --git a/inttests/storagepool_test.go b/inttests/storagepool_test.go index c6c57cf..314ea9b 100644 --- a/inttests/storagepool_test.go +++ b/inttests/storagepool_test.go @@ -188,14 +188,13 @@ func TestGetInstanceStoragePool(t *testing.T) { assert.NotNil(t, err) assert.Nil(t, pool) - //Find with name and Protection Domain ID + // Find with name and Protection Domain ID pd := getProtectionDomain(t) assert.NotNil(t, pd) pool, err = C.FindStoragePool("", name, "", pd.ProtectionDomain.ID) assert.Nil(t, err) assert.NotNil(t, pool) - } func TestCreateDeleteStoragePool(t *testing.T) { @@ -227,7 +226,6 @@ func TestCreateDeleteStoragePool(t *testing.T) { // delete the pool err = domain.DeleteStoragePool(invalidIdentifier) assert.NotNil(t, err) - } // TestGetSDSStoragePool gets the SDS instances associated with storage pool @@ -267,7 +265,7 @@ func TestStoragePoolMediaType(t *testing.T) { _, err = domain.ModifyStoragePoolMedia(poolID, "SSD") assert.Nil(t, err) - //delete the pool + // delete the pool err = domain.DeleteStoragePool(poolName) assert.Nil(t, err) } @@ -290,14 +288,14 @@ func TestEnableRFCache(t *testing.T) { assert.NotNil(t, poolID) _, err = domain.EnableRFCache(poolID) assert.Nil(t, err) - //delete the pool + // delete the pool err = domain.DeleteStoragePool(poolName) assert.Nil(t, err) } // Test all the additional functionality for a storage pool func TestStoragePoolAdditionalFunctionality(t *testing.T) { - //get the protection domain + // get the protection domain domain := getProtectionDomain(t) assert.NotNil(t, domain) @@ -313,45 +311,45 @@ func TestStoragePoolAdditionalFunctionality(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, poolID) - //disable the padding + // disable the padding err = domain.EnableOrDisableZeroPadding(poolID, "false") assert.Nil(t, err) pool, _ := domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.ZeroPaddingEnabled, false) // Now enable the padding err = domain.EnableOrDisableZeroPadding(poolID, "true") assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.ZeroPaddingEnabled, true) - //Modify Replication Journal Capacity to make it 36 + // Modify Replication Journal Capacity to make it 36 err = domain.SetReplicationJournalCapacity(poolID, "36") assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.ReplicationCapacityMaxRatio, 36) - //Again Modify Replication Journal Capacity to make it 0 else storage pool can't be deleted + // Again Modify Replication Journal Capacity to make it 0 else storage pool can't be deleted err = domain.SetReplicationJournalCapacity(poolID, "0") assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //again check the value + // again check the value assert.Equal(t, pool.ReplicationCapacityMaxRatio, 0) - //set the capacity threshold for the storage pool + // set the capacity threshold for the storage pool capacityAlertThreshold := &types.CapacityAlertThresholdParam{ CapacityAlertHighThresholdPercent: "68", } err = domain.SetCapacityAlertThreshold(poolID, capacityAlertThreshold) assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.CapacityAlertHighThreshold, 68) - //Set the protected maintenance mode + // Set the protected maintenance mode protectedMaintenanceModeParam := &types.ProtectedMaintenanceModeParam{ Policy: "favorAppIos", NumOfConcurrentIosPerDevice: "18", @@ -359,38 +357,38 @@ func TestStoragePoolAdditionalFunctionality(t *testing.T) { err = domain.SetProtectedMaintenanceModeIoPriorityPolicy(poolID, protectedMaintenanceModeParam) assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.ProtectedMaintenanceModeIoPriorityPolicy, "favorAppIos") assert.Equal(t, pool.ProtectedMaintenanceModeIoPriorityNumOfConcurrentIosPerDevice, 18) - //set rebalance enablement value + // set rebalance enablement value err = domain.SetRebalanceEnabled(poolID, "true") assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.RebalanceEnabled, true) - //Again set rebalance enablement value + // Again set rebalance enablement value err = domain.SetRebalanceEnabled(poolID, "false") assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") - //check the value + // check the value assert.Equal(t, pool.RebalanceEnabled, false) - //set the rebalance IO priority policy for the storage pool + // set the rebalance IO priority policy for the storage pool protectedMaintenanceModeParam = &types.ProtectedMaintenanceModeParam{ Policy: "limitNumOfConcurrentIos", NumOfConcurrentIosPerDevice: "13", } err = domain.SetRebalanceIoPriorityPolicy(poolID, protectedMaintenanceModeParam) assert.Nil(t, err) - //check the value + // check the value pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.RebalanceioPriorityPolicy, "limitNumOfConcurrentIos") assert.Equal(t, pool.RebalanceioPriorityNumOfConcurrentIosPerDevice, 13) assert.Nil(t, err) - //Set vtree migration IO priority policy + // Set vtree migration IO priority policy protectedMaintenanceModeParam = &types.ProtectedMaintenanceModeParam{ Policy: "favorAppIos", NumOfConcurrentIosPerDevice: "12", @@ -398,47 +396,47 @@ func TestStoragePoolAdditionalFunctionality(t *testing.T) { } err = domain.SetVTreeMigrationIOPriorityPolicy(poolID, protectedMaintenanceModeParam) assert.Nil(t, err) - //check the value + // check the value pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.VtreeMigrationIoPriorityPolicy, "favorAppIos") assert.Equal(t, pool.VtreeMigrationIoPriorityNumOfConcurrentIosPerDevice, 12) assert.Equal(t, pool.VtreeMigrationIoPriorityBwLimitPerDeviceInKbps, 1030) - //set the spare percentage + // set the spare percentage err = domain.SetSparePercentage(poolID, "67") assert.Nil(t, err) - //check the value + // check the value pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.SparePercentage, 67) - //set the Rmcache write handling mode + // set the Rmcache write handling mode err = domain.SetRMcacheWriteHandlingMode(poolID, "Cached") assert.Nil(t, err) - //check the value + // check the value pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.RmCacheWriteHandlingMode, "Cached") - //set the rebuild enablemenent value + // set the rebuild enablemenent value err = domain.SetRebuildEnabled(poolID, "false") assert.Nil(t, err) - //check the value + // check the value pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.RebuildEnabled, false) // set the number of parallel rebuild rebalance jobs per device err = domain.SetRebuildRebalanceParallelismParam(poolID, "9") assert.Nil(t, err) - //check the value + // check the value pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.NumofParallelRebuildRebalanceJobsPerDevice, 9) - //enable fragmentation + // enable fragmentation err = domain.Fragmentation(poolID, true) assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") assert.Equal(t, pool.FragmentationEnabled, true) - //disable fragmentation + // disable fragmentation err = domain.Fragmentation(poolID, false) assert.Nil(t, err) pool, _ = domain.FindStoragePool(poolID, "", "") @@ -467,7 +465,7 @@ func TestDisableRFCache(t *testing.T) { assert.NotNil(t, poolID) _, err = domain.DisableRFCache(poolID) assert.Nil(t, err) - //delete the pool + // delete the pool err = domain.DeleteStoragePool(poolName) assert.Nil(t, err) } diff --git a/inttests/system_limit_test.go b/inttests/system_limit_test.go index 5759d32..d3bc1fb 100644 --- a/inttests/system_limit_test.go +++ b/inttests/system_limit_test.go @@ -33,5 +33,4 @@ func TestGetMaxVol(t *testing.T) { fmt.Println("max vol size", maxvolsize) assert.NotNil(t, maxvolsize) assert.Nil(t, err) - } diff --git a/inttests/tree_quota_test.go b/inttests/tree_quota_test.go index 8a4a8ce..35f23d6 100644 --- a/inttests/tree_quota_test.go +++ b/inttests/tree_quota_test.go @@ -41,7 +41,6 @@ func TestTreeQuotaByID(t *testing.T) { assert.Nil(t, err) assert.Equal(t, treequota.ID, quota.ID) } - } // TestCreateModifyDeleteTreeQuota will create , modify and delete a tree quota @@ -61,9 +60,10 @@ func TestCreateModifyDeleteTreeQuota(t *testing.T) { } err = system.ModifyFileSystem(&types.FSModify{ - IsQuotaEnabled: true}, filesystem.ID) + IsQuotaEnabled: true, + }, filesystem.ID) - //create tree quota + // create tree quota quota, err := system.CreateTreeQuota(treequota) quotaid := quota.ID assert.Nil(t, err) @@ -73,7 +73,7 @@ func TestCreateModifyDeleteTreeQuota(t *testing.T) { quota, err = system.CreateTreeQuota(treequota) assert.NotNil(t, err) - //Modify Tree Quota + // Modify Tree Quota quotaModify := &types.TreeQuotaModify{ Description: treeQuotaModify, SoftLimit: 900, @@ -86,7 +86,7 @@ func TestCreateModifyDeleteTreeQuota(t *testing.T) { err = system.ModifyTreeQuota(quotaModify, "") assert.NotNil(t, err) - //Delete tree Quota + // Delete tree Quota err = system.DeleteTreeQuota(quotaid) assert.Nil(t, err) } @@ -105,7 +105,8 @@ func TestGetTreeQuotaByFSID(t *testing.T) { // enable quota for filesystem err = system.ModifyFileSystem(&types.FSModify{ - IsQuotaEnabled: true}, filesystem.ID) + IsQuotaEnabled: true, + }, filesystem.ID) // set tree quota for filesystem treequota := &types.TreeQuotaCreate{ @@ -131,8 +132,7 @@ func TestGetTreeQuotaByFSID(t *testing.T) { assert.Equal(t, treequota.ID, quota.ID) } - //Delete tree Quota + // Delete tree Quota err = system.DeleteTreeQuota(treeQuota.ID) assert.Nil(t, err) - } diff --git a/inttests/user_test.go b/inttests/user_test.go index 4e8ed0f..d7bd50a 100644 --- a/inttests/user_test.go +++ b/inttests/user_test.go @@ -13,10 +13,11 @@ package inttests import ( - siotypes "github.com/dell/goscaleio/types/v1" - "github.com/stretchr/testify/assert" "os" "testing" + + siotypes "github.com/dell/goscaleio/types/v1" + "github.com/stretchr/testify/assert" ) // TestGetAllUsers will return all user instances @@ -64,5 +65,4 @@ func TestCreateAndDeleteUser(t *testing.T) { // Remove the user err4 := system.RemoveUser(resp.ID) assert.Nil(t, err4) - } diff --git a/inttests/volume_test.go b/inttests/volume_test.go index 8450258..eba19b1 100644 --- a/inttests/volume_test.go +++ b/inttests/volume_test.go @@ -24,12 +24,9 @@ import ( "github.com/stretchr/testify/assert" ) -var ( - createdVolumes = make([]string, 0) -) +var createdVolumes = make([]string, 0) func getVolByID(id string) (*siotypes.Volume, error) { - // The `GetVolume` API returns a slice of volumes, but when only passing // in a volume ID, the response will be just the one volume vols, err := C.GetVolume("", strings.TrimSpace(id), "", "", false) @@ -447,7 +444,6 @@ func TestMapQueryUnmapSnapshot(t *testing.T) { assert.Nil(t, err) err = deleteVolume(t, volID) assert.Nil(t, err) - } func TestCreateInstanceVolume(t *testing.T) { diff --git a/nfs.go b/nfs.go index 7a8d00c..821878b 100644 --- a/nfs.go +++ b/nfs.go @@ -31,13 +31,11 @@ func (s *System) GetFileInterface(id string) (*types.FileInterface, error) { err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &resp) - if err != nil { return nil, errors.New("could not find the File interface using id") } return resp, nil - } // GetNASByIDName gets a NAS server by name or ID @@ -46,7 +44,6 @@ func (s *System) GetNASByIDName(id string, name string) (*types.NAS, error) { if name == "" && id == "" { return nil, errors.New("NAS server name or ID is mandatory, please enter a valid value") - } else if id != "" { path := fmt.Sprintf("/rest/v1/nas-servers/%s?select=*", id) @@ -74,7 +71,6 @@ func (s *System) GetNASByIDName(id string, name string) (*types.NAS, error) { return nil, errors.New("couldn't find given NAS server by name") } - } // CreateNAS creates a NAS server @@ -89,7 +85,6 @@ func (s *System) CreateNAS(name string, protectionDomainID string) (*types.Creat } err := s.client.getJSONWithRetry(http.MethodPost, path, body, &resp) - if err != nil { return nil, err } @@ -99,11 +94,9 @@ func (s *System) CreateNAS(name string, protectionDomainID string) (*types.Creat // DeleteNAS deletes a NAS server func (s *System) DeleteNAS(id string) error { - path := fmt.Sprintf("/rest/v1/nas-servers/%s", id) err := s.client.getJSONWithRetry(http.MethodDelete, path, nil, nil) - if err != nil { fmt.Println("err", err) return err diff --git a/nfs_export.go b/nfs_export.go index 5c54c76..c621cd6 100644 --- a/nfs_export.go +++ b/nfs_export.go @@ -54,7 +54,6 @@ func (c *Client) GetNFSExportByIDName(id string, name string) (respnfs *types.NF if id == "" && name == "" { return nil, errors.New("NFS export name or ID is mandatory for fetching NFS export details, please enter a valid value") - } else if id != "" { path := fmt.Sprintf("/rest/v1/nfs-exports/%s?select=*", id) @@ -79,7 +78,6 @@ func (c *Client) GetNFSExportByIDName(id string, name string) (respnfs *types.NF return nil, errors.New("couldn't find NFS export by name") } - } // DeleteNFSExport deletes the NFS export diff --git a/nfs_export_test.go b/nfs_export_test.go index 3481cc9..a3ca52e 100644 --- a/nfs_export_test.go +++ b/nfs_export_test.go @@ -170,12 +170,12 @@ func TestGetNFSExportByIDName(t *testing.T) { }, } - var testCaseFSNames = map[string]string{ + testCaseFSNames := map[string]string{ "success": "nfs-test-2", "not found": "nfs-test-3", } - var testCaseFSIds = map[string]string{ + testCaseFSIds := map[string]string{ "success": "64242c06-7a78-1773-50f4-2a50fb1ccff3", "not found": "6433a2b2-6d60-f737-9f3b-2a50fb1ccff3", } @@ -226,10 +226,9 @@ func TestGetNFSExportByIDName(t *testing.T) { } func TestDeleteNFSExport(t *testing.T) { - id := "new-nas" - //mock a powerflex endpoint + // mock a powerflex endpoint svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) })) @@ -269,7 +268,6 @@ func TestCreateNFSExport(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/nfs-exports") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -330,7 +328,6 @@ func TestCreateNFSExport(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } diff --git a/nfs_test.go b/nfs_test.go index 22f081a..32af32c 100644 --- a/nfs_test.go +++ b/nfs_test.go @@ -130,7 +130,6 @@ func TestGetNasByIDName(t *testing.T) { t.Fatal(err) } fmt.Fprintln(w, string(respData)) - })) return ts, &system, check(hasError) }, @@ -191,12 +190,12 @@ func TestGetNasByIDName(t *testing.T) { }, } - var testCaseNasNames = map[string]string{ + testCaseNasNames := map[string]string{ "success": "test-nas1", "not found": "test-nas3", } - var testCaseNasIDs = map[string]string{ + testCaseNasIDs := map[string]string{ "success": "5e8d8e8e-671b-336f-db4e-cee0fbdc981e", "not found": "6e8d8e8e-671b-336f-eb4e-dee0fbdc981f", } @@ -221,7 +220,6 @@ func TestGetNasByIDName(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } @@ -245,10 +243,8 @@ func TestGetNasByIDName(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } - } func TestCreateNAS(t *testing.T) { @@ -344,13 +340,11 @@ func TestCreateNAS(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } func TestDeleteNAS(t *testing.T) { - id := "new-nas" systemID := "0000aaacccddd1111" system := types.System{ @@ -358,7 +352,7 @@ func TestDeleteNAS(t *testing.T) { } system1 := &system - //mock a powerflex endpoint + // mock a powerflex endpoint svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) })) diff --git a/protectiondomain.go b/protectiondomain.go index 93cce20..9fafdec 100644 --- a/protectiondomain.go +++ b/protectiondomain.go @@ -122,7 +122,8 @@ func (pd *ProtectionDomain) Delete() error { // GetProtectionDomain returns a ProtectionDomain func (s *System) GetProtectionDomain( - pdhref string) ([]*types.ProtectionDomain, error) { + pdhref string, +) ([]*types.ProtectionDomain, error) { defer TimeSpent("GetprotectionDomain", time.Now()) var ( @@ -158,7 +159,8 @@ func (s *System) GetProtectionDomain( // FindProtectionDomain returns a ProtectionDomain func (s *System) FindProtectionDomain( - id, name, href string) (*types.ProtectionDomain, error) { + id, name, href string, +) (*types.ProtectionDomain, error) { defer TimeSpent("FindProtectionDomain", time.Now()) pds, err := s.GetProtectionDomain(href) diff --git a/sdc.go b/sdc.go index b1869f0..9f10079 100644 --- a/sdc.go +++ b/sdc.go @@ -145,13 +145,11 @@ func (s *System) ApproveSdcByGUID(sdcGUID string) (*types.ApproveSdcByGUIDRespon } err := s.client.getJSONWithRetry(http.MethodPost, path, body, &resp) - if err != nil { return nil, err } return &resp, nil - } // GetStatistics returns a Sdc statistcs @@ -231,7 +229,8 @@ func GetSdcLocalGUID() (string, error) { // MapVolumeSdc maps a volume to Sdc func (v *Volume) MapVolumeSdc( - mapVolumeSdcParam *types.MapVolumeSdcParam) error { + mapVolumeSdcParam *types.MapVolumeSdcParam, +) error { defer TimeSpent("MapVolumeSdc", time.Now()) path := fmt.Sprintf("/api/instances/Volume::%s/action/addMappedSdc", @@ -248,7 +247,8 @@ func (v *Volume) MapVolumeSdc( // UnmapVolumeSdc unmaps a volume from Sdc func (v *Volume) UnmapVolumeSdc( - unmapVolumeSdcParam *types.UnmapVolumeSdcParam) error { + unmapVolumeSdcParam *types.UnmapVolumeSdcParam, +) error { defer TimeSpent("UnmapVolumeSdc", time.Now()) path := fmt.Sprintf("/api/instances/Volume::%s/action/removeMappedSdc", @@ -265,7 +265,8 @@ func (v *Volume) UnmapVolumeSdc( // SetMappedSdcLimits sets Sdc mapped limits func (v *Volume) SetMappedSdcLimits( - setMappedSdcLimitsParam *types.SetMappedSdcLimitsParam) error { + setMappedSdcLimitsParam *types.SetMappedSdcLimitsParam, +) error { defer TimeSpent("SetMappedSdcLimits", time.Now()) path := fmt.Sprintf( diff --git a/sdc_test.go b/sdc_test.go index 64a32db..375285e 100644 --- a/sdc_test.go +++ b/sdc_test.go @@ -149,7 +149,7 @@ func TestRenameSdc(t *testing.T) { }, } - //mock a powerflex endpoint + // mock a powerflex endpoint svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { })) defer svr.Close() @@ -162,7 +162,7 @@ func TestRenameSdc(t *testing.T) { t.Fatal(err) } - //calling RenameSdc with mock value + // calling RenameSdc with mock value err = client.RenameSdc(tc.sdcID, tc.name) if err != nil { if tc.expected == nil { @@ -175,7 +175,6 @@ func TestRenameSdc(t *testing.T) { } }) } - } func TestApproveSdc(t *testing.T) { @@ -250,10 +249,8 @@ func TestApproveSdc(t *testing.T) { } http.Error(w, "The SDC is already approved.", http.StatusInternalServerError) - })) return ts, &system, check(hasError) - }, "Invalid guid err": func(t *testing.T) (*httptest.Server, *types.System, []checkFn) { systemID := "0000aaabbbccc1111" @@ -274,14 +271,12 @@ func TestApproveSdc(t *testing.T) { } http.Error(w, "The given GUID is invalid. Please specify GUID in the following format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", http.StatusInternalServerError) - })) return ts, &system, check(hasError) - }, } - var testCaseGuids = map[string]string{ + testCaseGuids := map[string]string{ "success": "1aaabd94-9acd-11ed-a8fc-0242ac120002", "Already Approved err": "1aaabd94-9acd-11ed-a8fc-0242ac120002", "Invalid guid err": "invald_guid", @@ -306,8 +301,6 @@ func TestApproveSdc(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } - } diff --git a/sds.go b/sds.go index 2f0beee..2953d51 100644 --- a/sds.go +++ b/sds.go @@ -54,7 +54,8 @@ func NewSdsEx(client *Client, sds *types.Sds) *Sds { // CreateSds creates a new Sds with automatically assigned roles to IPs func (pd *ProtectionDomain) CreateSds( - name string, ipList []string) (string, error) { + name string, ipList []string, +) (string, error) { defer TimeSpent("CreateSds", time.Now()) sdsParam := &types.SdsParam{ @@ -181,7 +182,8 @@ func (sys *System) GetAllSds() ([]types.Sds, error) { // FindSds returns a Sds func (pd *ProtectionDomain) FindSds( - field, value string) (*types.Sds, error) { + field, value string, +) (*types.Sds, error) { defer TimeSpent("FindSds", time.Now()) sdss, err := pd.GetSds() @@ -410,7 +412,8 @@ func (pd *ProtectionDomain) SetSdsPerformanceProfile(id, perfProf string) error // FindSds returns a Sds using system instance func (sys *System) FindSds( - field, value string) (*types.Sds, error) { + field, value string, +) (*types.Sds, error) { defer TimeSpent("FindSds", time.Now()) sdss, err := sys.GetAllSds() diff --git a/service.go b/service.go index d31aa4c..658c0ee 100644 --- a/service.go +++ b/service.go @@ -121,7 +121,7 @@ func (gc *GatewayClient) DeployService(deploymentName, deploymentDesc, serviceTe "deploymentDescription": deploymentDesc, "serviceTemplate": templateData, "updateServerFirmware": true, - "firmwareRepositoryId": firmwareRepositoryID, //TODO + "firmwareRepositoryId": firmwareRepositoryID, // TODO } deploymentPayloadJson, _ := json.Marshal(deploymentPayload) @@ -346,7 +346,6 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD for _, parameter := range clonedParams { parameter := parameter.(map[string]interface{}) if !excludeList[parameter["id"].(string)] { - if parameter["id"].(string) == "scaleio_mdm_role" { parameter["guid"] = nil parameter["value"] = "standby_mdm" @@ -354,7 +353,6 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD parameter["guid"] = nil parameter["value"] = nil } - } } @@ -476,7 +474,6 @@ func contains(list []string, str string) bool { } func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken bool) (*types.ServiceResponse, error) { - defer TimeSpent("GetServiceDetailsByID", time.Now()) if newToken { @@ -578,7 +575,6 @@ func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken boo } func (gc *GatewayClient) GetServiceDetailsByFilter(filter, value string) ([]types.ServiceResponse, error) { - defer TimeSpent("GetServiceDetailsByFilter", time.Now()) encodedValue := url.QueryEscape(value) @@ -634,7 +630,6 @@ func (gc *GatewayClient) GetServiceDetailsByFilter(filter, value string) ([]type } func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) { - defer TimeSpent("DeploGetServiceDetailsByIDyService", time.Now()) req, httpError := http.NewRequest("GET", gc.host+"/Api/V1/Deployment/", nil) @@ -682,7 +677,6 @@ func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) } func (gc *GatewayClient) DeleteService(serviceId, serversInInventory, serversManagedState string) (*types.ServiceResponse, error) { - var deploymentResponse types.ServiceResponse deploymentResponse.StatusCode = 400 diff --git a/snapshot_policy_test.go b/snapshot_policy_test.go index a41cbd9..be436f6 100644 --- a/snapshot_policy_test.go +++ b/snapshot_policy_test.go @@ -89,7 +89,6 @@ func TestModifySnapshotPolicyName(t *testing.T) { } cases := []testCase{ { - id: ID2, name: "renameSnapshotPolicy", expected: nil, diff --git a/sso_user.go b/sso_user.go index 7869ef4..a98653f 100644 --- a/sso_user.go +++ b/sso_user.go @@ -25,7 +25,6 @@ func (c *Client) GetSSOUser(userID string) (*types.SSOUserDetails, error) { path := fmt.Sprintf("/rest/v1/users/%s", userID) user := &types.SSOUserDetails{} err := c.getJSONWithRetry(http.MethodGet, path, nil, &user) - if err != nil { return nil, err } diff --git a/storagepool.go b/storagepool.go index 4e3f248..e3fdc64 100644 --- a/storagepool.go +++ b/storagepool.go @@ -58,7 +58,6 @@ func (pd *ProtectionDomain) CreateStoragePool(sp *types.StoragePoolParam) (strin // ModifyStoragePoolName Modifies Storagepool Name func (pd *ProtectionDomain) ModifyStoragePoolName(ID, name string) (string, error) { - storagePoolParam := &types.ModifyStoragePoolName{ Name: name, } @@ -77,7 +76,6 @@ func (pd *ProtectionDomain) ModifyStoragePoolName(ID, name string) (string, erro // ModifyStoragePoolMedia Modifies Storagepool Media Type func (pd *ProtectionDomain) ModifyStoragePoolMedia(ID, mediaType string) (string, error) { - storagePool := &types.StoragePoolMediaType{ MediaType: mediaType, } @@ -96,7 +94,6 @@ func (pd *ProtectionDomain) ModifyStoragePoolMedia(ID, mediaType string) (string // ModifyRMCache Sets Read RAM Cache func (sp *StoragePool) ModifyRMCache(useRmcache string) error { - link, err := GetLink(sp.StoragePool.Links, "self") if err != nil { return err @@ -112,7 +109,6 @@ func (sp *StoragePool) ModifyRMCache(useRmcache string) error { // EnableRFCache Enables RFCache func (pd *ProtectionDomain) EnableRFCache(ID string) (string, error) { - storagePoolParam := &types.StoragePoolUseRfCache{} path := fmt.Sprintf("/api/instances/StoragePool::%v/action/enableRfcache", ID) @@ -129,7 +125,6 @@ func (pd *ProtectionDomain) EnableRFCache(ID string) (string, error) { // EnableOrDisableZeroPadding Enables / disables zero padding func (pd *ProtectionDomain) EnableOrDisableZeroPadding(ID string, zeroPadValue string) error { - zeroPaddedParam := &types.StoragePoolZeroPadEnabled{ ZeroPadEnabled: zeroPadValue, } @@ -144,7 +139,6 @@ func (pd *ProtectionDomain) EnableOrDisableZeroPadding(ID string, zeroPadValue s // SetReplicationJournalCapacity Sets replication journal capacity func (pd *ProtectionDomain) SetReplicationJournalCapacity(ID string, replicationJournalCapacity string) error { - replicationJournalCapacityParam := &types.ReplicationJournalCapacityParam{ ReplicationJournalCapacityMaxRatio: replicationJournalCapacity, } @@ -296,7 +290,6 @@ func (pd *ProtectionDomain) Fragmentation(ID string, value bool) error { // DisableRFCache Disables RFCache func (pd *ProtectionDomain) DisableRFCache(ID string) (string, error) { - payload := &types.StoragePoolUseRfCache{} path := fmt.Sprintf("/api/instances/StoragePool::%v/action/disableRfcache", ID) @@ -340,8 +333,8 @@ func (pd *ProtectionDomain) DeleteStoragePool(name string) error { // GetStoragePool returns a storage pool func (pd *ProtectionDomain) GetStoragePool( - storagepoolhref string) ([]*types.StoragePool, error) { - + storagepoolhref string, +) ([]*types.StoragePool, error) { var ( err error sp = &types.StoragePool{} @@ -373,8 +366,8 @@ func (pd *ProtectionDomain) GetStoragePool( // FindStoragePool returns a storagepool based on id or name func (pd *ProtectionDomain) FindStoragePool( - id, name, href string) (*types.StoragePool, error) { - + id, name, href string, +) (*types.StoragePool, error) { sps, err := pd.GetStoragePool(href) if err != nil { return nil, fmt.Errorf("Error getting protection domains %s", err) @@ -387,12 +380,10 @@ func (pd *ProtectionDomain) FindStoragePool( } return nil, errors.New("Couldn't find storage pool") - } // GetStatistics returns statistics func (sp *StoragePool) GetStatistics() (*types.Statistics, error) { - link, err := GetLink(sp.StoragePool.Links, "/api/StoragePool/relationship/Statistics") if err != nil { diff --git a/system.go b/system.go index 7226a31..a0f0899 100644 --- a/system.go +++ b/system.go @@ -47,7 +47,8 @@ func (c *Client) GetSystems() ([]*types.System, error) { // FindSystem returns a system based on ID or name func (c *Client) FindSystem( - instanceID, name, href string) (*System, error) { + instanceID, name, href string, +) (*System, error) { defer TimeSpent("FindSystem", time.Now()) systems, err := c.GetInstance(href) @@ -87,7 +88,8 @@ func (s *System) GetStatistics() (*types.Statistics, error) { // CreateSnapshotConsistencyGroup creates a snapshot consistency group func (s *System) CreateSnapshotConsistencyGroup( - snapshotVolumesParam *types.SnapshotVolumesParam) (*types.SnapshotVolumesResp, error) { + snapshotVolumesParam *types.SnapshotVolumesParam, +) (*types.SnapshotVolumesResp, error) { defer TimeSpent("CreateSnapshotConsistencyGroup", time.Now()) link, err := GetLink(s.System.Links, "self") diff --git a/system_limit.go b/system_limit.go index b83f2ee..7abc248 100644 --- a/system_limit.go +++ b/system_limit.go @@ -38,17 +38,14 @@ func (c *Client) GetSystemLimits() (systemLimits *types.QuerySystemLimitsRespons func (c *Client) GetMaxVol() (MaxVolumeSize string, err error) { defer TimeSpent("GetMaxVol", time.Now()) sysLimit, err := c.GetSystemLimits() - if err != nil { return "", err } for _, systemLimit := range sysLimit.SystemLimitEntryList { - if systemLimit.Type == "volumeSizeGb" { return systemLimit.MaxVal, nil } - } return "", errors.New("couldn't get max vol size") } diff --git a/system_limit_test.go b/system_limit_test.go index 1ecc384..13c2bfe 100644 --- a/system_limit_test.go +++ b/system_limit_test.go @@ -125,7 +125,7 @@ func TestGetSystemLimits(t *testing.T) { defer ts.Close() // Create a test client and call GetSystemLimits. - //client := NewTestClient(ts.URL) // Replace with your own client creation logic. + // client := NewTestClient(ts.URL) // Replace with your own client creation logic. client, err := NewClientWithArgs(ts.URL, "", math.MaxInt64, true, false) client.configConnect.Version = "4.0" if err != nil { diff --git a/system_test.go b/system_test.go index 056dc79..ea06fb3 100644 --- a/system_test.go +++ b/system_test.go @@ -12,7 +12,6 @@ import ( ) func TestModifyPerformanceProfile(t *testing.T) { - type testCase struct { perfProfile string expected error @@ -56,13 +55,11 @@ func TestModifyPerformanceProfile(t *testing.T) { } } } - }) } } func TestAddStandByMDM(t *testing.T) { - type testCase struct { ips []string role string @@ -107,10 +104,8 @@ func TestAddStandByMDM(t *testing.T) { } } } - }) } - } func TestRemoveStandByMDM(t *testing.T) { @@ -157,10 +152,8 @@ func TestRemoveStandByMDM(t *testing.T) { } } } - }) } - } func TestChangeMDMOwnership(t *testing.T) { @@ -207,7 +200,6 @@ func TestChangeMDMOwnership(t *testing.T) { } } } - }) } } @@ -267,7 +259,6 @@ func TestSwitchClusterMode(t *testing.T) { } } } - }) } } @@ -321,7 +312,6 @@ func TestRenameMdm(t *testing.T) { for _, tc := range cases { tc := tc t.Run("", func(ts *testing.T) { - client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) client.configConnect.Version = "3.6" if err != nil { diff --git a/tree_quota_test.go b/tree_quota_test.go index 8c23e28..dffe602 100644 --- a/tree_quota_test.go +++ b/tree_quota_test.go @@ -98,7 +98,7 @@ func TestTreeQuotaByID(t *testing.T) { }, } - var testCaseIds = map[string]string{ + testCaseIds := map[string]string{ "success": "00000003-006a-0000-0600-000000000000", "not found": "00000003-006a-0000-0700-000000000000", } @@ -150,7 +150,6 @@ func TestCreateTreeQuota(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-tree-quotas") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -214,16 +213,14 @@ func TestCreateTreeQuota(t *testing.T) { for _, checkFn := range checkFns { checkFn(t, resp, err) } - }) } } func TestDeleteTreeQuota(t *testing.T) { - id := "00000003-006a-0000-0600-000000000000" - //mock a powerflex endpoint + // mock a powerflex endpoint svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) })) diff --git a/types/v1/types.go b/types/v1/types.go index 548291d..29eaaae 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -843,8 +843,7 @@ type StoragePoolUseRmCache struct { } // StoragePoolUseRfCache defines struct for StoragePoolUseRfCache -type StoragePoolUseRfCache struct { -} +type StoragePoolUseRfCache struct{} // StoragePoolZeroPadEnabled defines struct for zero Pad Enablement type StoragePoolZeroPadEnabled struct { @@ -895,8 +894,7 @@ type RebuildRebalanceParallelismParam struct { } // FragmentationParam defines struct for fragmentation -type FragmentationParam struct { -} +type FragmentationParam struct{} // StoragePoolResp defines struct for StoragePoolResp type StoragePoolResp struct { @@ -1059,8 +1057,7 @@ type RemoveVolumeParam struct { } // EmptyPayload defines struct for EmptyPayload -type EmptyPayload struct { -} +type EmptyPayload struct{} // SnapshotPolicy defines the struct for SnapshotPolicy type SnapshotPolicy struct { @@ -1262,7 +1259,7 @@ const ( type NFSServerInstance struct { // Unique identifier for NFS server ID string `json:"id"` - //HostName will be used by NFS clients to connect to this NFS server. + // HostName will be used by NFS clients to connect to this NFS server. HostName string `json:"host_name,omitempty"` // IsNFSv4Enabled is set to true if nfsv4 is enabled on NAS server IsNFSv4Enabled bool `json:"is_nfsv4_enabled,omitempty"` @@ -1786,8 +1783,7 @@ type QuerySystemLimitsResponse struct { SystemLimitEntryList []SystemLimits `json:"systemLimitEntryList"` } -type QuerySystemLimitsParam struct { -} +type QuerySystemLimitsParam struct{} // FaultSetParam is the parameters required to create a fault set type FaultSetParam struct { diff --git a/user.go b/user.go index dd7da7f..25fbbf8 100644 --- a/user.go +++ b/user.go @@ -15,9 +15,10 @@ package goscaleio import ( "errors" "fmt" - types "github.com/dell/goscaleio/types/v1" "net/http" "time" + + types "github.com/dell/goscaleio/types/v1" ) // GetUser returns user @@ -40,9 +41,7 @@ func (s *System) GetUser() ([]types.User, error) { // GetUserByIDName returns a specific user based on it's user id func (s *System) GetUserByIDName(userID string, username string) (*types.User, error) { if userID == "" && username == "" { - return nil, errors.New("user name or ID is mandatory, please enter a valid value") - } else if userID != "" { path := fmt.Sprintf("/api/instances/User::%v", userID) diff --git a/volume.go b/volume.go index b8c833c..9523a5c 100644 --- a/volume.go +++ b/volume.go @@ -56,7 +56,8 @@ func NewVolume(client *Client) *Volume { // GetVolume returns a volume func (sp *StoragePool) GetVolume( volumehref, volumeid, ancestorvolumeid, volumename string, - getSnapshots bool) ([]*types.Volume, error) { + getSnapshots bool, +) ([]*types.Volume, error) { defer TimeSpent("GetVolume", time.Now()) var ( @@ -189,7 +190,8 @@ func getVolumeMapping(sysID string, volID string) (mappedVolumes []*SdcMappedVol // CreateVolume creates a volume func (sp *StoragePool) CreateVolume( - volume *types.VolumeParam) (*types.VolumeResp, error) { + volume *types.VolumeParam, +) (*types.VolumeResp, error) { defer TimeSpent("CreateVolume", time.Now()) path := "/api/types/Volume/instances" @@ -269,7 +271,6 @@ func (v *Volume) RemoveVolume(removeMode string) error { // SetVolumeName sets a volume's name func (v *Volume) SetVolumeName(newName string) error { - path := fmt.Sprintf("/api/instances/Volume::%s/action/setVolumeName", v.Volume.ID) payload := &types.SetVolumeNameParam{ @@ -282,7 +283,6 @@ func (v *Volume) SetVolumeName(newName string) error { // SetVolumeSize sets a volume's size func (v *Volume) SetVolumeSize(sizeInGB string) error { - link, err := GetLink(v.Volume.Links, "self") if err != nil { return err @@ -440,7 +440,6 @@ func (v *Volume) SetCompressionMethod(compressionMethod string) error { // UnmarkForReplication Depricated Message (3.6) func (v *Volume) UnmarkForReplication() error { - path := fmt.Sprintf("/api/instances/Volume::%s/action/unmarkForReplication", v.Volume.ID) payload := &types.EmptyPayload{} diff --git a/vtree_test.go b/vtree_test.go index 07e15c6..13ab22f 100644 --- a/vtree_test.go +++ b/vtree_test.go @@ -68,7 +68,6 @@ func TestGetVTreeByID(t *testing.T) { } }) } - } func TestGetVTreeInstances(t *testing.T) { @@ -155,5 +154,4 @@ func TestGetVTreeByVolumeID(t *testing.T) { } }) } - } From 45652b78f77b4fe2561e53c222608dcc808ceec2 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Mon, 4 Mar 2024 03:41:54 -0500 Subject: [PATCH 03/24] Fix gofumpt warnings --- deploy.go | 1 - drv_cfg.go | 2 -- inttests/init_client.go | 1 - 3 files changed, 4 deletions(-) diff --git a/deploy.go b/deploy.go index 7c4d47d..cb66b1b 100644 --- a/deploy.go +++ b/deploy.go @@ -1008,7 +1008,6 @@ func (gc *GatewayClient) GetInQueueCommand() ([]types.MDMQueueCommandDetails, er mdmCommands, _ := json.Marshal(commandList) err = json.Unmarshal([]byte(mdmCommands), &mdmQueueCommandDetails) - if err != nil { return mdmQueueCommandDetails, fmt.Errorf("Error For Get In Queue Commands: %s", err) } diff --git a/drv_cfg.go b/drv_cfg.go index 47f66d0..798785f 100644 --- a/drv_cfg.go +++ b/drv_cfg.go @@ -84,7 +84,6 @@ func DrvCfgQueryGUID() (string, error) { buf := [1]ioctlGUID{} // #nosec CWE-242, validated buffer is large enough to hold data err = ioctl(f.Fd(), opCode, uintptr(unsafe.Pointer(&buf[0]))) - if err != nil { return "", fmt.Errorf("QueryGUID error: %v", err) } @@ -116,7 +115,6 @@ func DrvCfgQueryRescan() (string, error) { var rc int64 // #nosec CWE-242, validated buffer is large enough to hold data err = ioctl(f.Fd(), opCode, uintptr(unsafe.Pointer(&rc))) - if err != nil { return "", fmt.Errorf("Rescan error: %v", err) } diff --git a/inttests/init_client.go b/inttests/init_client.go index b159b61..3cbbe6c 100644 --- a/inttests/init_client.go +++ b/inttests/init_client.go @@ -73,7 +73,6 @@ func initClient2() bool { math.MaxInt64, os.Getenv("GOSCALEIO_INSECURE") == "true", os.Getenv("GOSCALEIO_INSECURE") == "true") - if err != nil { panic(err) } From 8e34bd1655f51bf0c30b55827c6707a7aeb4429d Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Mon, 4 Mar 2024 08:06:20 -0500 Subject: [PATCH 04/24] Fix golangci-lint warnings in api package --- api/api.go | 2 +- api/api_logging.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/api.go b/api/api.go index b3cc665..ef7f2ce 100644 --- a/api/api.go +++ b/api/api.go @@ -135,7 +135,7 @@ type ClientOptions struct { // New returns a new API client. func New( - ctx context.Context, + _ context.Context, host string, opts ClientOptions, debug bool, diff --git a/api/api_logging.go b/api/api_logging.go index 02d1c4c..5c35886 100644 --- a/api/api_logging.go +++ b/api/api_logging.go @@ -30,7 +30,7 @@ func isBinOctetBody(h http.Header) bool { } func logRequest( - ctx context.Context, + _ context.Context, req *http.Request, lf func(func(args ...interface{}), string), ) { @@ -58,9 +58,9 @@ func logRequest( } func logResponse( - ctx context.Context, + _ context.Context, res *http.Response, - lf func(func(args ...interface{}), string), + _ func(func(args ...interface{}), string), ) { log.SetLevel(log.DebugLevel) From 628e043b20ca9f39aaaf722f70d3014702e76baa Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Mon, 4 Mar 2024 09:05:18 -0500 Subject: [PATCH 05/24] Fix golangci-lint warning in inttests package --- inttests/api_test.go | 6 +++--- inttests/device_test.go | 12 ++++++------ inttests/fs_test.go | 2 +- inttests/sdc_test.go | 2 +- inttests/sds_test.go | 4 ++-- inttests/volume_test.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/inttests/api_test.go b/inttests/api_test.go index c5f7829..ff301d3 100644 --- a/inttests/api_test.go +++ b/inttests/api_test.go @@ -40,14 +40,14 @@ func TestCustomLogger(t *testing.T) { type customLogger struct{} -func (cl *customLogger) Info(ctx context.Context, format string, args ...interface{}) { +func (cl *customLogger) Info(_ context.Context, format string, args ...interface{}) { log.Printf("INFO:"+format, args...) } -func (cl *customLogger) Debug(ctx context.Context, format string, args ...interface{}) { +func (cl *customLogger) Debug(_ context.Context, format string, args ...interface{}) { log.Printf("DEBUG:"+format, args...) } -func (cl *customLogger) Error(ctx context.Context, format string, args ...interface{}) { +func (cl *customLogger) Error(_ context.Context, format string, args ...interface{}) { log.Printf("ERROR:"+format, args...) } diff --git a/inttests/device_test.go b/inttests/device_test.go index 78ab746..c0ba174 100644 --- a/inttests/device_test.go +++ b/inttests/device_test.go @@ -36,11 +36,11 @@ func getAllDevices(t *testing.T) []*goscaleio.Device { assert.NotZero(t, len(devices)) for _, d := range devices { // create a device to return to the caller - outDevice := goscaleio.NewDeviceEx(C, &d) + outDevice := goscaleio.NewDeviceEx(C, &d) // #nosec G601 allDevice = append(allDevice, outDevice) // create a device via NewDevice for testing purposes tempDevice := goscaleio.NewDevice(C) - tempDevice.Device = &d + tempDevice.Device = &d // #nosec G601 assert.Equal(t, outDevice.Device.ID, tempDevice.Device.ID) } return allDevice @@ -54,11 +54,11 @@ func getAllDevicesFromSystem(t *testing.T) []goscaleio.Device { assert.NotZero(t, len(devices)) for _, d := range devices { // create a device to return to the caller - outDevice := goscaleio.NewDeviceEx(C, &d) + outDevice := goscaleio.NewDeviceEx(C, &d) // #nosec G601 allDevice = append(allDevice, *outDevice) // create a device via NewDevice for testing purposes tempDevice := goscaleio.NewDevice(C) - tempDevice.Device = &d + tempDevice.Device = &d // #nosec G601 assert.Equal(t, outDevice.Device.ID, tempDevice.Device.ID) } return allDevice @@ -78,11 +78,11 @@ func getAllSdsDevices(t *testing.T) []*goscaleio.Device { assert.NotZero(t, len(devices)) for _, d := range devices { // create a device to return to the caller - outDevice := goscaleio.NewDeviceEx(C, &d) + outDevice := goscaleio.NewDeviceEx(C, &d) // #nosec G601 allDevice = append(allDevice, outDevice) // create a device via NewDevice for testing purposes tempDevice := goscaleio.NewDevice(C) - tempDevice.Device = &d + tempDevice.Device = &d // #nosec G601 assert.Equal(t, outDevice.Device.ID, tempDevice.Device.ID) } return allDevice diff --git a/inttests/fs_test.go b/inttests/fs_test.go index 6dff567..a36094d 100644 --- a/inttests/fs_test.go +++ b/inttests/fs_test.go @@ -53,7 +53,7 @@ func getAllFileSystems(t *testing.T) []*goscaleio.FileSystem { assert.Nil(t, err) assert.NotZero(t, len(fs)) for _, f := range fs { - outFs := goscaleio.NewFileSystem(C, &f) + outFs := goscaleio.NewFileSystem(C, &f) // #nosec G601 allFs = append(allFs, outFs) } return allFs diff --git a/inttests/sdc_test.go b/inttests/sdc_test.go index ea8866e..180929c 100644 --- a/inttests/sdc_test.go +++ b/inttests/sdc_test.go @@ -32,7 +32,7 @@ func getAllSdc(t *testing.T) []*goscaleio.Sdc { assert.Nil(t, err) assert.NotZero(t, len(sdc)) for _, s := range sdc { - outSdc := goscaleio.NewSdc(C, &s) + outSdc := goscaleio.NewSdc(C, &s) // #nosec G601 allSdc = append(allSdc, outSdc) } return allSdc diff --git a/inttests/sds_test.go b/inttests/sds_test.go index 9b98656..c725d93 100644 --- a/inttests/sds_test.go +++ b/inttests/sds_test.go @@ -44,11 +44,11 @@ func getAllSds(t *testing.T) []*goscaleio.Sds { assert.NotZero(t, len(sds)) for _, s := range sds { // create an SDS via NewSdsEx to the caller (appending to the allSds slice) - outSDS := goscaleio.NewSdsEx(C, &s) + outSDS := goscaleio.NewSdsEx(C, &s) // #nosec G601 allSds = append(allSds, outSDS) // create an SDS via NewSds that we will through away tempSDS := goscaleio.NewSds(C) - tempSDS.Sds = &s + tempSDS.Sds = &s // #nosec G601 assert.Equal(t, outSDS.Sds.Name, tempSDS.Sds.Name) } return allSds diff --git a/inttests/volume_test.go b/inttests/volume_test.go index eba19b1..3c24100 100644 --- a/inttests/volume_test.go +++ b/inttests/volume_test.go @@ -62,7 +62,7 @@ func createVolume(t *testing.T, useName string) (string, error) { return createResp.ID, nil } -func deleteVolume(t *testing.T, volID string) error { +func deleteVolume(_ *testing.T, volID string) error { existingVol, err := getVolByID(volID) if err != nil { return err From 1676549837e67745139c2351a05c87424387f381 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Thu, 7 Mar 2024 02:40:58 -0500 Subject: [PATCH 06/24] Fix golangci-lint warnings in types dir --- inttests/snapshot_policy_test.go | 8 ++++---- snapshot_policy_test.go | 14 +++++++------- types/v1/types.go | 10 +++++----- types/v1/vTreeTypes.go | 2 +- vtree.go | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/inttests/snapshot_policy_test.go b/inttests/snapshot_policy_test.go index fb5aeb7..96ba4fa 100644 --- a/inttests/snapshot_policy_test.go +++ b/inttests/snapshot_policy_test.go @@ -58,7 +58,7 @@ func TestCreateModifyDeleteSnapshotPolicy(t *testing.T) { volID, err := createVolume(t, "") assignVolume := &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: volID, + SourceVolumeID: volID, } // Assign and unassign volume to Snapshot Policy @@ -70,20 +70,20 @@ func TestCreateModifyDeleteSnapshotPolicy(t *testing.T) { assert.NotNil(t, vol) assignVolume = &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "Invalid", + SourceVolumeID: "Invalid", } err = system.AssignVolumeToSnapshotPolicy(assignVolume, snapID) assert.NotNil(t, err) unassignVolume := &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: volID, + SourceVolumeID: volID, AutoSnapshotRemovalAction: "Remove", } err = system.UnassignVolumeFromSnapshotPolicy(unassignVolume, snapID) assert.Nil(t, err) unassignVolume = &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: volID, + SourceVolumeID: volID, AutoSnapshotRemovalAction: "Invalid", } err = system.UnassignVolumeFromSnapshotPolicy(unassignVolume, snapID) diff --git a/snapshot_policy_test.go b/snapshot_policy_test.go index be436f6..e2b4987 100644 --- a/snapshot_policy_test.go +++ b/snapshot_policy_test.go @@ -192,21 +192,21 @@ func TestAssignSnapshotPolicy(t *testing.T) { { id: ID2, snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff00000001", + SourceVolumeID: "edba1bff00000001", }, expected: nil, }, { id: "Invalid", snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff00000001", + SourceVolumeID: "edba1bff00000001", }, expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), }, { id: ID2, snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff000000", + SourceVolumeID: "edba1bff000000", }, expected: errors.New("Invalid volume. Please try again with a valid ID or name."), }, @@ -251,7 +251,7 @@ func TestUnassignSnapshotPolicy(t *testing.T) { { id: ID2, snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff00000001", + SourceVolumeID: "edba1bff00000001", AutoSnapshotRemovalAction: "Remove", }, expected: nil, @@ -259,7 +259,7 @@ func TestUnassignSnapshotPolicy(t *testing.T) { { id: "Invalid", snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff00000001", + SourceVolumeID: "edba1bff00000001", AutoSnapshotRemovalAction: "Remove", }, expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), @@ -267,7 +267,7 @@ func TestUnassignSnapshotPolicy(t *testing.T) { { id: ID2, snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff000000", + SourceVolumeID: "edba1bff000000", AutoSnapshotRemovalAction: "Remove", }, expected: errors.New("Invalid volume. Please try again with a valid ID or name."), @@ -275,7 +275,7 @@ func TestUnassignSnapshotPolicy(t *testing.T) { { id: ID2, snap: &types.AssignVolumeToSnapshotPolicyParam{ - SourceVolumeId: "edba1bff000000", + SourceVolumeID: "edba1bff000000", AutoSnapshotRemovalAction: "Invalid", }, expected: errors.New("autoSnapshotRemovalAction should get one of the following values: Remove, Detach, but its value is Invalid."), diff --git a/types/v1/types.go b/types/v1/types.go index 29eaaae..e004dad 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -291,7 +291,7 @@ type SdcStatistics struct { UserDataSdcReadLatency BWC `json:"userDataSdcReadLatency"` UserDataSdcWriteLatency BWC `json:"userDataSdcWriteLatency"` UserDataSdcTrimLatency BWC `json:"userDataSdcTrimLatency"` - VolumeIds []string `json:"volumeIds"` + VolumeIDs []string `json:"volumeIds"` NumOfMappedVolumes int `json:"numOfMappedVolumes"` } @@ -303,7 +303,7 @@ type VolumeStatistics struct { UserDataSdcReadLatency BWC `json:"userDataSdcReadLatency"` UserDataSdcWriteLatency BWC `json:"userDataSdcWriteLatency"` UserDataSdcTrimLatency BWC `json:"userDataSdcTrimLatency"` - MappedSdcIds []string `json:"mappedSdcIds"` + MappedSdcIDs []string `json:"mappedSdcIds"` NumOfMappedSdcs int `json:"numOfMappedSdcs"` } @@ -986,7 +986,7 @@ type VolumeQeryIDByKeyParam struct { } // VolumeQeryBySelectedIdsParam defines struct for VolumeQeryBySelectedIdsParam -type VolumeQeryBySelectedIdsParam struct { +type VolumeQeryBySelectedIDsParam struct { IDs []string `json:"ids"` } @@ -1111,7 +1111,7 @@ type SnapshotPolicyModifyParam struct { // AssignVolumeToSnapshotPolicyParam defines the struct for assigning volume to a Snapshot Policy type AssignVolumeToSnapshotPolicyParam struct { - SourceVolumeId string `json:"sourceVolumeId"` + SourceVolumeID string `json:"sourceVolumeId"` AutoSnapshotRemovalAction string `json:"autoSnapshotRemovalAction,omitempty"` } @@ -1800,7 +1800,7 @@ type FaultSetResp struct { type FaultSet struct { ID string `json:"id"` Name string `json:"name"` - ProtectionDomainId string `json:"protectionDomainId"` + ProtectionDomainID string `json:"protectionDomainId"` Links []*Link `json:"links"` } diff --git a/types/v1/vTreeTypes.go b/types/v1/vTreeTypes.go index 9536556..bc78f06 100644 --- a/types/v1/vTreeTypes.go +++ b/types/v1/vTreeTypes.go @@ -24,6 +24,6 @@ type VTreeMigrationInfo struct { } // VTreeQueryBySelectedIdsParam defines struct for specifying Vtree IDs -type VTreeQueryBySelectedIdsParam struct { +type VTreeQueryBySelectedIDsParam struct { IDs []string `json:"ids"` } diff --git a/vtree.go b/vtree.go index cf6b6ba..33a6c78 100644 --- a/vtree.go +++ b/vtree.go @@ -55,7 +55,7 @@ func (c *Client) GetVTreeInstances(ids []string) ([]types.VTreeDetails, error) { path := "/api/types/VTree/instances/action/queryBySelectedIds" - payload := types.VTreeQueryBySelectedIdsParam{ + payload := types.VTreeQueryBySelectedIDsParam{ IDs: ids, } var vTree []types.VTreeDetails From 7620cddd7c40513a2acddcd375203a92b31e809c Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Fri, 8 Mar 2024 00:45:24 -0500 Subject: [PATCH 07/24] Fix golangci-lint warnings in fs related files --- fs.go | 27 +++++++++++++++------------ fs_test.go | 42 +++++++++++++++++++++--------------------- nfs.go | 34 +++++++++++++++++++--------------- nfs_export.go | 32 ++++++++++++++++++-------------- nfs_export_test.go | 20 ++++++++++---------- nfs_test.go | 20 ++++++++++---------- 6 files changed, 93 insertions(+), 82 deletions(-) diff --git a/fs.go b/fs.go index f90dbcc..8a627e7 100644 --- a/fs.go +++ b/fs.go @@ -56,7 +56,10 @@ func (s *System) GetFileSystemByIDName(id string, name string) (*types.FileSyste if id == "" && name == "" { return nil, errors.New("file system name or ID is mandatory, please enter a valid value") - } else if id != "" { + } + + // Get filesystem by id + if id != "" { path := fmt.Sprintf("/rest/v1/file-systems/%v?select=*", id) var fs types.FileSystem err := s.client.getJSONWithRetry( @@ -66,21 +69,21 @@ func (s *System) GetFileSystemByIDName(id string, name string) (*types.FileSyste } return &fs, nil + } - } else { - filesystems, err := s.GetAllFileSystems() - if err != nil { - return nil, err - } + // Get filesystem by name + filesystems, err := s.GetAllFileSystems() + if err != nil { + return nil, err + } - for _, fs := range filesystems { - if fs.Name == name { - return &fs, nil - } + for _, fs := range filesystems { + if fs.Name == name { + return &fs, nil } - - return nil, errors.New("couldn't find file system by name") } + + return nil, errors.New("couldn't find file system by name") } // CreateFileSystem creates a file system diff --git a/fs_test.go b/fs_test.go index a9029c1..7a0e4ba 100644 --- a/fs_test.go +++ b/fs_test.go @@ -29,26 +29,26 @@ func TestGetFileSystemByIDName(t *testing.T) { type checkFn func(*testing.T, *types.FileSystem, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.FileSystem, err error) { + hasNoError := func(t *testing.T, _ *types.FileSystem, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.FileSystem, err error) { + hasError := func(t *testing.T, _ *types.FileSystem, err error) { if err == nil { t.Fatalf("expected error") } } checkRespName := func(fsName string) func(t *testing.T, resp *types.FileSystem, err error) { - return func(t *testing.T, resp *types.FileSystem, err error) { + return func(t *testing.T, resp *types.FileSystem, _ error) { assert.Equal(t, fsName, resp.Name) } } checkRespID := func(fsID string) func(t *testing.T, resp *types.FileSystem, err error) { - return func(t *testing.T, resp *types.FileSystem, err error) { + return func(t *testing.T, resp *types.FileSystem, _ error) { assert.Equal(t, fsID, resp.ID) } } @@ -223,27 +223,27 @@ func TestCreateFileSystem(t *testing.T) { type checkFn func(*testing.T, *types.FileSystemResp, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.FileSystemResp, err error) { + hasNoError := func(t *testing.T, _ *types.FileSystemResp, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.FileSystemResp, err error) { + hasError := func(t *testing.T, _ *types.FileSystemResp, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(fsId string) func(t *testing.T, resp *types.FileSystemResp, err error) { - return func(t *testing.T, resp *types.FileSystemResp, err error) { + return func(t *testing.T, resp *types.FileSystemResp, _ error) { assert.Equal(t, fsId, resp.ID) } } tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-systems") + href := "/rest/v1/file-systems" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { @@ -267,7 +267,7 @@ func TestCreateFileSystem(t *testing.T) { return ts, check(hasNoError, checkResp("64366a19-54e8-1544-f3d7-2a50fb1ccff3")) }, "bad request": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/file-systems") + href := "/rest/v1/file-systems" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { @@ -318,20 +318,20 @@ func TestCreateFileSystemSnapshot(t *testing.T) { type checkFn func(*testing.T, *types.CreateFileSystemSnapshotResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.CreateFileSystemSnapshotResponse, err error) { + hasNoError := func(t *testing.T, _ *types.CreateFileSystemSnapshotResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.CreateFileSystemSnapshotResponse, err error) { + hasError := func(t *testing.T, _ *types.CreateFileSystemSnapshotResponse, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(snapId string) func(t *testing.T, resp *types.CreateFileSystemSnapshotResponse, err error) { - return func(t *testing.T, resp *types.CreateFileSystemSnapshotResponse, err error) { + return func(t *testing.T, resp *types.CreateFileSystemSnapshotResponse, _ error) { assert.Equal(t, snapId, resp.ID) } } @@ -412,20 +412,20 @@ func TestGetFsSnapshotsByVolumeID(t *testing.T) { type checkFn func(*testing.T, []types.FileSystem, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp []types.FileSystem, err error) { + hasNoError := func(t *testing.T, _ []types.FileSystem, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp []types.FileSystem, err error) { + hasError := func(t *testing.T, _ []types.FileSystem, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(snapLength int) func(t *testing.T, resp []types.FileSystem, err error) { - return func(t *testing.T, resp []types.FileSystem, err error) { + return func(t *testing.T, resp []types.FileSystem, _ error) { assert.Equal(t, snapLength, len(resp)) } } @@ -511,20 +511,20 @@ func TestRestoreFileSystemFromSnapshot(t *testing.T) { type checkFn func(*testing.T, *types.RestoreFsSnapResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.RestoreFsSnapResponse, err error) { + hasNoError := func(t *testing.T, _ *types.RestoreFsSnapResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.RestoreFsSnapResponse, err error) { + hasError := func(t *testing.T, _ *types.RestoreFsSnapResponse, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(snapId string) func(t *testing.T, resp *types.RestoreFsSnapResponse, err error) { - return func(t *testing.T, resp *types.RestoreFsSnapResponse, err error) { + return func(t *testing.T, resp *types.RestoreFsSnapResponse, _ error) { assert.Equal(t, snapId, resp.ID) } } @@ -645,7 +645,7 @@ func TestRestoreFileSystemFromSnapshot(t *testing.T) { func TestDeleteFileSystem(t *testing.T) { name := "new-fs" - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -686,13 +686,13 @@ func TestModifyFileSystem(t *testing.T) { }, } // mock a powerflex endpoint - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) diff --git a/nfs.go b/nfs.go index 821878b..eb69fee 100644 --- a/nfs.go +++ b/nfs.go @@ -44,7 +44,10 @@ func (s *System) GetNASByIDName(id string, name string) (*types.NAS, error) { if name == "" && id == "" { return nil, errors.New("NAS server name or ID is mandatory, please enter a valid value") - } else if id != "" { + } + + // Get NAS server by id + if id != "" { path := fmt.Sprintf("/rest/v1/nas-servers/%s?select=*", id) var resp *types.NAS @@ -55,29 +58,30 @@ func (s *System) GetNASByIDName(id string, name string) (*types.NAS, error) { } return resp, nil - } else { - path := fmt.Sprintf("/rest/v1/nas-servers?select=*") - err := s.client.getJSONWithRetry( - http.MethodGet, path, nil, &nasList) - if err != nil { - return nil, err - } + } - for _, nas := range nasList { - if nas.Name == name { - return &nas, nil - } - } + // Get NAS server by name + path := "/rest/v1/nas-servers?select=*" + err := s.client.getJSONWithRetry( + http.MethodGet, path, nil, &nasList) + if err != nil { + return nil, err + } - return nil, errors.New("couldn't find given NAS server by name") + for _, nas := range nasList { + if nas.Name == name { + return &nas, nil + } } + + return nil, errors.New("couldn't find given NAS server by name") } // CreateNAS creates a NAS server func (s *System) CreateNAS(name string, protectionDomainID string) (*types.CreateNASResponse, error) { var resp types.CreateNASResponse - path := fmt.Sprintf("/rest/v1/nas-servers") + path := "/rest/v1/nas-servers" var body types.CreateNASParam = types.CreateNASParam{ Name: name, diff --git a/nfs_export.go b/nfs_export.go index c621cd6..e19d8b0 100644 --- a/nfs_export.go +++ b/nfs_export.go @@ -24,7 +24,7 @@ import ( // GetNFSExport lists NFS Exports. func (c *Client) GetNFSExport() (nfsList []types.NFSExport, err error) { defer TimeSpent("GetNfsExport", time.Now()) - path := fmt.Sprintf("/rest/v1/nfs-exports?select=*") + path := "/rest/v1/nfs-exports?select=*" err = c.getJSONWithRetry( http.MethodGet, path, nil, &nfsList) @@ -37,7 +37,7 @@ func (c *Client) GetNFSExport() (nfsList []types.NFSExport, err error) { // CreateNFSExport create an NFS Export for a File System. func (c *Client) CreateNFSExport(createParams *types.NFSExportCreate) (respnfs *types.NFSExportCreateResponse, err error) { - path := fmt.Sprintf("/rest/v1/nfs-exports") + path := "/rest/v1/nfs-exports" var body *types.NFSExportCreate = createParams err = c.getJSONWithRetry(http.MethodPost, path, body, &respnfs) @@ -54,7 +54,10 @@ func (c *Client) GetNFSExportByIDName(id string, name string) (respnfs *types.NF if id == "" && name == "" { return nil, errors.New("NFS export name or ID is mandatory for fetching NFS export details, please enter a valid value") - } else if id != "" { + } + + // Get NFS export by id + if id != "" { path := fmt.Sprintf("/rest/v1/nfs-exports/%s?select=*", id) err = c.getJSONWithRetry( @@ -64,20 +67,21 @@ func (c *Client) GetNFSExportByIDName(id string, name string) (respnfs *types.NF } return respnfs, nil - } else { - nfsList, err := c.GetNFSExport() - if err != nil { - return nil, err - } + } - for _, nfs := range nfsList { - if nfs.Name == name { - return &nfs, nil - } - } + // Get NFS export by name + nfsList, err := c.GetNFSExport() + if err != nil { + return nil, err + } - return nil, errors.New("couldn't find NFS export by name") + for _, nfs := range nfsList { + if nfs.Name == name { + return &nfs, nil + } } + + return nil, errors.New("couldn't find NFS export by name") } // DeleteNFSExport deletes the NFS export diff --git a/nfs_export_test.go b/nfs_export_test.go index a3ca52e..3714f24 100644 --- a/nfs_export_test.go +++ b/nfs_export_test.go @@ -34,26 +34,26 @@ func TestGetNFSExportByIDName(t *testing.T) { type checkFn func(*testing.T, *types.NFSExport, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.NFSExport, err error) { + hasNoError := func(t *testing.T, _ *types.NFSExport, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.NFSExport, err error) { + hasError := func(t *testing.T, _ *types.NFSExport, err error) { if err == nil { t.Fatalf("expected error") } } checkRespName := func(nfsName string) func(t *testing.T, resp *types.NFSExport, err error) { - return func(t *testing.T, resp *types.NFSExport, err error) { + return func(t *testing.T, resp *types.NFSExport, _ error) { assert.Equal(t, nfsName, resp.Name) } } checkRespID := func(nfsID string) func(t *testing.T, resp *types.NFSExport, err error) { - return func(t *testing.T, resp *types.NFSExport, err error) { + return func(t *testing.T, resp *types.NFSExport, _ error) { assert.Equal(t, nfsID, resp.ID) } } @@ -229,7 +229,7 @@ func TestDeleteNFSExport(t *testing.T) { id := "new-nas" // mock a powerflex endpoint - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -248,27 +248,27 @@ func TestCreateNFSExport(t *testing.T) { type checkFn func(*testing.T, *types.NFSExportCreateResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.NFSExportCreateResponse, err error) { + hasNoError := func(t *testing.T, _ *types.NFSExportCreateResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.NFSExportCreateResponse, err error) { + hasError := func(t *testing.T, _ *types.NFSExportCreateResponse, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(nfsId string) func(t *testing.T, resp *types.NFSExportCreateResponse, err error) { - return func(t *testing.T, resp *types.NFSExportCreateResponse, err error) { + return func(t *testing.T, resp *types.NFSExportCreateResponse, _ error) { assert.Equal(t, nfsId, resp.ID) } } tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){ "success": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/nfs-exports") + href := "/rest/v1/nfs-exports" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { @@ -292,7 +292,7 @@ func TestCreateNFSExport(t *testing.T) { return ts, check(hasNoError, checkResp("64385158-97a1-bb86-4fd9-2a50fb1ccff3")) }, "bad request": func(t *testing.T) (*httptest.Server, []checkFn) { - href := fmt.Sprintf("/rest/v1/nfs-exports") + href := "/rest/v1/nfs-exports" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { diff --git a/nfs_test.go b/nfs_test.go index 32af32c..6667ebe 100644 --- a/nfs_test.go +++ b/nfs_test.go @@ -34,26 +34,26 @@ func TestGetNasByIDName(t *testing.T) { type checkFn func(*testing.T, *types.NAS, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.NAS, err error) { + hasNoError := func(t *testing.T, _ *types.NAS, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.NAS, err error) { + hasError := func(t *testing.T, _ *types.NAS, err error) { if err == nil { t.Fatalf("expected error") } } checkRespName := func(nasName string) func(t *testing.T, resp *types.NAS, err error) { - return func(t *testing.T, resp *types.NAS, err error) { + return func(t *testing.T, resp *types.NAS, _ error) { assert.Equal(t, nasName, resp.Name) } } checkRespID := func(nasId string) func(t *testing.T, resp *types.NAS, err error) { - return func(t *testing.T, resp *types.NAS, err error) { + return func(t *testing.T, resp *types.NAS, _ error) { assert.Equal(t, nasId, resp.ID) } } @@ -251,20 +251,20 @@ func TestCreateNAS(t *testing.T) { type checkFn func(*testing.T, *types.CreateNASResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.CreateNASResponse, err error) { + hasNoError := func(t *testing.T, _ *types.CreateNASResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.CreateNASResponse, err error) { + hasError := func(t *testing.T, _ *types.CreateNASResponse, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(nasId string) func(t *testing.T, resp *types.CreateNASResponse, err error) { - return func(t *testing.T, resp *types.CreateNASResponse, err error) { + return func(t *testing.T, resp *types.CreateNASResponse, _ error) { assert.Equal(t, nasId, resp.ID) } } @@ -272,7 +272,7 @@ func TestCreateNAS(t *testing.T) { tests := map[string]func(t *testing.T) (*httptest.Server, *types.System, []checkFn){ "success": func(t *testing.T) (*httptest.Server, *types.System, []checkFn) { systemID := "0000aaacccddd1111" - href := fmt.Sprintf("/rest/v1/nas-servers") + href := "/rest/v1/nas-servers" system := types.System{ ID: systemID, } @@ -299,7 +299,7 @@ func TestCreateNAS(t *testing.T) { return ts, &system, check(hasNoError, checkResp("5e8d8e8e-671b-336f-db4e-cee0fbdc981e")) }, "bad request": func(t *testing.T) (*httptest.Server, *types.System, []checkFn) { - href := fmt.Sprintf("/rest/v1/nas-servers") + href := "/rest/v1/nas-servers" systemID := "0000aaacccddd1111" system := types.System{ ID: systemID, @@ -353,7 +353,7 @@ func TestDeleteNAS(t *testing.T) { system1 := &system // mock a powerflex endpoint - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() From 15dd57ec756a7db579719dbca2288c17c453702e Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 04:50:11 -0400 Subject: [PATCH 08/24] Fix golangci-lint warnings in api and deploy --- api_test.go | 2 +- deploy.go | 82 +++++++++++++++++++++++++------------------------- deploy_test.go | 12 ++++---- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/api_test.go b/api_test.go index c073e92..a398cc0 100644 --- a/api_test.go +++ b/api_test.go @@ -200,7 +200,7 @@ func Test_addMetaData(t *testing.T) { } } -func Test_updateHeaders(t *testing.T) { +func Test_updateHeaders(_ *testing.T) { var wg sync.WaitGroup for i := 0; i < 3; i++ { wg.Add(1) diff --git a/deploy.go b/deploy.go index cb66b1b..d747b29 100644 --- a/deploy.go +++ b/deploy.go @@ -379,9 +379,9 @@ func (gc *GatewayClient) GetPackageDetails() ([]*types.PackageDetails, error) { return packageParam, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return packageParam, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return packageParam, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode == 200 { @@ -430,9 +430,9 @@ func (gc *GatewayClient) ValidateMDMDetails(mdmTopologyParam []byte) (*types.Gat return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -458,7 +458,7 @@ func (gc *GatewayClient) ValidateMDMDetails(mdmTopologyParam []byte) (*types.Gat var mdmTopologyDetails types.MDMTopologyDetails - err := json.Unmarshal([]byte(responseString), &mdmTopologyDetails) + err = json.Unmarshal([]byte(responseString), &mdmTopologyDetails) if err != nil { return &gatewayResponse, fmt.Errorf("Error Validating MDM Details: %s", err) } @@ -496,9 +496,9 @@ func (gc *GatewayClient) GetClusterDetails(mdmTopologyParam []byte, requireJSONO return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -532,7 +532,7 @@ func (gc *GatewayClient) GetClusterDetails(mdmTopologyParam []byte, requireJSONO var mdmTopologyDetails types.MDMTopologyDetails - err := json.Unmarshal([]byte(responseString), &mdmTopologyDetails) + err = json.Unmarshal([]byte(responseString), &mdmTopologyDetails) if err != nil { return &gatewayResponse, fmt.Errorf("Error For Get Cluster Details: %s", err) } @@ -570,9 +570,9 @@ func (gc *GatewayClient) DeletePackage(packageName string) (*types.GatewayRespon return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -664,12 +664,12 @@ func (gc *GatewayClient) BeginInstallation(jsonStr, mdmUsername, mdmPassword, li if httpResp.StatusCode != 202 { - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } - err := json.Unmarshal([]byte(responseString), &gatewayResponse) + err = json.Unmarshal([]byte(responseString), &gatewayResponse) if err != nil { return &gatewayResponse, fmt.Errorf("Error For Begin Installation: %s", err) } @@ -709,9 +709,9 @@ func (gc *GatewayClient) MoveToNextPhase() (*types.GatewayResponse, error) { return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -763,9 +763,9 @@ func (gc *GatewayClient) RetryPhase() (*types.GatewayResponse, error) { return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -817,9 +817,9 @@ func (gc *GatewayClient) AbortOperation() (*types.GatewayResponse, error) { return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -871,9 +871,9 @@ func (gc *GatewayClient) ClearQueueCommand() (*types.GatewayResponse, error) { return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -925,9 +925,9 @@ func (gc *GatewayClient) MoveToIdlePhase() (*types.GatewayResponse, error) { return &gatewayResponse, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode != 200 { @@ -978,9 +978,9 @@ func (gc *GatewayClient) GetInQueueCommand() ([]types.MDMQueueCommandDetails, er return mdmQueueCommandDetails, httpRespError } - responseString, error := extractString(httpResp) - if error != nil { - return mdmQueueCommandDetails, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return mdmQueueCommandDetails, fmt.Errorf("Error Extracting Response: %s", err) } if httpResp.StatusCode == 200 { @@ -1053,7 +1053,7 @@ func (gc *GatewayClient) CheckForCompletionQueueCommands(currentPhase string) (* } // UninstallCluster used for uninstallation of cluster -func (gc *GatewayClient) UninstallCluster(jsonStr, mdmUsername, mdmPassword, liaPassword string, allowNonSecureCommunicationWithMdm, allowNonSecureCommunicationWithLia, disableNonMgmtComponentsAuth, expansion bool) (*types.GatewayResponse, error) { +func (gc *GatewayClient) UninstallCluster(jsonStr, mdmUsername, mdmPassword, liaPassword string, allowNonSecureCommunicationWithMdm, allowNonSecureCommunicationWithLia, disableNonMgmtComponentsAuth, _ bool) (*types.GatewayResponse, error) { var gatewayResponse types.GatewayResponse clusterData, jsonParseError := jsonToMap(jsonStr) @@ -1102,12 +1102,12 @@ func (gc *GatewayClient) UninstallCluster(jsonStr, mdmUsername, mdmPassword, lia if httpResp.StatusCode != 202 { - responseString, error := extractString(httpResp) - if error != nil { - return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", error) + responseString, err := extractString(httpResp) + if err != nil { + return &gatewayResponse, fmt.Errorf("Error Extracting Response: %s", err) } - err := json.Unmarshal([]byte(responseString), &gatewayResponse) + err = json.Unmarshal([]byte(responseString), &gatewayResponse) if err != nil { return &gatewayResponse, fmt.Errorf("Error For Uninstall Cluster: %s", err) } diff --git a/deploy_test.go b/deploy_test.go index 68e015c..d4a5b29 100644 --- a/deploy_test.go +++ b/deploy_test.go @@ -31,13 +31,13 @@ func TestMoveToNextPhase(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) @@ -76,13 +76,13 @@ func TestUninstallCluster(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) @@ -117,13 +117,13 @@ func TestGetClusterDetails(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) From a26855acf6c4d83c94999ae694c053c31c36bdcc Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 04:51:12 -0400 Subject: [PATCH 09/24] Fix golangci-lint warnings in device and fault_set --- device.go | 12 ++++++------ fault_set.go | 16 ++++++++-------- fault_set_test.go | 36 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/device.go b/device.go index e92b60f..26a345b 100644 --- a/device.go +++ b/device.go @@ -139,13 +139,13 @@ func (sds *Sds) FindDevice( } // GetAllDevice returns all device in the system -func (system *System) GetAllDevice() ([]types.Device, error) { +func (s *System) GetAllDevice() ([]types.Device, error) { defer TimeSpent("GetAllDevice", time.Now()) path := "/api/types/Device/instances" var deviceResult []types.Device - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &deviceResult) if err != nil { return nil, err @@ -155,12 +155,12 @@ func (system *System) GetAllDevice() ([]types.Device, error) { } // GetDeviceByField returns a Device list filter by the field -func (system *System) GetDeviceByField( +func (s *System) GetDeviceByField( field, value string, ) ([]types.Device, error) { defer TimeSpent("GetDeviceByField", time.Now()) - devices, err := system.GetAllDevice() + devices, err := s.GetAllDevice() if err != nil { return nil, err } @@ -180,7 +180,7 @@ func (system *System) GetDeviceByField( } // GetDevice returns a device using Device ID -func (system *System) GetDevice(id string) (*types.Device, error) { +func (s *System) GetDevice(id string) (*types.Device, error) { defer TimeSpent("GetDevice", time.Now()) path := fmt.Sprintf( @@ -188,7 +188,7 @@ func (system *System) GetDevice(id string) (*types.Device, error) { id) var deviceResult types.Device - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &deviceResult) if err != nil { return nil, err diff --git a/fault_set.go b/fault_set.go index 01c178d..6f3d401 100644 --- a/fault_set.go +++ b/fault_set.go @@ -75,11 +75,11 @@ func (pd *ProtectionDomain) ModifyFaultSetPerfProfile(id, perfProfile string) er } // GetFaultSetByID will read the fault set using the ID. -func (system *System) GetFaultSetByID(id string) (*types.FaultSet, error) { +func (s *System) GetFaultSetByID(id string) (*types.FaultSet, error) { fs := &types.FaultSet{} path := fmt.Sprintf("/api/instances/FaultSet::%v", id) - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, fs) if err != nil { return nil, err @@ -88,12 +88,12 @@ func (system *System) GetFaultSetByID(id string) (*types.FaultSet, error) { } // GetAllFaultSets returns all fault sets on the system -func (sys *System) GetAllFaultSets() ([]types.FaultSet, error) { +func (s *System) GetAllFaultSets() ([]types.FaultSet, error) { defer TimeSpent("FaultSet", time.Now()) path := "/api/types/FaultSet/instances" var faultsets []types.FaultSet - err := sys.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &faultsets) if err != nil { return nil, err @@ -103,12 +103,12 @@ func (sys *System) GetAllFaultSets() ([]types.FaultSet, error) { } // GetAllSDSByFaultSetID returns SDS details associated with fault set -func (sys *System) GetAllSDSByFaultSetID(faultsetid string) ([]types.Sds, error) { +func (s *System) GetAllSDSByFaultSetID(faultsetid string) ([]types.Sds, error) { defer TimeSpent("FaultSet", time.Now()) path := fmt.Sprintf("/api/instances/FaultSet::%v/relationships/Sds", faultsetid) var faultsets []types.Sds - err := sys.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &faultsets) if err != nil { return nil, err @@ -118,8 +118,8 @@ func (sys *System) GetAllSDSByFaultSetID(faultsetid string) ([]types.Sds, error) } // GetFaultSetByName will read the fault set using the name -func (sys *System) GetFaultSetByName(name string) (*types.FaultSet, error) { - allFaultSets, err := sys.GetAllFaultSets() +func (s *System) GetFaultSetByName(name string) (*types.FaultSet, error) { + allFaultSets, err := s.GetAllFaultSets() if err != nil { return nil, err } diff --git a/fault_set_test.go b/fault_set_test.go index fb11045..ca61397 100644 --- a/fault_set_test.go +++ b/fault_set_test.go @@ -46,16 +46,16 @@ func TestCreateFaultSet(t *testing.T) { Name: "testFaultSet", ProtectionDomainID: "202a0466000000", }, - expected: errors.New("Invalid Protection Domain. Please try again with the correct ID or name."), + expected: errors.New("invalid Protection Domain. Please try again with the correct ID or name"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -89,16 +89,16 @@ func TestGetFaultByID(t *testing.T) { }, { id: "1234", - expected: errors.New("Invalid Fault Set. Please try again with the correct ID or name."), + expected: errors.New("invalid Fault Set. Please try again with the correct ID or name"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -136,16 +136,16 @@ func TestModifyFaultSetName(t *testing.T) { { id: "1234", name: "renameFaultSet", - expected: errors.New("Invalid Fault Set. Please try again with the correct ID or name."), + expected: errors.New("invalid Fault Set. Please try again with the correct ID or name"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -188,16 +188,16 @@ func TestModifyFaultPerfProfile(t *testing.T) { { id: ID, perfProfile: "Invalid", - expected: errors.New("perfProfile should get one of the following values: Compact, HighPerformance, but its value is Invalid."), + expected: errors.New("perfProfile should get one of the following values: Compact, HighPerformance, but its value is Invalid"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -232,16 +232,16 @@ func TestDeleteFaultSet(t *testing.T) { }, { id: "1234", - expected: errors.New("Invalid Fault Set. Please try again with the correct ID or name."), + expected: errors.New("invalid Fault Set. Please try again with the correct ID or name"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -265,7 +265,7 @@ func TestDeleteFaultSet(t *testing.T) { } func TestGetAllFaultSets(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -300,13 +300,13 @@ func TestGetAllFaultSetsSds(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) From 14c7cdffe423aa3d1403651b9fe70393e8b88f88 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 04:51:39 -0400 Subject: [PATCH 10/24] Fix golangci-lint warnings in sdc and sds --- sdc_test.go | 16 ++++++++-------- sds.go | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sdc_test.go b/sdc_test.go index 375285e..20f1dd8 100644 --- a/sdc_test.go +++ b/sdc_test.go @@ -29,19 +29,19 @@ func Test_FindVolumes(t *testing.T) { type checkFn func(*testing.T, []*Volume, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, vols []*Volume, err error) { + hasNoError := func(t *testing.T, _ []*Volume, err error) { if err != nil { t.Fatalf("expected no error") } } checkLength := func(length int) func(t *testing.T, vols []*Volume, err error) { - return func(t *testing.T, vols []*Volume, err error) { + return func(t *testing.T, vols []*Volume, _ error) { assert.Equal(t, length, len(vols)) } } - hasError := func(t *testing.T, vols []*Volume, err error) { + hasError := func(t *testing.T, _ []*Volume, err error) { if err == nil { t.Fatalf("expected error") } @@ -150,13 +150,13 @@ func TestRenameSdc(t *testing.T) { } // mock a powerflex endpoint - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -181,20 +181,20 @@ func TestApproveSdc(t *testing.T) { type checkFn func(*testing.T, *types.ApproveSdcByGUIDResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.ApproveSdcByGUIDResponse, err error) { + hasNoError := func(t *testing.T, _ *types.ApproveSdcByGUIDResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.ApproveSdcByGUIDResponse, err error) { + hasError := func(t *testing.T, _ *types.ApproveSdcByGUIDResponse, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(sdcId string) func(t *testing.T, resp *types.ApproveSdcByGUIDResponse, err error) { - return func(t *testing.T, resp *types.ApproveSdcByGUIDResponse, err error) { + return func(t *testing.T, resp *types.ApproveSdcByGUIDResponse, _ error) { assert.Equal(t, sdcId, resp.SdcID) } } diff --git a/sds.go b/sds.go index 2953d51..290a676 100644 --- a/sds.go +++ b/sds.go @@ -166,12 +166,12 @@ func (pd *ProtectionDomain) GetSds() ([]types.Sds, error) { } // GetAllSds returns all SDS on the system -func (sys *System) GetAllSds() ([]types.Sds, error) { +func (s *System) GetAllSds() ([]types.Sds, error) { defer TimeSpent("GetSds", time.Now()) path := "/api/types/Sds/instances" var sdss []types.Sds - err := sys.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &sdss) if err != nil { return nil, err @@ -203,13 +203,13 @@ func (pd *ProtectionDomain) FindSds( } // GetSdsByID returns a Sds by ID -func (sys *System) GetSdsByID(id string) (types.Sds, error) { +func (s *System) GetSdsByID(id string) (types.Sds, error) { defer TimeSpent("GetSdsByID", time.Now()) path := fmt.Sprintf("/api/instances/Sds::%s", id) var sds types.Sds - err := sys.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &sds) return sds, err @@ -411,12 +411,12 @@ func (pd *ProtectionDomain) SetSdsPerformanceProfile(id, perfProf string) error } // FindSds returns a Sds using system instance -func (sys *System) FindSds( +func (s *System) FindSds( field, value string, ) (*types.Sds, error) { defer TimeSpent("FindSds", time.Now()) - sdss, err := sys.GetAllSds() + sdss, err := s.GetAllSds() if err != nil { return nil, err } From 20759706a3dab1a8a5b8b859b85694506cef338c Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 04:52:23 -0400 Subject: [PATCH 11/24] Fix golangci-lint warnings in snapshot_policy and storagepool --- snapshot_policy.go | 36 ++++++++++++------------- snapshot_policy_test.go | 60 ++++++++++++++++++++--------------------- storagepool.go | 8 +++--- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/snapshot_policy.go b/snapshot_policy.go index eaa04ba..89b8da8 100644 --- a/snapshot_policy.go +++ b/snapshot_policy.go @@ -21,12 +21,12 @@ import ( ) // CreateSnapshotPolicy creates a snapshot policy on the PowerFlex array -func (system *System) CreateSnapshotPolicy(snapPolicy *types.SnapshotPolicyCreateParam) (string, error) { +func (s *System) CreateSnapshotPolicy(snapPolicy *types.SnapshotPolicyCreateParam) (string, error) { defer TimeSpent("crate snapshot policy", time.Now()) path := fmt.Sprintf("/api/types/SnapshotPolicy/instances") snapResp := types.SnapShotPolicyCreateResp{} - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, snapPolicy, &snapResp) if err != nil { return "", err @@ -35,10 +35,10 @@ func (system *System) CreateSnapshotPolicy(snapPolicy *types.SnapshotPolicyCreat } // RemoveSnapshotPolicy removes a snapshot policy from the PowerFlex array -func (system *System) RemoveSnapshotPolicy(id string) error { +func (s *System) RemoveSnapshotPolicy(id string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/removeSnapshotPolicy", id) removeParam := &types.EmptyPayload{} - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, removeParam, nil) if err != nil { return err @@ -47,12 +47,12 @@ func (system *System) RemoveSnapshotPolicy(id string) error { } // RenameSnapshotPolicy renames a snapshot policy -func (system *System) RenameSnapshotPolicy(id, name string) error { +func (s *System) RenameSnapshotPolicy(id, name string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/renameSnapshotPolicy", id) renameSnap := &types.SnapshotPolicyRenameParam{ NewName: name, } - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, renameSnap, nil) if err != nil { return err @@ -61,9 +61,9 @@ func (system *System) RenameSnapshotPolicy(id, name string) error { } // ModifySnapshotPolicy modifies a snapshot policy -func (system *System) ModifySnapshotPolicy(modifysnapPolicy *types.SnapshotPolicyModifyParam, id string) error { +func (s *System) ModifySnapshotPolicy(modifysnapPolicy *types.SnapshotPolicyModifyParam, id string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/modifySnapshotPolicy", id) - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, modifysnapPolicy, nil) if err != nil { return err @@ -72,9 +72,9 @@ func (system *System) ModifySnapshotPolicy(modifysnapPolicy *types.SnapshotPolic } // AssignVolumeToSnapshotPolicy assigns volume to a snapshot policy -func (system *System) AssignVolumeToSnapshotPolicy(assignVoltoSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error { +func (s *System) AssignVolumeToSnapshotPolicy(assignVoltoSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/addSourceVolumeToSnapshotPolicy", id) - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, assignVoltoSnap, nil) if err != nil { return err @@ -83,9 +83,9 @@ func (system *System) AssignVolumeToSnapshotPolicy(assignVoltoSnap *types.Assign } // UnassignVolumeFromSnapshotPolicy unassigns volume from a snapshot policy -func (system *System) UnassignVolumeFromSnapshotPolicy(UnassignVolFromSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error { +func (s *System) UnassignVolumeFromSnapshotPolicy(UnassignVolFromSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/removeSourceVolumeFromSnapshotPolicy", id) - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, UnassignVolFromSnap, nil) if err != nil { return err @@ -94,10 +94,10 @@ func (system *System) UnassignVolumeFromSnapshotPolicy(UnassignVolFromSnap *type } // PauseSnapshotPolicy pause a snapshot policy -func (system *System) PauseSnapshotPolicy(id string) error { +func (s *System) PauseSnapshotPolicy(id string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/pauseSnapshotPolicy", id) pauseParam := &types.EmptyPayload{} - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, pauseParam, nil) if err != nil { return err @@ -106,10 +106,10 @@ func (system *System) PauseSnapshotPolicy(id string) error { } // ResumeSnapshotPolicy resume a snapshot policy which was paused -func (system *System) ResumeSnapshotPolicy(id string) error { +func (s *System) ResumeSnapshotPolicy(id string) error { path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/resumeSnapshotPolicy", id) resumeParam := &types.EmptyPayload{} - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodPost, path, resumeParam, nil) if err != nil { return err @@ -118,10 +118,10 @@ func (system *System) ResumeSnapshotPolicy(id string) error { } // GetSourceVolume returns a list of volumes assigned to snapshot policy -func (system *System) GetSourceVolume(id string) ([]*types.Volume, error) { +func (s *System) GetSourceVolume(id string) ([]*types.Volume, error) { var volumes []*types.Volume path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/relationships/SourceVolume", id) - err := system.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &volumes) if err != nil { return nil, err diff --git a/snapshot_policy_test.go b/snapshot_policy_test.go index e2b4987..9b51f22 100644 --- a/snapshot_policy_test.go +++ b/snapshot_policy_test.go @@ -48,16 +48,16 @@ func TestCreateSnapshotPolicy(t *testing.T) { NumOfRetainedSnapshotsPerLevel: []string{"1"}, SnapshotAccessMode: "Invalid", }, - expected: errors.New("accessMode should get one of the following values: ReadWrite, ReadOnly, but its value is Invalid."), + expected: errors.New("accessMode should get one of the following values: ReadWrite, ReadOnly, but its value is Invalid"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -96,16 +96,16 @@ func TestModifySnapshotPolicyName(t *testing.T) { { id: "1234", name: "renameSnapshotPolicy", - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -149,16 +149,16 @@ func TestModifySnapshotPolicy(t *testing.T) { AutoSnapshotCreationCadenceInMin: "6", NumOfRetainedSnapshotsPerLevel: []string{"2", "3"}, }, - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -201,23 +201,23 @@ func TestAssignSnapshotPolicy(t *testing.T) { snap: &types.AssignVolumeToSnapshotPolicyParam{ SourceVolumeID: "edba1bff00000001", }, - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, { id: ID2, snap: &types.AssignVolumeToSnapshotPolicyParam{ SourceVolumeID: "edba1bff000000", }, - expected: errors.New("Invalid volume. Please try again with a valid ID or name."), + expected: errors.New("Invalid volume. Please try again with a valid ID or name"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -262,7 +262,7 @@ func TestUnassignSnapshotPolicy(t *testing.T) { SourceVolumeID: "edba1bff00000001", AutoSnapshotRemovalAction: "Remove", }, - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, { id: ID2, @@ -270,7 +270,7 @@ func TestUnassignSnapshotPolicy(t *testing.T) { SourceVolumeID: "edba1bff000000", AutoSnapshotRemovalAction: "Remove", }, - expected: errors.New("Invalid volume. Please try again with a valid ID or name."), + expected: errors.New("Invalid volume. Please try again with a valid ID or name"), }, { id: ID2, @@ -278,16 +278,16 @@ func TestUnassignSnapshotPolicy(t *testing.T) { SourceVolumeID: "edba1bff000000", AutoSnapshotRemovalAction: "Invalid", }, - expected: errors.New("autoSnapshotRemovalAction should get one of the following values: Remove, Detach, but its value is Invalid."), + expected: errors.New("autoSnapshotRemovalAction should get one of the following values: Remove, Detach, but its value is Invalid"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -323,16 +323,16 @@ func TestPauseSnapshotPolicy(t *testing.T) { }, { id: "Invalid", - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -368,16 +368,16 @@ func TestResumeSnapshotPolicy(t *testing.T) { }, { id: "Invalid", - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -413,16 +413,16 @@ func TestDeleteSnapshotPolicy(t *testing.T) { }, { id: "Invalid", - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -458,16 +458,16 @@ func TestGetSourceVolume(t *testing.T) { }, { id: "Invalid", - expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) diff --git a/storagepool.go b/storagepool.go index e3fdc64..b3f5bf1 100644 --- a/storagepool.go +++ b/storagepool.go @@ -419,13 +419,13 @@ func (sp *StoragePool) GetSDSStoragePool() ([]types.Sds, error) { } // GetStoragePoolByID returns a Storagepool by ID -func (sys *System) GetStoragePoolByID(id string) (*types.StoragePool, error) { +func (s *System) GetStoragePoolByID(id string) (*types.StoragePool, error) { defer TimeSpent("GetStoragePoolByID", time.Now()) path := fmt.Sprintf("/api/instances/StoragePool::%s", id) var storagepool *types.StoragePool - err := sys.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &storagepool) if err != nil { return nil, err @@ -435,12 +435,12 @@ func (sys *System) GetStoragePoolByID(id string) (*types.StoragePool, error) { } // GetAllStoragePools returns all Storage pools on the system -func (sys *System) GetAllStoragePools() ([]types.StoragePool, error) { +func (s *System) GetAllStoragePools() ([]types.StoragePool, error) { defer TimeSpent("GetStoragepool", time.Now()) path := "/api/types/StoragePool/instances" var storagepools []types.StoragePool - err := sys.client.getJSONWithRetry( + err := s.client.getJSONWithRetry( http.MethodGet, path, nil, &storagepools) if err != nil { return nil, err From d54e68e492326b6583d9b19ac642904acd6358af Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 04:59:05 -0400 Subject: [PATCH 12/24] Fix golangci-lint warnings in node and replication --- node_test.go | 22 +++++++++++----------- replication.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/node_test.go b/node_test.go index 99755b7..bf40bcd 100644 --- a/node_test.go +++ b/node_test.go @@ -23,7 +23,7 @@ import ( ) func TestGetNodes(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -56,13 +56,13 @@ func TestGetNodeByID(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewGateway(svr.URL, "", "", true, false) client.version = "4.5" if err != nil { @@ -100,13 +100,13 @@ func TestGetNodePoolByID(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewGateway(svr.URL, "", "", true, false) client.version = "4.5" if err != nil { @@ -128,7 +128,7 @@ func TestGetNodePoolByID(t *testing.T) { } func TestGetNodeByFilters(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -145,7 +145,7 @@ func TestGetNodeByFilters(t *testing.T) { } func TestGetNodePoolByName(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -162,7 +162,7 @@ func TestGetNodePoolByName(t *testing.T) { } func TestGetNodePoolByNameError(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, `{"error":"Resource not found"}`) })) @@ -180,7 +180,7 @@ func TestGetNodePoolByNameError(t *testing.T) { } func TestGetNodePoolByIDNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, `{"error":"Resource not found"}`) })) @@ -198,7 +198,7 @@ func TestGetNodePoolByIDNegative(t *testing.T) { } func TestGetNodeByIDNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, `{"error":"Resource not found"}`) })) @@ -216,7 +216,7 @@ func TestGetNodeByIDNegative(t *testing.T) { } func TestGetAllNodesNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) diff --git a/replication.go b/replication.go index 6b84ca1..9f956d0 100644 --- a/replication.go +++ b/replication.go @@ -250,7 +250,7 @@ func (rcg *ReplicationConsistencyGroup) ExecuteFailoverOnReplicationGroup() erro } // ExecuteSwitchoverOnReplicationGroup sets the ReplicationconsistencyGroup into a switchover state. -func (rcg *ReplicationConsistencyGroup) ExecuteSwitchoverOnReplicationGroup(force bool) error { +func (rcg *ReplicationConsistencyGroup) ExecuteSwitchoverOnReplicationGroup(_ bool) error { defer TimeSpent("ExecuteSwitchoverOnReplicationGroup", time.Now()) uri := "/api/instances/ReplicationConsistencyGroup::" + rcg.ReplicationConsistencyGroup.ID + "/action/switchoverReplicationConsistencyGroup" From da786da9ac5b5e07af74117069d9d45b323b651b Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:21:23 -0400 Subject: [PATCH 13/24] Fix golangci-lint warnings in service --- service.go | 573 +++++++++++++++++++++--------------------------- service_test.go | 14 +- 2 files changed, 259 insertions(+), 328 deletions(-) diff --git a/service.go b/service.go index 658c0ee..b67aaba 100644 --- a/service.go +++ b/service.go @@ -94,96 +94,83 @@ func (gc *GatewayClient) DeployService(deploymentName, deploymentDesc, serviceTe responseString, _ = extractString(httpResp) - if httpResp.StatusCode == 200 && responseString != "" { - var templateData map[string]interface{} - - parseError := json.Unmarshal([]byte(responseString), &templateData) - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Template: %s", parseError) - } - - configuredNode, _ := templateData["serverCount"].(float64) - - configuredNodeCount := int(configuredNode) - - nodes, _ := strconv.Atoi(nodes) + if httpResp.StatusCode != http.StatusOK || responseString == "" { + return nil, fmt.Errorf("Service Template Not Found") + } - if nodes > 0 { - nodeDiff := nodes - configuredNodeCount + var templateData map[string]interface{} + parseError := json.Unmarshal([]byte(responseString), &templateData) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Template: %s", parseError) + } - if nodeDiff != 0 { - return nil, fmt.Errorf("Node count is not matching with Service Template") - } - } + configuredNode, _ := templateData["serverCount"].(float64) + configuredNodeCount := int(configuredNode) + nodesCount, _ := strconv.Atoi(nodes) + if nodesCount > 0 { + nodeDiff := nodesCount - configuredNodeCount - deploymentPayload := map[string]interface{}{ - "deploymentName": deploymentName, - "deploymentDescription": deploymentDesc, - "serviceTemplate": templateData, - "updateServerFirmware": true, - "firmwareRepositoryId": firmwareRepositoryID, // TODO + if nodeDiff != 0 { + return nil, fmt.Errorf("Node count is not matching with Service Template") } + } - deploymentPayloadJson, _ := json.Marshal(deploymentPayload) - - req, httpError := http.NewRequest("POST", gc.host+"/Api/V1/Deployment", bytes.NewBuffer(deploymentPayloadJson)) - if httpError != nil { - return nil, httpError - } - if gc.version == "4.0" { - req.Header.Set("Authorization", "Bearer "+gc.token) + deploymentPayload := map[string]interface{}{ + "deploymentName": deploymentName, + "deploymentDescription": deploymentDesc, + "serviceTemplate": templateData, + "updateServerFirmware": true, + "firmwareRepositoryId": firmwareRepositoryID, // TODO + } - err := setCookie(req.Header, gc.host) - if err != nil { - return nil, fmt.Errorf("Error While Handling Cookie: %s", err) - } - } else { - req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) - } - req.Header.Set("Content-Type", "application/json") + deploymentPayloadJSON, _ := json.Marshal(deploymentPayload) + req, httpError = http.NewRequest("POST", gc.host+"/Api/V1/Deployment", bytes.NewBuffer(deploymentPayloadJSON)) + if httpError != nil { + return nil, httpError + } - client := gc.http - httpResp, httpRespError := client.Do(req) - if httpRespError != nil { - return nil, httpRespError - } + if gc.version == "4.0" { + req.Header.Set("Authorization", "Bearer "+gc.token) - responseString, error := extractString(httpResp) - if error != nil { - return nil, fmt.Errorf("Error Extracting Response: %s", error) + err := setCookie(req.Header, gc.host) + if err != nil { + return nil, fmt.Errorf("Error While Handling Cookie: %s", err) } + } else { + req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) + } + req.Header.Set("Content-Type", "application/json") - if httpResp.StatusCode == 200 { - - var deploymentResponse types.ServiceResponse - - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - - deploymentResponse.StatusCode = 200 - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } - - return &deploymentResponse, nil - - } else { - var deploymentResponse types.ServiceFailedResponse - - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - - deploymentResponse.StatusCode = 400 + client = gc.http + httpResp, httpRespError = client.Do(req) + if httpRespError != nil { + return nil, httpRespError + } - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } + responseString, ioErr := extractString(httpResp) + if ioErr != nil { + return nil, fmt.Errorf("Error Extracting Response: %s", ioErr) + } - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", deploymentResponse.Messages[0].DisplayMessage) + if httpResp.StatusCode != 200 { + var deploymentResponse types.ServiceFailedResponse + parseError = json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) } - } else { - return nil, fmt.Errorf("Service Template Not Found") + deploymentResponse.StatusCode = 400 + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", deploymentResponse.Messages[0].DisplayMessage) + } + + var deploymentResponse types.ServiceResponse + parseError = json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) } + + deploymentResponse.StatusCode = 200 + return &deploymentResponse, nil } func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentDesc, nodes, nodename string) (*types.ServiceResponse, error) { @@ -218,249 +205,222 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD responseString, _ := extractString(httpResp) - if httpResp.StatusCode == 200 && responseString != "" { - - var deploymentResponse types.ServiceResponse - + if httpResp.StatusCode != 200 || responseString == "" { + var deploymentResponse types.ServiceFailedResponse parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) if parseError != nil { return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) } + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", deploymentResponse.Messages[0].DisplayMessage) + } - deployedNodes := deploymentResponse.ServiceTemplate.ServerCount + var deploymentResponse types.ServiceResponse + parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) + } - var deploymentPayloadJson []byte + var deploymentPayloadJSON []byte + deployedNodes := deploymentResponse.ServiceTemplate.ServerCount + nodesCount, _ := strconv.Atoi(nodes) + nodeDiff := nodesCount - deployedNodes - nodes, _ := strconv.Atoi(nodes) + if nodeDiff >= 1 { + var deploymentData map[string]interface{} - nodeDiff := nodes - deployedNodes + parseError := json.Unmarshal([]byte(responseString), &deploymentData) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) + } - if nodeDiff >= 1 { + deploymentData["deploymentName"] = deploymentName + deploymentData["deploymentDescription"] = deploymentDesc - var deploymentData map[string]interface{} + // Access the "components" field + serviceTemplate, ok := deploymentData["serviceTemplate"].(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") + } - parseError := json.Unmarshal([]byte(responseString), &deploymentData) - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } + components, ok := serviceTemplate["components"].([]interface{}) + if !ok { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") + } - deploymentData["deploymentName"] = deploymentName + // Find the component with type "SERVER" + var serverComponent map[string]interface{} - deploymentData["deploymentDescription"] = deploymentDesc + componentFound := false - // Access the "components" field - serviceTemplate, ok := deploymentData["serviceTemplate"].(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") + for _, comp := range components { + comp := comp.(map[string]interface{}) + if comp["type"].(string) == "SERVER" && comp["name"].(string) == nodename { + serverComponent = comp + componentFound = true + break } + } - components, ok := serviceTemplate["components"].([]interface{}) - if !ok { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") + if !componentFound { + return nil, fmt.Errorf("Host to clone from not found") + } + + for numberOfNode := 1; numberOfNode <= nodeDiff; numberOfNode++ { + // Deep copy the component + clonedComponent := make(map[string]interface{}) + for key, value := range serverComponent { + clonedComponent[key] = value } - // Find the component with type "SERVER" - var serverComponent map[string]interface{} + uuid := uuid.New().String() - componentFound := false + // Modify ID and GUID of the cloned component + clonedComponent["id"] = uuid + clonedComponent["name"] = uuid + clonedComponent["brownfield"] = false + clonedComponent["identifier"] = nil + clonedComponent["asmGUID"] = nil + clonedComponent["puppetCertName"] = nil + clonedComponent["osPuppetCertName"] = nil + clonedComponent["managementIpAddress"] = nil - for _, comp := range components { - comp := comp.(map[string]interface{}) - if comp["type"].(string) == "SERVER" && comp["name"].(string) == nodename { - serverComponent = comp - componentFound = true - break - } + // Deep copy resources + resources, ok := clonedComponent["resources"].([]interface{}) + if !ok { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") } - if !componentFound { - return nil, fmt.Errorf("Host to clone from not found") + clonedResources := make([]interface{}, len(resources)) + for i, res := range resources { + resCopy := make(map[string]interface{}) + for k, v := range res.(map[string]interface{}) { + resCopy[k] = v + } + clonedResources[i] = resCopy + } + clonedComponent["resources"] = clonedResources + + // Exclude list of parameters to skip + excludeList := map[string]bool{ + "razor_image": true, + "scaleio_enabled": true, + "scaleio_role": true, + "compression_enabled": true, + "replication_enabled": true, } - for numberOfNode := 1; numberOfNode <= nodeDiff; numberOfNode++ { - - // Deep copy the component - clonedComponent := make(map[string]interface{}) - for key, value := range serverComponent { - clonedComponent[key] = value - } + // Iterate over resources to modify parameters + for _, comp := range clonedResources { + comp := comp.(map[string]interface{}) + if comp["id"].(string) == "asm::server" { - uuid := uuid.New().String() - - // Modify ID and GUID of the cloned component - clonedComponent["id"] = uuid - clonedComponent["name"] = uuid - clonedComponent["brownfield"] = false - clonedComponent["identifier"] = nil - clonedComponent["asmGUID"] = nil - clonedComponent["puppetCertName"] = nil - clonedComponent["osPuppetCertName"] = nil - clonedComponent["managementIpAddress"] = nil - - // Deep copy resources - resources, ok := clonedComponent["resources"].([]interface{}) - if !ok { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") - } + comp["guid"] = nil - clonedResources := make([]interface{}, len(resources)) - for i, res := range resources { - resCopy := make(map[string]interface{}) - for k, v := range res.(map[string]interface{}) { - resCopy[k] = v + parameters, ok := comp["parameters"].([]interface{}) + if !ok { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") } - clonedResources[i] = resCopy - } - clonedComponent["resources"] = clonedResources - - // Exclude list of parameters to skip - excludeList := map[string]bool{ - "razor_image": true, - "scaleio_enabled": true, - "scaleio_role": true, - "compression_enabled": true, - "replication_enabled": true, - } - - // Iterate over resources to modify parameters - for _, comp := range clonedResources { - comp := comp.(map[string]interface{}) - if comp["id"].(string) == "asm::server" { - comp["guid"] = nil - - parameters, ok := comp["parameters"].([]interface{}) - if !ok { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment") - } - - clonedParams := make([]interface{}, len(parameters)) - for i, param := range parameters { - paramCopy := make(map[string]interface{}) - for k, v := range param.(map[string]interface{}) { - paramCopy[k] = v - } - clonedParams[i] = paramCopy + clonedParams := make([]interface{}, len(parameters)) + for i, param := range parameters { + paramCopy := make(map[string]interface{}) + for k, v := range param.(map[string]interface{}) { + paramCopy[k] = v } + clonedParams[i] = paramCopy + } - for _, parameter := range clonedParams { - parameter := parameter.(map[string]interface{}) - if !excludeList[parameter["id"].(string)] { - if parameter["id"].(string) == "scaleio_mdm_role" { - parameter["guid"] = nil - parameter["value"] = "standby_mdm" - } else { - parameter["guid"] = nil - parameter["value"] = nil - } + for _, parameter := range clonedParams { + parameter := parameter.(map[string]interface{}) + if !excludeList[parameter["id"].(string)] { + if parameter["id"].(string) == "scaleio_mdm_role" { + parameter["guid"] = nil + parameter["value"] = "standby_mdm" + } else { + parameter["guid"] = nil + parameter["value"] = nil } } - - // Update parameters in the component - comp["parameters"] = clonedParams } - } - - // Append the cloned component back to the components array - components = append(components, clonedComponent) - - // Update serviceTemplate with modified components - serviceTemplate["components"] = components - - } - - // Update deploymentData with modified serviceTemplate - deploymentData["serviceTemplate"] = serviceTemplate - // Update other fields as needed - deploymentData["scaleUp"] = true - deploymentData["retry"] = true - - // Marshal deploymentData to JSON - deploymentPayloadJson, _ = json.Marshal(deploymentData) - - } else if nodeDiff == 0 { - - deploymentResponse, jsonParseError := jsonToMap(responseString) - if jsonParseError != nil { - return nil, jsonParseError + // Update parameters in the component + comp["parameters"] = clonedParams + } } - deploymentResponse["deploymentName"] = deploymentName - - deploymentResponse["deploymentDescription"] = deploymentDesc - - deploymentPayloadJson, _ = json.Marshal(deploymentResponse) - } else if nodeDiff < 0 { - return nil, fmt.Errorf("Removing node(s) is not supported") + // Append the cloned component back to the components array + components = append(components, clonedComponent) + // Update serviceTemplate with modified components + serviceTemplate["components"] = components } - req, httpError := http.NewRequest("PUT", gc.host+"/Api/V1/Deployment/"+deploymentID, bytes.NewBuffer(deploymentPayloadJson)) - if httpError != nil { - return nil, httpError - } - if gc.version == "4.0" { - req.Header.Set("Authorization", "Bearer "+gc.token) + // Update deploymentData with modified serviceTemplate + deploymentData["serviceTemplate"] = serviceTemplate + // Update other fields as needed + deploymentData["scaleUp"] = true + deploymentData["retry"] = true + // Marshal deploymentData to JSON + deploymentPayloadJSON, _ = json.Marshal(deploymentData) - err := setCookie(req.Header, gc.host) - if err != nil { - return nil, fmt.Errorf("Error While Handling Cookie: %s", err) - } - } else { - req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) - } - req.Header.Set("Content-Type", "application/json") - - client := gc.http - httpResp, httpRespError := client.Do(req) - if httpRespError != nil { - return nil, httpRespError - } + } else if nodeDiff == 0 { - responseString, error := extractString(httpResp) - if error != nil { - return nil, fmt.Errorf("Error Extracting Response: %s", error) + deploymentResponse, jsonParseError := jsonToMap(responseString) + if jsonParseError != nil { + return nil, jsonParseError } - if httpResp.StatusCode == 200 { - - var deploymentResponse types.ServiceResponse - - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - - deploymentResponse.StatusCode = 200 - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } - - return &deploymentResponse, nil + deploymentResponse["deploymentName"] = deploymentName + deploymentResponse["deploymentDescription"] = deploymentDesc + deploymentPayloadJSON, _ = json.Marshal(deploymentResponse) + } else if nodeDiff < 0 { + return nil, fmt.Errorf("Removing node(s) is not supported") + } - } else { - var deploymentResponse types.ServiceFailedResponse + req, httpError = http.NewRequest("PUT", gc.host+"/Api/V1/Deployment/"+deploymentID, bytes.NewBuffer(deploymentPayloadJSON)) + if httpError != nil { + return nil, httpError + } - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) + if gc.version == "4.0" { + req.Header.Set("Authorization", "Bearer "+gc.token) - deploymentResponse.StatusCode = 400 + err := setCookie(req.Header, gc.host) + if err != nil { + return nil, fmt.Errorf("Error While Handling Cookie: %s", err) + } + } else { + req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) + } + req.Header.Set("Content-Type", "application/json") - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } + client = gc.http + httpResp, httpRespError = client.Do(req) + if httpRespError != nil { + return nil, httpRespError + } - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", deploymentResponse.Messages[0].DisplayMessage) - } + responseString, ioErr := extractString(httpResp) + if ioErr != nil { + return nil, fmt.Errorf("Error Extracting Response: %s", ioErr) + } - } else { + if httpResp.StatusCode != http.StatusOK { var deploymentResponse types.ServiceFailedResponse - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - if parseError != nil { return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) } - + deploymentResponse.StatusCode = 400 return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", deploymentResponse.Messages[0].DisplayMessage) } + + deploymentResponse = types.ServiceResponse{} + parseError = json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) + } + deploymentResponse.StatusCode = 200 + return &deploymentResponse, nil } // Function to check if string is not present in list @@ -516,7 +476,6 @@ func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken boo } responseBody := string(bs) - result := make(map[string]interface{}) jsonErr := json.Unmarshal([]byte(responseBody), &result) if err != nil { @@ -524,7 +483,6 @@ func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken boo } token := result["access_token"].(string) - gc.token = token } @@ -554,31 +512,23 @@ func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken boo if httpRespError != nil { return nil, httpRespError } + if httpResp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("Couldn't find service with the given filter") + } + var deploymentResponse types.ServiceResponse responseString, _ := extractString(httpResp) - - if httpResp.StatusCode == 200 { - - var deploymentResponse types.ServiceResponse - - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } - - return &deploymentResponse, nil - - } else { - return nil, fmt.Errorf("Couldn't find service with the given filter") + parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) } + return &deploymentResponse, nil } func (gc *GatewayClient) GetServiceDetailsByFilter(filter, value string) ([]types.ServiceResponse, error) { defer TimeSpent("GetServiceDetailsByFilter", time.Now()) encodedValue := url.QueryEscape(value) - path := fmt.Sprintf("/Api/V1/Deployment?filter=eq,%v,%v", filter, encodedValue) req, httpError := http.NewRequest("GET", gc.host+path, nil) @@ -605,28 +555,21 @@ func (gc *GatewayClient) GetServiceDetailsByFilter(filter, value string) ([]type if httpRespError != nil { return nil, httpRespError } + if httpResp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("Couldn't find service with the given filter") + } + var deploymentResponse []types.ServiceResponse responseString, _ := extractString(httpResp) - - if httpResp.StatusCode == 200 { - - var deploymentResponse []types.ServiceResponse - - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } - - if len(deploymentResponse) == 0 { - return nil, fmt.Errorf("Couldn't find service with the given filter") - } - - return deploymentResponse, nil - - } else { + parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) + } + if len(deploymentResponse) == 0 { return nil, fmt.Errorf("Couldn't find service with the given filter") } + + return deploymentResponse, nil } func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) { @@ -644,7 +587,6 @@ func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) if err != nil { return nil, fmt.Errorf("Error While Handling Cookie: %s", err) } - } else { req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) } @@ -656,34 +598,27 @@ func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) if httpRespError != nil { return nil, httpRespError } + if httpResp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("Couldn't find service with the given filter") + } + var deploymentResponse []types.ServiceResponse responseString, _ := extractString(httpResp) - - if httpResp.StatusCode == 200 { - - var deploymentResponse []types.ServiceResponse - - parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) - } - - return deploymentResponse, nil - - } else { - return nil, fmt.Errorf("Couldn't find service with the given filter") + parseError := json.Unmarshal([]byte(responseString), &deploymentResponse) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Deployment: %s", parseError) } + return deploymentResponse, nil } -func (gc *GatewayClient) DeleteService(serviceId, serversInInventory, serversManagedState string) (*types.ServiceResponse, error) { +func (gc *GatewayClient) DeleteService(serviceID, serversInInventory, serversManagedState string) (*types.ServiceResponse, error) { var deploymentResponse types.ServiceResponse deploymentResponse.StatusCode = 400 defer TimeSpent("DeleteService", time.Now()) - req, httpError := http.NewRequest("DELETE", gc.host+"/Api/V1/Deployment/"+serviceId+"?serversInInventory="+serversInInventory+"&resourceState="+serversManagedState, nil) + req, httpError := http.NewRequest("DELETE", gc.host+"/Api/V1/Deployment/"+serviceID+"?serversInInventory="+serversInInventory+"&resourceState="+serversManagedState, nil) if httpError != nil { return nil, httpError } @@ -695,7 +630,6 @@ func (gc *GatewayClient) DeleteService(serviceId, serversInInventory, serversMan if err != nil { return nil, fmt.Errorf("Error While Handling Cookie: %s", err) } - } else { req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) } @@ -709,11 +643,8 @@ func (gc *GatewayClient) DeleteService(serviceId, serversInInventory, serversMan } if httpResp.StatusCode == 204 { - deploymentResponse.StatusCode = 200 - return &deploymentResponse, nil } - return nil, fmt.Errorf("Couldn't delete service") } diff --git a/service_test.go b/service_test.go index 62c086d..ce75ff8 100644 --- a/service_test.go +++ b/service_test.go @@ -23,7 +23,7 @@ import ( ) func TestGetAllDeployeService(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -55,13 +55,13 @@ func TestGetDeployeServiceByID(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { GC, err := NewGateway(svr.URL, "", "", true, true) if err != nil { t.Fatal(err) @@ -82,7 +82,7 @@ func TestGetDeployeServiceByID(t *testing.T) { } func TestGetDeployeServiceByFilters(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -98,7 +98,7 @@ func TestGetDeployeServiceByFilters(t *testing.T) { } func TestGetDeployeServiceByIDNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) @@ -115,7 +115,7 @@ func TestGetDeployeServiceByIDNegative(t *testing.T) { } func TestGetDeployeServiceByFiltersNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) @@ -132,7 +132,7 @@ func TestGetDeployeServiceByFiltersNegative(t *testing.T) { } func TestGetAllDeployeServiceNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) From 4b73d43a12843e3f0f28dd26a3f23be7a8478e00 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:23:19 -0400 Subject: [PATCH 14/24] Fix golangci-lint warnings in sso_user_test --- sso_user_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sso_user_test.go b/sso_user_test.go index 1b33636..665119f 100644 --- a/sso_user_test.go +++ b/sso_user_test.go @@ -50,13 +50,13 @@ func TestCreateSSOUser(t *testing.T) { expected: errors.New("Invalid enum value"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -91,13 +91,13 @@ func TestGetSSOUser(t *testing.T) { expected: errors.New("error getting user details"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -128,13 +128,13 @@ func TestGetSSOUserByFilters(t *testing.T) { expected: nil, }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -176,13 +176,13 @@ func TestModifySSOUser(t *testing.T) { expected: errors.New("Invalid enum value"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -217,13 +217,13 @@ func TestResetSSOUserPassword(t *testing.T) { expected: nil, }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -258,13 +258,13 @@ func TestDeleteSSOUser(t *testing.T) { expected: errors.New("HTTP 404 Not Found"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -285,7 +285,7 @@ func TestDeleteSSOUser(t *testing.T) { } func TestGetSSOUserNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, `{"error":"User 93634330-6ffd-4d17-a22a-d3ec701e73d4 not found"}`) })) @@ -302,7 +302,7 @@ func TestGetSSOUserNegative(t *testing.T) { } func TestDeleteSSOUserNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) fmt.Fprintln(w, `{"error":"User 93634330-6ffd-4d17-a22a-d3ec701e73d4 not found"}`) })) @@ -318,7 +318,7 @@ func TestDeleteSSOUserNegative(t *testing.T) { } func TestCreateSSOUserNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusBadRequest) fmt.Fprintln(w, `{"error":"Invalid enum value"}`) })) From ec748203b6630934e2e1eb24fa318c294b4dad20 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:24:24 -0400 Subject: [PATCH 15/24] Fix golangci-lint warnings in system_limit_test --- system_limit_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system_limit_test.go b/system_limit_test.go index 13c2bfe..64f676b 100644 --- a/system_limit_test.go +++ b/system_limit_test.go @@ -28,13 +28,13 @@ func TestGetSystemLimits(t *testing.T) { type checkFn func(*testing.T, *types.QuerySystemLimitsResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) { + hasNoError := func(t *testing.T, _ *types.QuerySystemLimitsResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) { + hasError := func(t *testing.T, _ *types.QuerySystemLimitsResponse, err error) { if err == nil { t.Fatalf("expected error") } From 5a0b9e1b64b240c65b8cdf641118df4b039c124b Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:26:29 -0400 Subject: [PATCH 16/24] Fix golangci-lint warnings in system_test --- system_test.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/system_test.go b/system_test.go index ea06fb3..71bfd2b 100644 --- a/system_test.go +++ b/system_test.go @@ -29,13 +29,13 @@ func TestModifyPerformanceProfile(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -74,13 +74,13 @@ func TestAddStandByMDM(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -126,13 +126,13 @@ func TestRemoveStandByMDM(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -174,13 +174,13 @@ func TestChangeMDMOwnership(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -227,13 +227,13 @@ func TestSwitchClusterMode(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -264,7 +264,7 @@ func TestSwitchClusterMode(t *testing.T) { } func TestGetMDMClusterDetails(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -304,14 +304,14 @@ func TestRenameMdm(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) client.configConnect.Version = "3.6" if err != nil { From f60d2bda240dbb790fc36cdf8e85f6cdccedb101 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:36:04 -0400 Subject: [PATCH 17/24] Fix golangci-lint warnings in template --- template.go | 47 +++++++++++++++++++---------------------------- template_test.go | 14 +++++++------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/template.go b/template.go index df9d4cb..92b6534 100644 --- a/template.go +++ b/template.go @@ -42,7 +42,6 @@ func (gc *GatewayClient) GetTemplateByID(id string) (*types.TemplateDetails, err if err != nil { return nil, fmt.Errorf("Error While Handling Cookie: %s", err) } - } else { req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) } @@ -55,26 +54,23 @@ func (gc *GatewayClient) GetTemplateByID(id string) (*types.TemplateDetails, err return nil, httpRespError } - responseString, _ := extractString(httpResp) - - if httpResp.StatusCode == 200 { - parseError := json.Unmarshal([]byte(responseString), &template) - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Template: %s", parseError) - } - - return &template, nil - } else { + if httpResp.StatusCode != http.StatusOK { return nil, fmt.Errorf("Template not found") } + + responseString, _ := extractString(httpResp) + err := json.Unmarshal([]byte(responseString), &template) + if err != nil { + return nil, fmt.Errorf("Error parsing response data for template: %s", err) + } + return &template, nil } // GetAllTemplates gets all the Template details func (gc *GatewayClient) GetAllTemplates() ([]types.TemplateDetails, error) { defer TimeSpent("GetAllTemplates", time.Now()) - path := fmt.Sprintf("/Api/V1/template") + path := "/Api/V1/template" var templates types.TemplateDetailsFilter req, httpError := http.NewRequest("GET", gc.host+path, nil) @@ -89,7 +85,6 @@ func (gc *GatewayClient) GetAllTemplates() ([]types.TemplateDetails, error) { if err != nil { return nil, fmt.Errorf("Error While Handling Cookie: %s", err) } - } else { req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(gc.username+":"+gc.password))) } @@ -102,9 +97,8 @@ func (gc *GatewayClient) GetAllTemplates() ([]types.TemplateDetails, error) { return nil, httpRespError } - responseString, _ := extractString(httpResp) - if httpResp.StatusCode == 200 { + responseString, _ := extractString(httpResp) parseError := json.Unmarshal([]byte(responseString), &templates) if parseError != nil { @@ -149,20 +143,17 @@ func (gc *GatewayClient) GetTemplateByFilters(key string, value string) ([]types return nil, httpRespError } - responseString, _ := extractString(httpResp) - - if httpResp.StatusCode == 200 { - parseError := json.Unmarshal([]byte(responseString), &templates) - - if parseError != nil { - return nil, fmt.Errorf("Error While Parsing Response Data For Template: %s", parseError) - } + if httpResp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("Template not found") + } - if len(templates.TemplateDetails) == 0 { - return nil, fmt.Errorf("Template not found") - } + responseString, _ := extractString(httpResp) + parseError := json.Unmarshal([]byte(responseString), &templates) + if parseError != nil { + return nil, fmt.Errorf("Error While Parsing Response Data For Template: %s", parseError) + } - } else { + if len(templates.TemplateDetails) == 0 { return nil, fmt.Errorf("Template not found") } diff --git a/template_test.go b/template_test.go index 0578605..353459a 100644 --- a/template_test.go +++ b/template_test.go @@ -23,7 +23,7 @@ import ( ) func TestGetTemplates(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -56,13 +56,13 @@ func TestGetTemplateByID(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewGateway(svr.URL, "", "", true, false) client.version = "4.5" if err != nil { @@ -84,7 +84,7 @@ func TestGetTemplateByID(t *testing.T) { } func TestGetTemplateByFilters(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -101,7 +101,7 @@ func TestGetTemplateByFilters(t *testing.T) { } func TestGetTemplateByIDNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) @@ -119,7 +119,7 @@ func TestGetTemplateByIDNegative(t *testing.T) { } func TestGetTemplateByFiltersNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) @@ -137,7 +137,7 @@ func TestGetTemplateByFiltersNegative(t *testing.T) { } func TestGetAllTemplatesNegative(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintln(w, `{"error":"Internal Server Error"}`) })) From e447147c9872e5803bd0712ef244a94e116401b4 Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:38:57 -0400 Subject: [PATCH 18/24] Fix golangci-lint warnings in tree_quota_test --- tree_quota_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tree_quota_test.go b/tree_quota_test.go index dffe602..7d14f6a 100644 --- a/tree_quota_test.go +++ b/tree_quota_test.go @@ -35,20 +35,20 @@ func TestTreeQuotaByID(t *testing.T) { type checkFn func(*testing.T, *types.TreeQuota, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.TreeQuota, err error) { + hasNoError := func(t *testing.T, _ *types.TreeQuota, _ error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.TreeQuota, err error) { + hasError := func(t *testing.T, _ *types.TreeQuota, _ error) { if err == nil { t.Fatalf("expected error") } } checkRespID := func(quotaID string) func(t *testing.T, resp *types.TreeQuota, err error) { - return func(t *testing.T, resp *types.TreeQuota, err error) { + return func(t *testing.T, resp *types.TreeQuota, _ error) { assert.Equal(t, quotaID, resp.ID) } } @@ -98,7 +98,7 @@ func TestTreeQuotaByID(t *testing.T) { }, } - testCaseIds := map[string]string{ + testCaseIDs := map[string]string{ "success": "00000003-006a-0000-0600-000000000000", "not found": "00000003-006a-0000-0700-000000000000", } @@ -118,7 +118,7 @@ func TestTreeQuotaByID(t *testing.T) { client: client, } - resp, err := s.GetTreeQuotaByID(testCaseIds[id]) + resp, err := s.GetTreeQuotaByID(testCaseIDs[id]) for _, checkFn := range checkFns { checkFn(t, resp, err) } @@ -130,20 +130,20 @@ func TestCreateTreeQuota(t *testing.T) { type checkFn func(*testing.T, *types.TreeQuotaCreateResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, resp *types.TreeQuotaCreateResponse, err error) { + hasNoError := func(t *testing.T, _ *types.TreeQuotaCreateResponse, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, resp *types.TreeQuotaCreateResponse, err error) { + hasError := func(t *testing.T, _ *types.TreeQuotaCreateResponse, err error) { if err == nil { t.Fatalf("expected error") } } checkResp := func(quotaId string) func(t *testing.T, resp *types.TreeQuotaCreateResponse, err error) { - return func(t *testing.T, resp *types.TreeQuotaCreateResponse, err error) { + return func(t *testing.T, resp *types.TreeQuotaCreateResponse, _ error) { assert.Equal(t, quotaId, resp.ID) } } @@ -221,7 +221,7 @@ func TestDeleteTreeQuota(t *testing.T) { id := "00000003-006a-0000-0600-000000000000" // mock a powerflex endpoint - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -262,13 +262,13 @@ func TestModifyTreeQuota(t *testing.T) { }, } // mock a powerflex endpoint - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) From e02b53ebf1c7ad20bf12997663ed69a6ca9642ba Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:40:42 -0400 Subject: [PATCH 19/24] Fix golangci-lint warnings in tree_quota_test --- tree_quota_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tree_quota_test.go b/tree_quota_test.go index 7d14f6a..1f85880 100644 --- a/tree_quota_test.go +++ b/tree_quota_test.go @@ -35,13 +35,13 @@ func TestTreeQuotaByID(t *testing.T) { type checkFn func(*testing.T, *types.TreeQuota, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, _ *types.TreeQuota, _ error) { + hasNoError := func(t *testing.T, _ *types.TreeQuota, err error) { if err != nil { t.Fatalf("expected no error") } } - hasError := func(t *testing.T, _ *types.TreeQuota, _ error) { + hasError := func(t *testing.T, _ *types.TreeQuota, err error) { if err == nil { t.Fatalf("expected error") } From 7f06a0e21cba17ef48811b6deddfcc7204434a9b Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:45:20 -0400 Subject: [PATCH 20/24] Fix golangci-lint warnings in user --- user.go | 32 ++++++++++++++++---------------- user_test.go | 16 ++++++++-------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/user.go b/user.go index 25fbbf8..4406895 100644 --- a/user.go +++ b/user.go @@ -42,32 +42,32 @@ func (s *System) GetUser() ([]types.User, error) { func (s *System) GetUserByIDName(userID string, username string) (*types.User, error) { if userID == "" && username == "" { return nil, errors.New("user name or ID is mandatory, please enter a valid value") - } else if userID != "" { - path := fmt.Sprintf("/api/instances/User::%v", - userID) + } + // Get user by userID + if userID != "" { + path := fmt.Sprintf("/api/instances/User::%v", userID) user := &types.User{} - err := s.client.getJSONWithRetry( - http.MethodGet, path, nil, &user) + err := s.client.getJSONWithRetry(http.MethodGet, path, nil, &user) if err != nil { return nil, err } return user, nil - } else { - allUsers, err := s.GetUser() - if err != nil { - return nil, err - } + } + // Get user by username + allUsers, err := s.GetUser() + if err != nil { + return nil, err + } - for _, user := range allUsers { - if user.Name == username { - return &user, nil - } + for _, user := range allUsers { + if user.Name == username { + return &user, nil } - - return nil, errors.New("couldn't find user by name") } + + return nil, errors.New("couldn't find user by name") } // CreateUser creates a new user with some role. diff --git a/user_test.go b/user_test.go index 2554ef9..0a5d800 100644 --- a/user_test.go +++ b/user_test.go @@ -33,13 +33,13 @@ func TestCreateUser(t *testing.T) { expected: errors.New("userRole should get on Monitor, Configure, Administrator, Security, FrontendConfig, BackendConfig, but its value is Role"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -80,13 +80,13 @@ func TestGetUserByIDName(t *testing.T) { expected: errors.New("user name or ID is mandatory, please enter a valid value"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -124,13 +124,13 @@ func TestRemoveUser(t *testing.T) { expected: errors.New("User not found. Please check that you have the correct user name"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -175,13 +175,13 @@ func TestSetRole(t *testing.T) { expected: errors.New("userRole should get one of the following values: Monitor, Configure, Administrator, Security, FrontendConfig, BackendConfig, but its value is any"), }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) From 52a8d64d354aac8df9524ddbd7bdab0382d7d95c Mon Sep 17 00:00:00 2001 From: AkshaySainiDell Date: Wed, 13 Mar 2024 06:48:21 -0400 Subject: [PATCH 21/24] Fix golangci-lint warnings in volume and vtree --- volume_test.go | 2 +- vtree_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/volume_test.go b/volume_test.go index 49581fd..1212188 100644 --- a/volume_test.go +++ b/volume_test.go @@ -102,7 +102,7 @@ func Test_GetVolumeStatistics(t *testing.T) { }, }, } - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { volumeStats := types.VolumeStatistics{} respData, err := json.Marshal(volumeStats) if err != nil { diff --git a/vtree_test.go b/vtree_test.go index 13ab22f..b626fc5 100644 --- a/vtree_test.go +++ b/vtree_test.go @@ -11,7 +11,7 @@ import ( ) func TestGetVTrees(t *testing.T) { - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) })) defer svr.Close() @@ -44,13 +44,13 @@ func TestGetVTreeByID(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -87,13 +87,13 @@ func TestGetVTreeInstances(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) @@ -130,13 +130,13 @@ func TestGetVTreeByVolumeID(t *testing.T) { }, } - svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { })) defer svr.Close() for _, tc := range cases { tc := tc - t.Run("", func(ts *testing.T) { + t.Run("", func(_ *testing.T) { client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) if err != nil { t.Fatal(err) From b2216d5015609dc2b7a787303612f59acc9a2b06 Mon Sep 17 00:00:00 2001 From: Akshay Saini <109056238+AkshaySainiDell@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:15:44 +0530 Subject: [PATCH 22/24] Update service.go --- service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service.go b/service.go index 9f8d4e6..a575685 100644 --- a/service.go +++ b/service.go @@ -618,7 +618,7 @@ func (gc *GatewayClient) DeleteService(serviceID, serversInInventory, serversMan defer TimeSpent("DeleteService", time.Now()) - req, httpError := http.NewRequest("DELETE", gc.host+"/Api/V1/Deployment/"+serviceId+"?serversInInventory="+serversInInventory+"&serversManagedState="+serversManagedState, nil) + req, httpError := http.NewRequest("DELETE", gc.host+"/Api/V1/Deployment/"+serviceID+"?serversInInventory="+serversInInventory+"&serversManagedState="+serversManagedState, nil) if httpError != nil { return nil, httpError } From 4029c29aa038b8c46897586ae56d6b8015f51071 Mon Sep 17 00:00:00 2001 From: Akshay Saini Date: Thu, 25 Apr 2024 09:22:43 +0000 Subject: [PATCH 23/24] Fix remaining linting issues --- service.go | 5 ++ types/v1/serviceTypes.go | 3 ++ types/v1/templateTypes.go | 99 +++++++++++++++++++++++++++++++++++++++ types/v1/types.go | 5 +- types/v1/vTreeTypes.go | 2 +- 5 files changed, 111 insertions(+), 3 deletions(-) diff --git a/service.go b/service.go index a575685..6ed55cd 100644 --- a/service.go +++ b/service.go @@ -173,6 +173,7 @@ func (gc *GatewayClient) DeployService(deploymentName, deploymentDesc, serviceTe return &deploymentResponse, nil } +// UpdateService updates an existing service in the ScaleIO Gateway. func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentDesc, nodes, nodename string) (*types.ServiceResponse, error) { defer TimeSpent("UpdateService", time.Now()) @@ -433,6 +434,7 @@ func contains(list []string, str string) bool { return false } +// GetServiceDetailsByID retrieves service details by deployment ID. func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken bool) (*types.ServiceResponse, error) { defer TimeSpent("GetServiceDetailsByID", time.Now()) @@ -525,6 +527,7 @@ func (gc *GatewayClient) GetServiceDetailsByID(deploymentID string, newToken boo return &deploymentResponse, nil } +// GetServiceDetailsByFilter retrieves service details based on a filter and value. func (gc *GatewayClient) GetServiceDetailsByFilter(filter, value string) ([]types.ServiceResponse, error) { defer TimeSpent("GetServiceDetailsByFilter", time.Now()) @@ -572,6 +575,7 @@ func (gc *GatewayClient) GetServiceDetailsByFilter(filter, value string) ([]type return deploymentResponse, nil } +// GetAllServiceDetails retrieves all service details from the GatewayClient. func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) { defer TimeSpent("DeploGetServiceDetailsByIDyService", time.Now()) @@ -611,6 +615,7 @@ func (gc *GatewayClient) GetAllServiceDetails() ([]types.ServiceResponse, error) return deploymentResponse, nil } +// DeleteService deletes a service by its ID, along with servers in inventory and managed state. func (gc *GatewayClient) DeleteService(serviceID, serversInInventory, serversManagedState string) (*types.ServiceResponse, error) { var deploymentResponse types.ServiceResponse diff --git a/types/v1/serviceTypes.go b/types/v1/serviceTypes.go index 3a23b2d..ab2039f 100644 --- a/types/v1/serviceTypes.go +++ b/types/v1/serviceTypes.go @@ -1,5 +1,6 @@ package goscaleio +// ServiceFailedResponse represents the response when a service fails. type ServiceFailedResponse struct { DetailMessage string `json:"detailMessage,omitempty"` Status int `json:"status,omitempty"` @@ -10,6 +11,7 @@ type ServiceFailedResponse struct { Messages []Messages `json:"messages,omitempty"` } +// DeploymentPayload represents the payload for deploying a service. type DeploymentPayload struct { DeploymentName string `json:"deploymentName,omitempty"` DeploymentDescription string `json:"deploymentDescription,omitempty"` @@ -19,6 +21,7 @@ type DeploymentPayload struct { Status string `json:"status,omitempty"` } +// ServiceResponse represents the response from a service operation. type ServiceResponse struct { ID string `json:"id,omitempty"` DeploymentName string `json:"deploymentName,omitempty"` diff --git a/types/v1/templateTypes.go b/types/v1/templateTypes.go index 42edeb9..a3f9090 100644 --- a/types/v1/templateTypes.go +++ b/types/v1/templateTypes.go @@ -12,6 +12,7 @@ package goscaleio +// TemplateDetails defines the details of a template. type TemplateDetails struct { ID string `json:"id,omitempty"` TemplateName string `json:"templateName,omitempty"` @@ -49,6 +50,7 @@ type TemplateDetails struct { Draft bool `json:"draft,omitempty"` } +// Messages defines a struct for messages. type Messages struct { ID string `json:"id,omitempty"` MessageCode string `json:"messageCode,omitempty"` @@ -64,11 +66,13 @@ type Messages struct { SequenceNumber int `json:"sequenceNumber,omitempty"` } +// TemplateValid defines the validity of a template. type TemplateValid struct { Valid bool `json:"valid,omitempty"` Messages []Messages `json:"messages,omitempty"` } +// SoftwareComponent defines the details of a software component. type SoftwareComponents struct { ID string `json:"id,omitempty"` PackageID string `json:"packageId,omitempty"` @@ -98,6 +102,7 @@ type SoftwareComponents struct { FirmwareRepoName string `json:"firmwareRepoName,omitempty"` } +// SoftwareBundles defines a struct for software bundles. type SoftwareBundles struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -122,11 +127,13 @@ type SoftwareBundles struct { SoftwareComponents []SoftwareComponents `json:"softwareComponents,omitempty"` } +// DeploymentValid defines the validity of a deployment. type DeploymentValid struct { Valid bool `json:"valid,omitempty"` Messages []Messages `json:"messages,omitempty"` } +// DeploymentDevice defines the details of a device in a deployment. type DeploymentDevice struct { RefID string `json:"refId,omitempty"` RefType string `json:"refType,omitempty"` @@ -153,6 +160,7 @@ type DeploymentDevice struct { Brownfield bool `json:"brownfield,omitempty"` } +// Vms defines a struct for virtual machines. type Vms struct { CertificateName string `json:"certificateName,omitempty"` VMModel string `json:"vmModel,omitempty"` @@ -161,6 +169,7 @@ type Vms struct { VMServiceTag string `json:"vmServiceTag,omitempty"` } +// LicenseRepository defines the details of a license repository. type LicenseRepository struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -176,6 +185,7 @@ type LicenseRepository struct { LicenseData string `json:"licenseData,omitempty"` } +// AssignedUsers defines a struct for assigned users. type AssignedUsers struct { UserSeqID int `json:"userSeqId,omitempty"` UserName string `json:"userName,omitempty"` @@ -201,6 +211,7 @@ type AssignedUsers struct { Roles []string `json:"roles,omitempty"` } +// JobDetails defines the details of a job. type JobDetails struct { Level string `json:"level,omitempty"` Message string `json:"message,omitempty"` @@ -209,6 +220,7 @@ type JobDetails struct { ComponentID string `json:"componentId,omitempty"` } +// DeploymentValidationResponse defines the response of deployment validation. type DeploymentValidationResponse struct { Nodes int `json:"nodes,omitempty"` StoragePools int `json:"storagePools,omitempty"` @@ -227,6 +239,7 @@ type DeploymentValidationResponse struct { DiskTypeMismatch bool `json:"diskTypeMismatch,omitempty"` } +// Deployments defines the details of a deployment. type Deployments struct { ID string `json:"id,omitempty"` DeploymentName string `json:"deploymentName,omitempty"` @@ -289,6 +302,7 @@ type Deployments struct { CanMigratevCLSVMs bool `json:"canMigratevCLSVMs,omitempty"` } +// FirmwareRepository defines the details of a firmware repository. type FirmwareRepository struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -325,22 +339,26 @@ type FirmwareRepository struct { Rcmapproved bool `json:"rcmapproved,omitempty"` } +// ComponentValid defines the validity of a component. type ComponentValid struct { Valid bool `json:"valid,omitempty"` Messages []Messages `json:"messages,omitempty"` } +// DependenciesDetails defines the details of a dependency. type DependenciesDetails struct { ID string `json:"id,omitempty"` DependencyTarget string `json:"dependencyTarget,omitempty"` DependencyValue string `json:"dependencyValue,omitempty"` } +// NetworkIPAddressList defines the details of a network IP address. type NetworkIPAddressList struct { ID string `json:"id,omitempty"` IPAddress string `json:"ipAddress,omitempty"` } +// Partitions defines the details of a partition. type Partitions struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -361,6 +379,7 @@ type Partitions struct { PartitionIndex int `json:"partition_index,omitempty"` } +// Interfaces defines an interface. type Interfaces struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -374,6 +393,7 @@ type Interfaces struct { AllNetworks []string `json:"allNetworks,omitempty"` } +// InterfacesDetails defines the details of an interface. type InterfacesDetails struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -389,12 +409,14 @@ type InterfacesDetails struct { NictypeSource string `json:"nictypeSource,omitempty"` } +// NetworkConfiguration defines the network configuration. type NetworkConfiguration struct { ID string `json:"id,omitempty"` Interfaces []InterfacesDetails `json:"interfaces,omitempty"` SoftwareOnly bool `json:"softwareOnly,omitempty"` } +// ConfigurationDetails defines the details of a configuration. type ConfigurationDetails struct { ID string `json:"id,omitempty"` Disktype string `json:"disktype,omitempty"` @@ -406,6 +428,7 @@ type ConfigurationDetails struct { Categories []Categories `json:"categories,omitempty"` } +// VirtualDisks defines the details of a virtual disk. type VirtualDisks struct { PhysicalDisks []string `json:"physicalDisks,omitempty"` VirtualDiskFqdd string `json:"virtualDiskFqdd,omitempty"` @@ -418,6 +441,7 @@ type VirtualDisks struct { EncryptionType string `json:"encryptionType,omitempty"` } +// ExternalVirtualDisks defines the details of an external virtual disk. type ExternalVirtualDisks struct { PhysicalDisks []string `json:"physicalDisks,omitempty"` VirtualDiskFqdd string `json:"virtualDiskFqdd,omitempty"` @@ -430,6 +454,7 @@ type ExternalVirtualDisks struct { EncryptionType string `json:"encryptionType,omitempty"` } +// RaidConfiguration defines the raid configuration. type RaidConfiguration struct { VirtualDisks []VirtualDisks `json:"virtualDisks,omitempty"` ExternalVirtualDisks []ExternalVirtualDisks `json:"externalVirtualDisks,omitempty"` @@ -440,6 +465,7 @@ type RaidConfiguration struct { SizeToDiskMap map[string]int `json:"sizeToDiskMap,omitempty"` } +// OptionsDetails defines the details of an option. type OptionsDetails struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -448,6 +474,7 @@ type OptionsDetails struct { Attributes map[string]string `json:"attributes,omitempty"` } +// ScaleIODiskConfiguration defines the scaleio disk configuration. type ScaleIOStoragePoolDisks struct { ProtectionDomainID string `json:"protectionDomainId,omitempty"` ProtectionDomainName string `json:"protectionDomainName,omitempty"` @@ -458,46 +485,66 @@ type ScaleIOStoragePoolDisks struct { VirtualDiskFqdds []string `json:"virtualDiskFqdds,omitempty"` SoftwareOnlyDisks []string `json:"softwareOnlyDisks,omitempty"` } + +// ScaleIODiskConfiguration defines the scaleio disk configuration. type ScaleIODiskConfiguration struct { ScaleIOStoragePoolDisks []ScaleIOStoragePoolDisks `json:"scaleIOStoragePoolDisks,omitempty"` } + +// ShortWindow defines a short window. type ShortWindow struct { Threshold int `json:"threshold,omitempty"` WindowSizeInSec int `json:"windowSizeInSec,omitempty"` } + +// MediumWindow defines a medium window. type MediumWindow struct { Threshold int `json:"threshold,omitempty"` WindowSizeInSec int `json:"windowSizeInSec,omitempty"` } + +// LongWindow defines a long window. type LongWindow struct { Threshold int `json:"threshold,omitempty"` WindowSizeInSec int `json:"windowSizeInSec,omitempty"` } + +// SdsCounterParameters defines the sds counter parameters. type SdsDecoupledCounterParameters struct { ShortWindow ShortWindow `json:"shortWindow,omitempty"` MediumWindow MediumWindow `json:"mediumWindow,omitempty"` LongWindow LongWindow `json:"longWindow,omitempty"` } + +// SdsConfigurationFailureCounterParameters defines the sds configuration failure counter parameters. type SdsConfigurationFailureCounterParameters struct { ShortWindow ShortWindow `json:"shortWindow,omitempty"` MediumWindow MediumWindow `json:"mediumWindow,omitempty"` LongWindow LongWindow `json:"longWindow,omitempty"` } + +// MdmSdsCounterParameters defines the mdm sds counter parameters. type MdmSdsCounterParameters struct { ShortWindow ShortWindow `json:"shortWindow,omitempty"` MediumWindow MediumWindow `json:"mediumWindow,omitempty"` LongWindow LongWindow `json:"longWindow,omitempty"` } + +// SdsSdsCounterParameters defines the sds sds counter parameters. type SdsSdsCounterParameters struct { ShortWindow ShortWindow `json:"shortWindow,omitempty"` MediumWindow MediumWindow `json:"mediumWindow,omitempty"` LongWindow LongWindow `json:"longWindow,omitempty"` } + +// SdsReceiveBufferAllocationFailuresCounterParameters defines the sds receive buffer allocation failures counter parameters. type SdsReceiveBufferAllocationFailuresCounterParameters struct { ShortWindow ShortWindow `json:"shortWindow,omitempty"` MediumWindow MediumWindow `json:"mediumWindow,omitempty"` LongWindow LongWindow `json:"longWindow,omitempty"` } + +// General defines the general. type General struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -520,6 +567,7 @@ type General struct { RfcacheEnabled bool `json:"rfcacheEnabled,omitempty"` } +// StatisticsDetails defines the statistics details. type StatisticsDetails struct { NumOfDevices int `json:"numOfDevices,omitempty"` UnusedCapacityInKb int `json:"unusedCapacityInKb,omitempty"` @@ -541,6 +589,8 @@ type StatisticsDetails struct { ThinCapacityInUseInKb int `json:"thinCapacityInUseInKb,omitempty"` ThickCapacityInUseInKb int `json:"thickCapacityInUseInKb,omitempty"` } + +// DiskList defines the disk list. type DiskList struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -557,6 +607,7 @@ type DiskList struct { ModelName string `json:"modelName,omitempty"` } +// MappedSdcInfoDetails defines the mapped sdc info details. type MappedSdcInfoDetails struct { SdcIP string `json:"sdcIp,omitempty"` SdcID string `json:"sdcId,omitempty"` @@ -564,6 +615,7 @@ type MappedSdcInfoDetails struct { LimitIops int `json:"limitIops,omitempty"` } +// VolumeList defines the volume list. type VolumeList struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -576,6 +628,7 @@ type VolumeList struct { VolumeClass string `json:"volumeClass,omitempty"` } +// StoragePoolList defines the storage pool list. type StoragePoolList struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -615,11 +668,13 @@ type StoragePoolList struct { FglAccpID string `json:"fglAccpId,omitempty"` } +// IPList defines the ip list. type IPList struct { IP string `json:"ip,omitempty"` Role string `json:"role,omitempty"` } +// SdsListDetails defines the sds list. type SdsListDetails struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -636,6 +691,8 @@ type SdsListDetails struct { OnVMWare bool `json:"onVmWare,omitempty"` IPList []IPList `json:"ipList,omitempty"` } + +// SdrListDetails defines the sdr list. type SdrListDetails struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -649,6 +706,8 @@ type SdrListDetails struct { PerfProfile string `json:"perfProfile,omitempty"` IPList []IPList `json:"ipList,omitempty"` } + +// AccelerationPool defines the acceleration pool. type AccelerationPool struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -656,6 +715,8 @@ type AccelerationPool struct { MediaType string `json:"mediaType,omitempty"` Rfcache bool `json:"rfcache,omitempty"` } + +// ProtectionDomainSettings defines the protection domain settings. type ProtectionDomainSettings struct { General General `json:"general,omitempty"` Statistics StatisticsDetails `json:"statistics,omitempty"` @@ -664,20 +725,28 @@ type ProtectionDomainSettings struct { SdrList []SdrListDetails `json:"sdr_list,omitempty"` AccelerationPool []AccelerationPool `json:"acceleration_pool,omitempty"` } + +// FaultSetSettings defines the fault set settings. type FaultSetSettings struct { ProtectionDomainID string `json:"protectionDomainId,omitempty"` Name string `json:"name,omitempty"` ID string `json:"id,omitempty"` } + +// Datacenter defines the datacenter. type Datacenter struct { VcenterID string `json:"vcenterId,omitempty"` DatacenterID string `json:"datacenterId,omitempty"` DatacenterName string `json:"datacenterName,omitempty"` } + +// PortGroupOptions defines the port group options. type PortGroupOptions struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` } + +// PortGroups defines the port groups. type PortGroups struct { ID string `json:"id,omitempty"` DisplayName string `json:"displayName,omitempty"` @@ -686,6 +755,8 @@ type PortGroups struct { Value string `json:"value,omitempty"` PortGroupOptions []PortGroupOptions `json:"portGroupOptions,omitempty"` } + +// VdsSettings defines the vds settings. type VdsSettings struct { ID string `json:"id,omitempty"` DisplayName string `json:"displayName,omitempty"` @@ -693,14 +764,20 @@ type VdsSettings struct { Value string `json:"value,omitempty"` PortGroups []PortGroups `json:"portGroups,omitempty"` } + +// VdsNetworkMtuSizeConfiguration defines the vds network mtu size configuration. type VdsNetworkMtuSizeConfiguration struct { ID string `json:"id,omitempty"` Value string `json:"value,omitempty"` } + +// VdsNetworkMTUSizeConfiguration defines the vds network mtu size configuration. type VdsNetworkMTUSizeConfiguration struct { ID string `json:"id,omitempty"` Value string `json:"value,omitempty"` } + +// VdsConfiguration defines the vds configuration. type VdsConfiguration struct { Datacenter Datacenter `json:"datacenter,omitempty"` PortGroupOption string `json:"portGroupOption,omitempty"` @@ -709,11 +786,15 @@ type VdsConfiguration struct { VdsNetworkMtuSizeConfiguration []VdsNetworkMtuSizeConfiguration `json:"vdsNetworkMtuSizeConfiguration,omitempty"` VdsNetworkMTUSizeConfiguration []VdsNetworkMTUSizeConfiguration `json:"vdsNetworkMTUSizeConfiguration,omitempty"` } + +// NodeSelection defines the node selection. type NodeSelection struct { ID string `json:"id,omitempty"` ServiceTag string `json:"serviceTag,omitempty"` MgmtIPAddress string `json:"mgmtIpAddress,omitempty"` } + +// ParametersDetails defines the parameters details. type ParametersDetails struct { GUID string `json:"guid,omitempty"` ID string `json:"id,omitempty"` @@ -746,6 +827,8 @@ type ParametersDetails struct { VdsConfiguration VdsConfiguration `json:"vdsConfiguration,omitempty"` NodeSelection NodeSelection `json:"nodeSelection,omitempty"` } + +// AdditionalPropDetails defines the additional prop details. type AdditionalPropDetails struct { GUID string `json:"guid,omitempty"` ID string `json:"id,omitempty"` @@ -779,6 +862,7 @@ type AdditionalPropDetails struct { NodeSelection NodeSelection `json:"nodeSelection,omitempty"` } +// Resources defines the resources. type Resources struct { GUID string `json:"guid,omitempty"` ID string `json:"id,omitempty"` @@ -786,6 +870,8 @@ type Resources struct { Parameters []ParametersDetails `json:"parameters,omitempty"` ParametersMap map[string]string `json:"parametersMap,omitempty"` } + +// Components defines the components. type Components struct { ID string `json:"id,omitempty"` ComponentID string `json:"componentID,omitempty"` @@ -814,12 +900,16 @@ type Components struct { Changed bool `json:"changed,omitempty"` IP string `json:"ip,omitempty"` } + +// IPRange defines the ip range. type IPRange struct { ID string `json:"id,omitempty"` StartingIP string `json:"startingIp,omitempty"` EndingIP string `json:"endingIp,omitempty"` Role string `json:"role,omitempty"` } + +// StaticRoute defines the static route. type StaticRoute struct { StaticRouteSourceNetworkID string `json:"staticRouteSourceNetworkId,omitempty"` StaticRouteDestinationNetworkID string `json:"staticRouteDestinationNetworkId,omitempty"` @@ -827,6 +917,8 @@ type StaticRoute struct { SubnetMask string `json:"subnetMask,omitempty"` DestinationIPAddress string `json:"destinationIpAddress,omitempty"` } + +// StaticNetworkConfiguration defines the static network configuration. type StaticNetworkConfiguration struct { Gateway string `json:"gateway,omitempty"` Subnet string `json:"subnet,omitempty"` @@ -837,6 +929,8 @@ type StaticNetworkConfiguration struct { IPAddress string `json:"ipAddress,omitempty"` StaticRoute []StaticRoute `json:"staticRoute,omitempty"` } + +// Network defines the details of a network. type Networks struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` @@ -847,12 +941,16 @@ type Networks struct { Static bool `json:"static,omitempty"` Type string `json:"type,omitempty"` } + +// Options defines the options. type Options struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Dependencies []DependenciesDetails `json:"dependencies,omitempty"` Attributes map[string]string `json:"attributes,omitempty"` } + +// Parameters defines the parameters details. type Parameters struct { ID string `json:"id,omitempty"` Value string `json:"value,omitempty"` @@ -876,6 +974,7 @@ type Parameters struct { OptionsSortable bool `json:"optionsSortable,omitempty"` } +// Categories defines the details of a category. type Categories struct { ID string `json:"id,omitempty"` DisplayName string `json:"displayName,omitempty"` diff --git a/types/v1/types.go b/types/v1/types.go index e004dad..c35b577 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -985,7 +985,7 @@ type VolumeQeryIDByKeyParam struct { Name string `json:"name"` } -// VolumeQeryBySelectedIdsParam defines struct for VolumeQeryBySelectedIdsParam +// VolumeQeryBySelectedIDsParam defines struct for VolumeQeryBySelectedIDsParam type VolumeQeryBySelectedIDsParam struct { IDs []string `json:"ids"` } @@ -1778,11 +1778,12 @@ type SystemLimits struct { MaxVal string `json:"maxVal,omitempty"` } -// SystemLimitEntryList defines struct for system limit entryList +// QuerySystemLimitsResponse defines struct for system limit response type QuerySystemLimitsResponse struct { SystemLimitEntryList []SystemLimits `json:"systemLimitEntryList"` } +// QuerySystemLimitsParam is the parameters required to query system limits type QuerySystemLimitsParam struct{} // FaultSetParam is the parameters required to create a fault set diff --git a/types/v1/vTreeTypes.go b/types/v1/vTreeTypes.go index bc78f06..4d85725 100644 --- a/types/v1/vTreeTypes.go +++ b/types/v1/vTreeTypes.go @@ -23,7 +23,7 @@ type VTreeMigrationInfo struct { ThicknessConversionType string `json:"thicknessConversionType"` } -// VTreeQueryBySelectedIdsParam defines struct for specifying Vtree IDs +// VTreeQueryBySelectedIDsParam defines struct for specifying Vtree IDs type VTreeQueryBySelectedIDsParam struct { IDs []string `json:"ids"` } From cdd1e75ccdb6924d066df7b83b114069cd000866 Mon Sep 17 00:00:00 2001 From: Akshay Saini Date: Thu, 25 Apr 2024 09:26:40 +0000 Subject: [PATCH 24/24] Fix remaining linting issues --- types/v1/templateTypes.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/v1/templateTypes.go b/types/v1/templateTypes.go index a3f9090..9ddff98 100644 --- a/types/v1/templateTypes.go +++ b/types/v1/templateTypes.go @@ -72,7 +72,7 @@ type TemplateValid struct { Messages []Messages `json:"messages,omitempty"` } -// SoftwareComponent defines the details of a software component. +// SoftwareComponents defines the details of a software component. type SoftwareComponents struct { ID string `json:"id,omitempty"` PackageID string `json:"packageId,omitempty"` @@ -474,7 +474,7 @@ type OptionsDetails struct { Attributes map[string]string `json:"attributes,omitempty"` } -// ScaleIODiskConfiguration defines the scaleio disk configuration. +// ScaleIOStoragePoolDisks defines the scaleio storage pool disks. type ScaleIOStoragePoolDisks struct { ProtectionDomainID string `json:"protectionDomainId,omitempty"` ProtectionDomainName string `json:"protectionDomainName,omitempty"` @@ -509,7 +509,7 @@ type LongWindow struct { WindowSizeInSec int `json:"windowSizeInSec,omitempty"` } -// SdsCounterParameters defines the sds counter parameters. +// SdsDecoupledCounterParameters defines the decoupled parameters for sds counter. type SdsDecoupledCounterParameters struct { ShortWindow ShortWindow `json:"shortWindow,omitempty"` MediumWindow MediumWindow `json:"mediumWindow,omitempty"` @@ -930,7 +930,7 @@ type StaticNetworkConfiguration struct { StaticRoute []StaticRoute `json:"staticRoute,omitempty"` } -// Network defines the details of a network. +// Networks defines the details of a network. type Networks struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"`