Skip to content

feat(linter) : add goconst check and fix issues #2236

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

Merged
merged 1 commit into from
Nov 21, 2019
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
2 changes: 1 addition & 1 deletion hack/go-linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ header_text "Running golangci-lint"
golangci-lint run --disable-all \
--deadline 5m \
--enable=nakedret \
--enable=goconst \

##todo(camilamacedo86): The following checks requires fixes in the code
# --enable=golint
# --enable=gocyclo
# --enable=goimports
# --enable=lll
# --enable=goconst
# --enable=gosec
# --enable=maligned
# --enable=deadcode \
Expand Down
19 changes: 8 additions & 11 deletions internal/scaffold/olm-catalog/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ import (
appsv1 "k8s.io/api/apps/v1"
)

const testDataDir = "testdata"
const (
testDataDir = "testdata"
projectName = "app-operator-dir"
operatorName = "app-operator"
oldCSVVer = "0.1.0"
newCSVVer = "0.2.0"
csvVer = "0.1.0"
)

var testDeployDir = filepath.Join(testDataDir, scaffold.DeployDir)

Expand All @@ -47,9 +54,6 @@ func TestCSVNew(t *testing.T) {
return buf, nil
},
}
csvVer := "0.1.0"
projectName := "app-operator-dir"
operatorName := "app-operator"

sc := &CSV{CSVVersion: csvVer, pathPrefix: testDataDir, OperatorName: operatorName}
err := s.Execute(&input.Config{ProjectName: projectName}, sc)
Expand All @@ -71,9 +75,6 @@ func TestCSVNew(t *testing.T) {

func TestCSVFromOld(t *testing.T) {
s := &scaffold.Scaffold{Fs: afero.NewMemMapFs()}
projectName := "app-operator-dir"
operatorName := "app-operator"
oldCSVVer, newCSVVer := "0.1.0", "0.2.0"

// Write all files in testdata/deploy to fs so manifests are present when
// writing a new CSV.
Expand Down Expand Up @@ -113,10 +114,6 @@ func TestCSVFromOld(t *testing.T) {
}

func TestUpdateVersion(t *testing.T) {
projectName := "app-operator-dir"
operatorName := "app-operator"

oldCSVVer, newCSVVer := "0.1.0", "0.2.0"
sc := &CSV{
Input: input.Input{ProjectName: projectName},
CSVVersion: newCSVVer,
Expand Down
22 changes: 14 additions & 8 deletions internal/scorecard/plugins/olm_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ func (t *CRDsHaveResourcesTest) Run(ctx context.Context) *schelpers.TestResult {
}

func getUsedResources(proxyPod *v1.Pod) ([]schema.GroupVersionKind, error) {
const api = "api"
const apis = "apis"
logs, err := getProxyLogs(proxyPod)
if err != nil {
return nil, err
Expand Down Expand Up @@ -322,38 +324,42 @@ func getUsedResources(proxyPod *v1.Pod) ([]schema.GroupVersionKind, error) {
splitURI = splitURI[1:]
switch len(splitURI) {
case 3:
if splitURI[0] == "api" {
if splitURI[0] == api {
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[2]}] = true
break
} else if splitURI[0] == "apis" {
}
if splitURI[0] == apis {
// this situation happens when the client enumerates the available resources of the server
// Example: "/apis/apps/v1?timeout=32s"
break
}
log.Warnf("Invalid URI: \"%s\"", uri)
case 4:
if splitURI[0] == "api" {
if splitURI[0] == api {
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[2]}] = true
break
} else if splitURI[0] == "apis" {
}
if splitURI[0] == apis {
resources[schema.GroupVersionKind{Group: splitURI[1], Version: splitURI[2], Kind: splitURI[3]}] = true
break
}
log.Warnf("Invalid URI: \"%s\"", uri)
case 5:
if splitURI[0] == "api" {
if splitURI[0] == api {
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[4]}] = true
break
} else if splitURI[0] == "apis" {
}
if splitURI[0] == apis {
resources[schema.GroupVersionKind{Group: splitURI[1], Version: splitURI[2], Kind: splitURI[3]}] = true
break
}
log.Warnf("Invalid URI: \"%s\"", uri)
case 6, 7:
if splitURI[0] == "api" {
if splitURI[0] == api {
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[4]}] = true
break
} else if splitURI[0] == "apis" {
}
if splitURI[0] == apis {
resources[schema.GroupVersionKind{Group: splitURI[1], Version: splitURI[2], Kind: splitURI[5]}] = true
break
}
Expand Down