Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for several scenarios #244

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions csireverseproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"sync"
"syscall"
"time"

"revproxy/v2/pkg/common"
"revproxy/v2/pkg/config"
"revproxy/v2/pkg/k8sutils"
"revproxy/v2/pkg/standaloneproxy"
"revproxy/v2/pkg/utils"
"strings"
"sync"
"syscall"
"time"

log "github.com/sirupsen/logrus"

Expand Down
16 changes: 9 additions & 7 deletions csireverseproxy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import (
"os"
"path/filepath"
"reflect"
"sync"
"syscall"
"testing"
"time"

"revproxy/v2/pkg/common"
"revproxy/v2/pkg/config"
"revproxy/v2/pkg/k8smock"
"revproxy/v2/pkg/servermock"
"revproxy/v2/pkg/utils"
"sync"
"syscall"
"testing"
"time"

log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -157,7 +158,8 @@ func doHTTPRequest(port, path string) (string, error) {
}
creds := common.Credentials{
UserName: "test-username",
Password: "test-password"}
Password: "test-password",
}
req.Header.Set("Authorization", utils.BasicAuth(creds))

resp, err := client.Do(req)
Expand Down Expand Up @@ -206,7 +208,7 @@ func stopServers() {
}

func readYAMLConfig(filename, fileDir string) (config.ProxyConfigMap, error) {
var configmap = config.ProxyConfigMap{}
configmap := config.ProxyConfigMap{}
file := filepath.Join(fileDir, filename)
yamlFile, err := ioutil.ReadFile(file)
if err != nil {
Expand All @@ -225,7 +227,7 @@ func writeYAMLConfig(val interface{}, fileName, fileDir string) error {
return err
}
filepath := filepath.Join(fileDir, fileName)
return ioutil.WriteFile(filepath, file, 0777)
return ioutil.WriteFile(filepath, file, 0o777)
}

func createTempConfig(mode string) error {
Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package cache

import (
log "github.com/sirupsen/logrus"
"sync"
"time"

log "github.com/sirupsen/logrus"
)

// Cache is the interface for a timed key-value store
Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
package common

import (
log "github.com/sirupsen/logrus"
"net/http"
"net/http/httputil"
"net/url"
"sync"
"sync/atomic"
"time"

log "github.com/sirupsen/logrus"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/common/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package common

import (
log "github.com/sirupsen/logrus"
"net/http"
"sync/atomic"
"time"

log "github.com/sirupsen/logrus"
)

// Envoy is an interface for failover/failback enabled proxy clients
Expand Down
13 changes: 7 additions & 6 deletions csireverseproxy/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net/url"
"reflect"

"revproxy/v2/pkg/common"
"revproxy/v2/pkg/k8sutils"
"revproxy/v2/pkg/utils"
Expand Down Expand Up @@ -201,7 +202,7 @@ func (proxy *StandAloneProxyConfig) updateProxyCredentials(creds common.Credenti

// GetManagementServers - Returns the list of management servers present in StandAloneProxyConfig
func (proxy *StandAloneProxyConfig) GetManagementServers() []ManagementServer {
var mgmtServers = make([]ManagementServer, 0)
mgmtServers := make([]ManagementServer, 0)
for _, v := range proxy.managementServers {
mgmtServers = append(mgmtServers, *v)
}
Expand Down Expand Up @@ -355,15 +356,15 @@ func (proxy *StandAloneProxyConfig) UpdateManagementServers(config *StandAlonePr
// Check for deleted management servers, if any delete the map entry for it
for url, server := range proxy.managementServers {
if _, ok := config.managementServers[url]; !ok {
//the management server is not present in new config, delete its entry from active config
// the management server is not present in new config, delete its entry from active config
deletedManagementServers = append(deletedManagementServers, *server)
delete(proxy.managementServers, url)
}
}
// Check for adding/updating a new/existing management server, if any
for url, mgmntServer := range config.managementServers {
if _, ok := proxy.managementServers[url]; !ok {
//Not found, the management server is not present in active config so add its entry
// Not found, the management server is not present in active config so add its entry
updatedManagemetServers = append(updatedManagemetServers, *mgmntServer)
proxy.managementServers[url] = config.managementServers[url]
} else {
Expand Down Expand Up @@ -391,7 +392,7 @@ func (proxy *StandAloneProxyConfig) UpdateManagedArrays(config *StandAloneProxyC

// GetAuthorizedArrays - Given a credential, returns the list of authorized storage arrays
func (proxy *StandAloneProxyConfig) GetAuthorizedArrays(username, password string) []string {
var authorisedArrays = make([]string, 0)
authorisedArrays := make([]string, 0)
for _, a := range proxy.managedArrays {
isAuth, err := proxy.IsUserAuthorized(username, password, a.StorageArrayIdentifier)
if err != nil {
Expand Down Expand Up @@ -428,7 +429,7 @@ func (proxy *StandAloneProxyConfig) IsUserAuthorized(username, password, storage

// GetStorageArray - Returns a list of storage array given a storage array id
func (proxy *StandAloneProxyConfig) GetStorageArray(storageArrayID string) []StorageArray {
var storageArrays = make([]StorageArray, 0)
storageArrays := make([]StorageArray, 0)
if storageArrayID != "" {
if storageArray, ok := proxy.managedArrays[storageArrayID]; ok {
storageArrays = append(storageArrays, *storageArray)
Expand Down Expand Up @@ -621,7 +622,7 @@ func ReadConfig(configFile, configPath string) (*ProxyConfigMap, error) {
viper.SetConfigName(configFile)
viper.SetConfigType("yaml")
viper.AddConfigPath(configPath)
//viper.SetEnvPrefix("X_CSI_REVPROXY")
// viper.SetEnvPrefix("X_CSI_REVPROXY")
err := viper.ReadInConfig()
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package config
import (
"fmt"
"os"
"testing"

"revproxy/v2/pkg/common"
"revproxy/v2/pkg/k8smock"
"revproxy/v2/pkg/k8sutils"
"revproxy/v2/pkg/utils"
"testing"

log "github.com/sirupsen/logrus"
)
Expand Down
5 changes: 3 additions & 2 deletions csireverseproxy/pkg/k8smock/k8smock.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"context"
"fmt"
"os"
"strconv"
"time"

"revproxy/v2/pkg/common"
"revproxy/v2/pkg/k8sutils"
"revproxy/v2/pkg/utils"
"strconv"
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/k8smock/k8smock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package k8smock
import (
"fmt"
"os"
"revproxy/v2/pkg/utils"
"testing"

"revproxy/v2/pkg/utils"

log "github.com/sirupsen/logrus"
)

Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/k8sutils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
"fmt"
"os"
"path/filepath"
"revproxy/v2/pkg/common"
"strconv"
"time"

"revproxy/v2/pkg/common"

log "github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd"

Expand Down
1 change: 1 addition & 0 deletions csireverseproxy/pkg/servermock/servermock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package servermock

import (
"net/http"

"revproxy/v2/pkg/utils"

"github.com/gorilla/mux"
Expand Down
15 changes: 8 additions & 7 deletions csireverseproxy/pkg/standaloneproxy/standaloneproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import (
"net/http/httputil"
"net/url"
"reflect"
"revproxy/v2/pkg/common"
"revproxy/v2/pkg/config"
"revproxy/v2/pkg/utils"
"strings"
"sync"
"sync/atomic"
"time"

"revproxy/v2/pkg/common"
"revproxy/v2/pkg/config"
"revproxy/v2/pkg/utils"

log "github.com/sirupsen/logrus"

types "github.com/dell/gopowermax/v2/types/v100"
Expand Down Expand Up @@ -392,14 +393,14 @@ func (revProxy *StandAloneProxy) GetRouter() http.Handler {
router.HandleFunc(utils.Prefix+"/{version}/system/version", revProxy.ifNoSymIDInvoke(revProxy.ServeVersions))
router.HandleFunc(utils.Prefix+"/version", revProxy.ifNoSymIDInvoke(revProxy.ServeVersions))

//Snapshot
// Snapshot
router.HandleFunc(utils.Prefix+"/{version}/replication/capabilities/symmetrix", revProxy.ifNoSymIDInvoke(revProxy.ServeReplicationCapabilities))

// file
router.PathPrefix(utils.InternalPrefix + "/{version}/file/symmetrix/{symid}").HandlerFunc(revProxy.ServeReverseProxy)
router.PathPrefix(utils.Prefix + "/{version}/file/symmetrix/{symid}").HandlerFunc(revProxy.ServeReverseProxy)

//migration
// migration
router.PathPrefix(utils.Prefix + "/{version}/migration/symmetrix/{symid}").HandlerFunc(revProxy.ServeReverseProxy)

return revProxy.loggingMiddleware(router)
Expand Down Expand Up @@ -615,8 +616,8 @@ func (revProxy *StandAloneProxy) ServeReplicationCapabilities(res http.ResponseW
utils.WriteHTTPError(res, "decoding error: "+err.Error(), 400)
log.Errorf("decoding error: %s", err.Error())
}
//symCapability := symCapabilities.SymmetrixCapability
//symRepCapabilities.SymmetrixCapability = append(symRepCapabilities.SymmetrixCapability, symCapability)
// symCapability := symCapabilities.SymmetrixCapability
// symRepCapabilities.SymmetrixCapability = append(symRepCapabilities.SymmetrixCapability, symCapability)
for _, symCapability := range symCapabilities.SymmetrixCapability {
symRepCapabilities.SymmetrixCapability = append(symRepCapabilities.SymmetrixCapability, symCapability)
}
Expand Down
8 changes: 4 additions & 4 deletions csireverseproxy/pkg/utils/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package utils

import (
"fmt"
"revproxy/v2/pkg/common"
"sync"

"revproxy/v2/pkg/common"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -114,8 +115,7 @@ var lockMutex sync.Mutex

var lockRequestsQueue = make(chan LockRequest, LockRequestQueueLength)

type lockWorkers struct {
}
type lockWorkers struct{}

var lockWorker *lockWorkers

Expand All @@ -129,7 +129,7 @@ func InitializeLock() {

// LockRequestHandler - goroutine which listens for any lock/unlock requests
func LockRequestHandler() {
var fifoLocks = make(map[string]*LockProperties)
fifoLocks := make(map[string]*LockProperties)
go func() {
log.Debug("Successfully started the lock request handler")
for {
Expand Down
3 changes: 2 additions & 1 deletion csireverseproxy/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"os"
"path"
"path/filepath"
"revproxy/v2/pkg/common"
"runtime"
"strings"
"time"

"revproxy/v2/pkg/common"

log "github.com/sirupsen/logrus"
)

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ require (
github.com/dell/gocsi v1.7.0
github.com/dell/gofsutil v1.13.1
github.com/dell/goiscsi v1.8.0
github.com/dell/gopowermax/v2 v2.4.0
github.com/dell/gopowermax/v2 v2.4.1-0.20231108074435-27281047efea
github.com/fsnotify/fsnotify v1.4.9
github.com/golang/protobuf v1.5.3
github.com/kubernetes-csi/csi-lib-utils v0.7.0
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.1
github.com/vmware/govmomi v0.29.0
Expand Down Expand Up @@ -73,7 +73,7 @@ require (
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/dell/goiscsi v1.8.0 h1:kocGVOdgnufc6eGpfmwP66hyhY7OVgIafaS/+uM6ogU=
github.com/dell/goiscsi v1.8.0/go.mod h1:PTlQGJaGKYgia95mGwwHSBgvfOr3BfLIjGNh1HT6p+s=
github.com/dell/gonvme v1.5.0 h1:n73WeQSFaVOlAqjhtk5T3pbu7eZgMTLpPo8/8JymOJ8=
github.com/dell/gonvme v1.5.0/go.mod h1:7MFbd7lWSaQwR5pf9ZnVZqhkAKkveSwQEO67jDBZuX0=
github.com/dell/gopowermax/v2 v2.4.0 h1:vyf2WcdPtbvU4ITRdM+vnXvmqyITffg/qfwOUbgSviY=
github.com/dell/gopowermax/v2 v2.4.0/go.mod h1:IvFKMvXw35EiuBKig9v4eDf2tYX5up/0LqDBLzvwGZ4=
github.com/dell/gopowermax/v2 v2.4.1-0.20231108074435-27281047efea h1:2Ilxl5P2d18JTfL/T4ZOaf2NB08hDxgoOmJlpm9s+EQ=
github.com/dell/gopowermax/v2 v2.4.1-0.20231108074435-27281047efea/go.mod h1:IvFKMvXw35EiuBKig9v4eDf2tYX5up/0LqDBLzvwGZ4=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
Expand Down Expand Up @@ -413,8 +413,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -619,8 +619,8 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
Expand Down
3 changes: 2 additions & 1 deletion k8sutils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package k8sutils
import (
"context"
"fmt"
"os"

"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
)

type leaderElection interface {
Expand Down
Loading
Loading