Skip to content

Commit 07147b7

Browse files
feat(linter) : add goconst check and fix issues (#2236)
1 parent 418b603 commit 07147b7

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

hack/go-linter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ header_text "Running golangci-lint"
99
golangci-lint run --disable-all \
1010
--deadline 5m \
1111
--enable=nakedret \
12+
--enable=goconst \
1213

1314
##todo(camilamacedo86): The following checks requires fixes in the code
1415
# --enable=golint
1516
# --enable=gocyclo
1617
# --enable=goimports
1718
# --enable=lll
18-
# --enable=goconst
1919
# --enable=gosec
2020
# --enable=maligned
2121
# --enable=deadcode \

internal/scaffold/olm-catalog/csv_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ import (
3636
appsv1 "k8s.io/api/apps/v1"
3737
)
3838

39-
const testDataDir = "testdata"
39+
const (
40+
testDataDir = "testdata"
41+
projectName = "app-operator-dir"
42+
operatorName = "app-operator"
43+
oldCSVVer = "0.1.0"
44+
newCSVVer = "0.2.0"
45+
csvVer = "0.1.0"
46+
)
4047

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

@@ -47,9 +54,6 @@ func TestCSVNew(t *testing.T) {
4754
return buf, nil
4855
},
4956
}
50-
csvVer := "0.1.0"
51-
projectName := "app-operator-dir"
52-
operatorName := "app-operator"
5357

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

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

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

115116
func TestUpdateVersion(t *testing.T) {
116-
projectName := "app-operator-dir"
117-
operatorName := "app-operator"
118-
119-
oldCSVVer, newCSVVer := "0.1.0", "0.2.0"
120117
sc := &CSV{
121118
Input: input.Input{ProjectName: projectName},
122119
CSVVersion: newCSVVer,

internal/scorecard/plugins/olm_tests.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ func (t *CRDsHaveResourcesTest) Run(ctx context.Context) *schelpers.TestResult {
274274
}
275275

276276
func getUsedResources(proxyPod *v1.Pod) ([]schema.GroupVersionKind, error) {
277+
const api = "api"
278+
const apis = "apis"
277279
logs, err := getProxyLogs(proxyPod)
278280
if err != nil {
279281
return nil, err
@@ -322,38 +324,42 @@ func getUsedResources(proxyPod *v1.Pod) ([]schema.GroupVersionKind, error) {
322324
splitURI = splitURI[1:]
323325
switch len(splitURI) {
324326
case 3:
325-
if splitURI[0] == "api" {
327+
if splitURI[0] == api {
326328
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[2]}] = true
327329
break
328-
} else if splitURI[0] == "apis" {
330+
}
331+
if splitURI[0] == apis {
329332
// this situation happens when the client enumerates the available resources of the server
330333
// Example: "/apis/apps/v1?timeout=32s"
331334
break
332335
}
333336
log.Warnf("Invalid URI: \"%s\"", uri)
334337
case 4:
335-
if splitURI[0] == "api" {
338+
if splitURI[0] == api {
336339
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[2]}] = true
337340
break
338-
} else if splitURI[0] == "apis" {
341+
}
342+
if splitURI[0] == apis {
339343
resources[schema.GroupVersionKind{Group: splitURI[1], Version: splitURI[2], Kind: splitURI[3]}] = true
340344
break
341345
}
342346
log.Warnf("Invalid URI: \"%s\"", uri)
343347
case 5:
344-
if splitURI[0] == "api" {
348+
if splitURI[0] == api {
345349
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[4]}] = true
346350
break
347-
} else if splitURI[0] == "apis" {
351+
}
352+
if splitURI[0] == apis {
348353
resources[schema.GroupVersionKind{Group: splitURI[1], Version: splitURI[2], Kind: splitURI[3]}] = true
349354
break
350355
}
351356
log.Warnf("Invalid URI: \"%s\"", uri)
352357
case 6, 7:
353-
if splitURI[0] == "api" {
358+
if splitURI[0] == api {
354359
resources[schema.GroupVersionKind{Version: splitURI[1], Kind: splitURI[4]}] = true
355360
break
356-
} else if splitURI[0] == "apis" {
361+
}
362+
if splitURI[0] == apis {
357363
resources[schema.GroupVersionKind{Group: splitURI[1], Version: splitURI[2], Kind: splitURI[5]}] = true
358364
break
359365
}

0 commit comments

Comments
 (0)