cleanup: resolves gofumpt issues of internal codes

This PR runs gofumpt for internal folder.

Updates: #1586

Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
Yati Padia
2021-07-13 17:51:05 +05:30
committed by mergify[bot]
parent 696ee496fc
commit f36d611ef9
25 changed files with 115 additions and 124 deletions

View File

@ -44,7 +44,7 @@ const (
)
func createCephConfigRoot() error {
return os.MkdirAll(cephConfigRoot, 0755) // #nosec
return os.MkdirAll(cephConfigRoot, 0o755) // #nosec
}
// WriteCephConfig writes out a basic ceph.conf file, making it easy to use
@ -54,7 +54,7 @@ func WriteCephConfig() error {
return err
}
err := ioutil.WriteFile(CephConfigPath, cephConfig, 0600)
err := ioutil.WriteFile(CephConfigPath, cephConfig, 0o600)
if err != nil {
return err
}

View File

@ -80,7 +80,7 @@ func TestConnPool(t *testing.T) {
// create a keyfile with some contents
keyfile := "/tmp/conn_utils.keyfile"
err := ioutil.WriteFile(keyfile, []byte("the-key"), 0600)
err := ioutil.WriteFile(keyfile, []byte("the-key"), 0o600)
if err != nil {
t.Errorf("failed to create keyfile: %v", err)
return

View File

@ -18,13 +18,12 @@ package util
import (
"context"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"path"
"strings"
"crypto/rand"
)
const (

View File

@ -22,11 +22,13 @@ import (
"testing"
)
var basePath = "./test_artifacts"
var csiClusters = "csi-clusters.json"
var pathToConfig = basePath + "/" + csiClusters
var clusterID1 = "test1"
var clusterID2 = "test2"
var (
basePath = "./test_artifacts"
csiClusters = "csi-clusters.json"
pathToConfig = basePath + "/" + csiClusters
clusterID1 = "test1"
clusterID2 = "test2"
)
func cleanupTestData() {
os.RemoveAll(basePath)
@ -41,7 +43,7 @@ func TestCSIConfig(t *testing.T) {
defer cleanupTestData()
err = os.MkdirAll(basePath, 0700)
err = os.MkdirAll(basePath, 0o700)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -53,7 +55,7 @@ func TestCSIConfig(t *testing.T) {
}
data = ""
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0600)
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -65,7 +67,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterIDBad\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0600)
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -77,7 +79,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitorsBad\":[\"mon1\",\"mon2\",\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0600)
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -89,7 +91,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",2,\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0600)
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -101,7 +103,7 @@ func TestCSIConfig(t *testing.T) {
}
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0600)
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}
@ -120,7 +122,7 @@ func TestCSIConfig(t *testing.T) {
data = "[{\"clusterID\":\"" + clusterID2 + "\",\"monitors\":[\"mon1\",\"mon2\",\"mon3\"]}," +
"{\"clusterID\":\"" + clusterID1 + "\",\"monitors\":[\"mon4\",\"mon5\",\"mon6\"]}]"
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0600)
err = ioutil.WriteFile(basePath+"/"+csiClusters, []byte(data), 0o600)
if err != nil {
t.Errorf("Test setup error %s", err)
}

View File

@ -26,6 +26,7 @@ func StartMetricsServer(c *Config) {
FatalLogMsg("failed to listen on address %v: %s", addr, err)
}
}
func addPath(name string, handler http.Handler) {
http.Handle(name, handler)
DebugLogMsg("DEBUG: registered profiling handler on /debug/pprof/%s\n", name)

View File

@ -57,7 +57,6 @@ func TestOperationLocks(t *testing.T) {
volumeID := "test-vol"
lock := NewOperationLock()
err := lock.GetCloneLock(volumeID)
if err != nil {
t.Errorf("failed to acquire clone lock for %s %s", volumeID, err)
}

View File

@ -31,7 +31,6 @@ func TestGetPIDLimit(t *testing.T) {
}
limit, err := GetPIDLimit()
if err != nil {
t.Errorf("no error should be returned, got: %v", err)
}

View File

@ -133,9 +133,7 @@ type TopologyConstrainedPool struct {
// from a CSI CreateVolume request.
func GetTopologyFromRequest(
req *csi.CreateVolumeRequest) (*[]TopologyConstrainedPool, *csi.TopologyRequirement, error) {
var (
topologyPools []TopologyConstrainedPool
)
var topologyPools []TopologyConstrainedPool
// check if parameters have pool configuration pertaining to topology
topologyPoolsStr := req.GetParameters()["topologyConstrainedPools"]

View File

@ -41,17 +41,17 @@ func checkAndReportError(t *testing.T, msg string, err error) {
func TestFindPoolAndTopology(t *testing.T) {
t.Parallel()
var err error
var label1 = "region"
var label2 = "zone"
var l1Value1 = "R1"
var l1Value2 = "R2"
var l2Value1 = "Z1"
var l2Value2 = "Z2"
var pool1 = "PoolA"
var pool2 = "PoolB"
var topologyPrefix = "prefix"
var emptyTopoPools = []TopologyConstrainedPool{}
var emptyPoolNameTopoPools = []TopologyConstrainedPool{
label1 := "region"
label2 := "zone"
l1Value1 := "R1"
l1Value2 := "R2"
l2Value1 := "Z1"
l2Value2 := "Z2"
pool1 := "PoolA"
pool2 := "PoolB"
topologyPrefix := "prefix"
emptyTopoPools := []TopologyConstrainedPool{}
emptyPoolNameTopoPools := []TopologyConstrainedPool{
{
DomainSegments: []topologySegment{
{
@ -65,12 +65,12 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var emptyDomainsInTopoPools = []TopologyConstrainedPool{
emptyDomainsInTopoPools := []TopologyConstrainedPool{
{
PoolName: pool1,
},
}
var partialDomainsInTopoPools = []TopologyConstrainedPool{
partialDomainsInTopoPools := []TopologyConstrainedPool{
{
PoolName: pool1,
DomainSegments: []topologySegment{
@ -81,7 +81,7 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var differentDomainsInTopoPools = []TopologyConstrainedPool{
differentDomainsInTopoPools := []TopologyConstrainedPool{
{
PoolName: pool1,
DomainSegments: []topologySegment{
@ -109,7 +109,7 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var validSingletonTopoPools = []TopologyConstrainedPool{
validSingletonTopoPools := []TopologyConstrainedPool{
{
PoolName: pool1,
DomainSegments: []topologySegment{
@ -124,7 +124,7 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var validMultipleTopoPools = []TopologyConstrainedPool{
validMultipleTopoPools := []TopologyConstrainedPool{
{
PoolName: pool1,
DomainSegments: []topologySegment{
@ -152,14 +152,14 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var emptyAccReq = csi.TopologyRequirement{}
var emptySegmentAccReq = csi.TopologyRequirement{
emptyAccReq := csi.TopologyRequirement{}
emptySegmentAccReq := csi.TopologyRequirement{
Requisite: []*csi.Topology{
{},
{},
},
}
var partialHigherSegmentAccReq = csi.TopologyRequirement{
partialHigherSegmentAccReq := csi.TopologyRequirement{
Preferred: []*csi.Topology{
{
Segments: map[string]string{
@ -168,7 +168,7 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var partialLowerSegmentAccReq = csi.TopologyRequirement{
partialLowerSegmentAccReq := csi.TopologyRequirement{
Preferred: []*csi.Topology{
{
Segments: map[string]string{
@ -177,7 +177,7 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var differentSegmentAccReq = csi.TopologyRequirement{
differentSegmentAccReq := csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{
@ -193,7 +193,7 @@ func TestFindPoolAndTopology(t *testing.T) {
},
},
}
var validAccReq = csi.TopologyRequirement{
validAccReq := csi.TopologyRequirement{
Requisite: []*csi.Topology{
{
Segments: map[string]string{

View File

@ -273,7 +273,7 @@ func GenerateVolID(
// CreateMountPoint creates the directory with given path.
func CreateMountPoint(mountPath string) error {
return os.MkdirAll(mountPath, 0750)
return os.MkdirAll(mountPath, 0o750)
}
// checkDirExists checks directory exists or not.

View File

@ -256,10 +256,21 @@ func TestParseKernelRelease(t *testing.T) {
}
}
goodReleases := []string{"5.12", "5.12xlinux", "5.1-2-yam", "3.1-5-x", "5.12.14", "5.12.14xlinux",
"5.12.14-xlinux", "5.12.14-99-x", "3.3x-3"}
goodVersions := [][]int{{5, 12, 0, 0}, {5, 12, 0, 0}, {5, 1, 0, 2}, {3, 1, 0, 5},
{5, 12, 14, 0}, {5, 12, 14, 0}, {5, 12, 14, 0}, {5, 12, 14, 99}, {3, 3, 0, 0}}
goodReleases := []string{
"5.12", "5.12xlinux", "5.1-2-yam", "3.1-5-x", "5.12.14", "5.12.14xlinux",
"5.12.14-xlinux", "5.12.14-99-x", "3.3x-3",
}
goodVersions := [][]int{
{5, 12, 0, 0},
{5, 12, 0, 0},
{5, 1, 0, 2},
{3, 1, 0, 5},
{5, 12, 14, 0},
{5, 12, 14, 0},
{5, 12, 14, 0},
{5, 12, 14, 99},
{3, 3, 0, 0},
}
for i, release := range goodReleases {
version, patchlevel, sublevel, extraversion, err := parseKernelRelease(release)
if err != nil {

View File

@ -90,8 +90,10 @@ func (ci CSIIdentifier) ComposeCSIID() (string, error) {
binary.BigEndian.PutUint64(buf64, uint64(ci.LocationID))
poolIDEncodedHex := hex.EncodeToString(buf64)
return strings.Join([]string{versionEncodedHex, clusterIDLength, ci.ClusterID,
poolIDEncodedHex, ci.ObjectUUID}, "-"), nil
return strings.Join([]string{
versionEncodedHex, clusterIDLength, ci.ClusterID,
poolIDEncodedHex, ci.ObjectUUID,
}, "-"), nil
}
/*