Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/dell/goscaleio into ci-add-…
Browse files Browse the repository at this point in the history
…golangci-lint
  • Loading branch information
VamsiSiddu-7 committed Aug 9, 2023
2 parents b09f9cf + 657fcb1 commit 20fdf04
Show file tree
Hide file tree
Showing 15 changed files with 1,216 additions and 77 deletions.
282 changes: 219 additions & 63 deletions deploy.go

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions deploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright © 2021 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goscaleio

import (
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"
)

func TestMoveToNextPhase(t *testing.T) {
type testCase struct {
expected error
}

cases := []testCase{
{
nil,
},
}

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
defer svr.Close()

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)
}

_, err = GC.MoveToNextPhase()
if err != nil {
if tc.expected == nil {
t.Errorf("Move to Next Phase did not work as expected, \n\tgot: %s \n\twant: %v", err, tc.expected)
} else {
if err.Error() != tc.expected.Error() {
t.Errorf("Move to Next Phase did not work as expected, \n\tgot: %s \n\twant: %s", err, tc.expected)
}
}
}

})
}
}

func TestUninstallCluster(t *testing.T) {
type testCase struct {
jsonInput string
username string
mdmPassword string
liaPassword string
expected error
}

cases := []testCase{
{
"",
"test",
"123",
"123",
errors.New("unexpected end of JSON input"),
},
}

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
defer svr.Close()

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)
}

_, err = GC.UninstallCluster(tc.jsonInput, tc.username, tc.mdmPassword, tc.liaPassword, true, true, false, true)
if err != nil {
if tc.expected == nil {
t.Errorf("Uninstalling Cluster did not work as expected, \n\tgot: %s \n\twant: %v", err, tc.expected)
} else {
if err.Error() != tc.expected.Error() {
t.Errorf("Uninstalling Cluster did not work as expected, \n\tgot: %s \n\twant: %s", err, tc.expected)
}
}
}

})
}
}

func TestGetClusterDetails(t *testing.T) {
type testCase struct {
mdmIP string
mdmPassword string
expected error
}

cases := []testCase{
{
"",
"",
errors.New("Error Getting Cluster Details"),
},
}

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
defer svr.Close()

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)
}

clusterData := map[string]interface{}{
"mdmUser": "admin",
"mdmPassword": tc.mdmPassword,
}
clusterData["mdmIps"] = []string{tc.mdmIP}

secureData := map[string]interface{}{
"allowNonSecureCommunicationWithMdm": true,
"allowNonSecureCommunicationWithLia": true,
"disableNonMgmtComponentsAuth": false,
}
clusterData["securityConfiguration"] = secureData

jsonres, _ := json.Marshal(clusterData)

_, err = GC.GetClusterDetails(jsonres, false)
if err != nil {
if tc.expected == nil {
t.Errorf("Uninstalling Cluster did not work as expected, \n\tgot: %s \n\twant: %v", err, tc.expected)
} else {
if err.Error() != tc.expected.Error() {
t.Errorf("Uninstalling Cluster did not work as expected, \n\tgot: %s \n\twant: %s", err, tc.expected)
}
}
}

})
}
}
16 changes: 16 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ func (s *System) RestoreFileSystemFromSnapshot(restoreSnapParam *types.RestoreFs
return nil, nil
}

// GetFsSnapshotsByVolumeID gets list of snapshots associated with a filesystem
func (s *System) GetFsSnapshotsByVolumeID(fsID string) ([]types.FileSystem, error) {
defer TimeSpent("GetFsSnapshotsByVolumeID", time.Now())
var snapshotList []types.FileSystem
fsList, err := s.GetAllFileSystems()
if err != nil {
return nil, err
}
for _, fs := range fsList {
if fs.ParentID == fsID {
snapshotList = append(snapshotList, fs)
}
}
return snapshotList, err
}

// DeleteFileSystem deletes a file system
func (s *System) DeleteFileSystem(name string) error {
defer TimeSpent("DeleteFileSystem", time.Now())
Expand Down
102 changes: 102 additions & 0 deletions fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,108 @@ func TestCreateFileSystemSnapshot(t *testing.T) {
}
}

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) {
if err != nil {
t.Fatalf("expected no error")
}
}

hasError := func(t *testing.T, resp []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) {
assert.Equal(t, snapLength, len(resp))
}
}

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

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Fatal(fmt.Errorf("wrong method. Expected %s; but got %s", http.MethodGet, r.Method))
}

if r.URL.Path != href {
t.Fatal(fmt.Errorf("wrong path. Expected %s; but got %s", href, r.URL.Path))
}

resp = []types.FileSystem{
{
ID: "64366a19-54e8-1544-f3d7-2a50fb1ccff3",
Name: "fs-test-1",
},
{
ID: "6436aa58-e6a1-a4e2-de7b-2a50fb1ccff3",
Name: "fs-test-2",
},
}

respData, err := json.Marshal(resp)
if err != nil {
t.Fatal(err)
}
fmt.Fprintln(w, string(respData))

}))
return ts, check(hasNoError, checkResp(len(resp)))
},

"operation-failed": func(t *testing.T) (*httptest.Server, []checkFn) {
href := "/rest/v1/file-systems"

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Fatal(fmt.Errorf("wrong method. Expected %s; but got %s", http.MethodGet, r.Method))
}

if r.URL.Path != href {
t.Fatal(fmt.Errorf("wrong path. Expected %s; but got %s", href, r.URL.Path))
}

http.Error(w, "operation failed", http.StatusUnprocessableEntity)
}))
return ts, check(hasError)
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
ts, checkFns := tc(t)
defer ts.Close()

client, err := NewClientWithArgs(ts.URL, "", math.MaxInt64, true, false)
client.configConnect.Version = "4.0"
if err != nil {
t.Fatal(err)
}

s := System{
client: client,
}

fsID := "64366a19-54e8-1544-f3d7-2a50fb1ccff3"

resp, err := s.GetFsSnapshotsByVolumeID(fsID)
for _, checkFn := range checkFns {
checkFn(t, resp, err)
}

})
}
}

func TestRestoreFileSystemFromSnapshot(t *testing.T) {
type checkFn func(*testing.T, *types.RestoreFsSnapResponse, error)
check := func(fns ...checkFn) []checkFn { return fns }
Expand Down
2 changes: 2 additions & 0 deletions inttests/GOSCALEIO_TEST.env_example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ GOSCALEIO_STORAGEPOOL=pool1
GOSCALEIO_SYSTEMNAME=powerflex-gateway
GOSCALEIO_INSTALLATIONID=08bhsd7f9cfy890g
GOSCALEIO_SDSID=0db2c37100002311
GOSCALEIO_MDMIP=1.2.3.4
GOSCALEIO_MDMPASSWORD=Password
USER_PASSWORD=Password

# For filesystem operations, enable these values
Expand Down
44 changes: 38 additions & 6 deletions inttests/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inttests

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -30,20 +31,20 @@ func TestDeployGetPackgeDetails(t *testing.T) {

// TestDeployValidateMDMDetails function to test Retrival of MDM Topology Function
func TestDeployValidateMDMDetails(t *testing.T) {
mapData := map[string]interface{}{
clusterData := map[string]interface{}{
"mdmUser": "admin",
"mdmPassword": "Password123",
"mdmPassword": string(os.Getenv("GOSCALEIO_MDMPASSWORD")),
}
mapData["mdmIps"] = []string{"10.247.101.68"}
clusterData["mdmIps"] = []string{string(os.Getenv("GOSCALEIO_MDMIP"))}

secureData := map[string]interface{}{
"allowNonSecureCommunicationWithMdm": true,
"allowNonSecureCommunicationWithLia": true,
"disableNonMgmtComponentsAuth": false,
}
mapData["securityConfiguration"] = secureData
clusterData["securityConfiguration"] = secureData

jsonres, _ := json.Marshal(mapData)
jsonres, _ := json.Marshal(clusterData)

res, err := GC.ValidateMDMDetails(jsonres)

Expand All @@ -54,6 +55,31 @@ func TestDeployValidateMDMDetails(t *testing.T) {
assert.Nil(t, err)
}

func TestDeployGetClusterDetails(t *testing.T) {
clusterData := map[string]interface{}{
"mdmUser": "admin",
"mdmPassword": string(os.Getenv("GOSCALEIO_MDMPASSWORD")),
}
clusterData["mdmIps"] = []string{string(os.Getenv("GOSCALEIO_MDMIP"))}

secureData := map[string]interface{}{
"allowNonSecureCommunicationWithMdm": true,
"allowNonSecureCommunicationWithLia": true,
"disableNonMgmtComponentsAuth": false,
}
clusterData["securityConfiguration"] = secureData

jsonres, _ := json.Marshal(clusterData)

res, err := GC.GetClusterDetails(jsonres, false)

assert.NotNil(t, res)

assert.EqualValues(t, res.StatusCode, 200)

assert.Nil(t, err)
}

// TestDeployDeletePackge function to test Delete Functionality
func TestDeployDeletePackge(t *testing.T) {
res, err := GC.DeletePackage("ABC")
Expand All @@ -64,7 +90,13 @@ func TestDeployDeletePackge(t *testing.T) {

// TestDeployBeginInstallation function to test Begin Installation with Parsed CSV Data
func TestDeployBeginInstallation(t *testing.T) {
_, err := GC.BeginInstallation("", "admin", "Password", "Password", true)
_, err := GC.BeginInstallation("", "admin", "Password", "Password", true, true, false, true)
assert.NotNil(t, err)
}

// TestDeployUninstallCluster function to test Begin Installation with Parsed CSV Data
func TestDeployUninstallCluster(t *testing.T) {
_, err := GC.UninstallCluster("", "admin", "Password", "Password", true, true, false, true)
assert.NotNil(t, err)
}

Expand Down
Loading

0 comments on commit 20fdf04

Please sign in to comment.