Skip to content

Commit 2b3388c

Browse files
bendorytekton-robot
authored andcommitted
Replaced deadcode linter with unused linter.
The `deadcode` linter is deprecated and unsupported. The `unused` linter is the drop-in replacement. Note that configuration skips unused code detection in files where it is failing for unknown reasons. Also: moved several vars and related functions from multiarch_utils to examples_test. These were only used in examples_test, and while the two files are part of the same package, the `unused` linter had trouble identifying that they were in fact in use in examples_test. There are no expected functional changes in this PR.
1 parent e9dfc59 commit 2b3388c

File tree

3 files changed

+58
-60
lines changed

3 files changed

+58
-60
lines changed

.golangci.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ linters-settings:
1616
linters:
1717
disable-all: true
1818
enable:
19-
- deadcode
2019
- errcheck
2120
- gofmt
2221
- goimports
@@ -28,8 +27,8 @@ linters:
2827
- misspell
2928
- unconvert
3029
- depguard
31-
# To keep this PR small, I'm going to add one linter at a time.
32-
#- unused
30+
- unused
31+
# TODO: enable whitespace linter
3332
#- whitespace
3433
output:
3534
uniq-by-line: false
@@ -39,6 +38,13 @@ issues:
3938
linters:
4039
- errcheck
4140
- gosec
41+
- path: test/pipelinerun_test\.go
42+
linters:
43+
- unused
44+
- path: pkg/reconciler/pipelinerun/pipelinerun_test\.go
45+
# This 11,000+ line file is too big for unused code detection.
46+
linters:
47+
- unused
4248
max-issues-per-linter: 0
4349
max-same-issues: 0
4450
include:

test/examples_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
var (
3939
defaultKoDockerRepoRE = regexp.MustCompile("gcr.io/christiewilson-catfactory")
4040
v1Version = "v1"
41+
imagesMappingRE = getImagesMappingRE()
4142
)
4243

4344
// getCreatedTektonCRD parses output of an external ko invocation provided as
@@ -267,3 +268,49 @@ func testYamls(t *testing.T, baseDir string, createFunc createFunc, filter pathF
267268
t.Run(testName, exampleTest(path, waitValidateFunc, createFunc, kind))
268269
}
269270
}
271+
272+
// getImagesMappingRE generates the map ready to search and replace image names with regexp for examples files.
273+
// search is done using "image: <name>" pattern.
274+
func getImagesMappingRE() map[*regexp.Regexp][]byte {
275+
imageNamesMapping := imageNamesMapping()
276+
imageMappingRE := make(map[*regexp.Regexp][]byte, len(imageNamesMapping))
277+
278+
for existingImage, archSpecificImage := range imageNamesMapping {
279+
imageMappingRE[regexp.MustCompile("(?im)image: "+existingImage+"$")] = []byte("image: " + archSpecificImage)
280+
imageMappingRE[regexp.MustCompile("(?im)default: "+existingImage+"$")] = []byte("default: " + archSpecificImage)
281+
}
282+
283+
return imageMappingRE
284+
}
285+
286+
// imageNamesMapping provides mapping between image name in the examples yaml files and desired image name for specific arch.
287+
// by default empty map is returned.
288+
func imageNamesMapping() map[string]string {
289+
switch getTestArch() {
290+
case "s390x":
291+
return map[string]string{
292+
"registry": getTestImage(registryImage),
293+
"node": "node:alpine3.11",
294+
"gcr.io/cloud-builders/git": "alpine/git:latest",
295+
"docker:dind": "ibmcom/docker-s390x:20.10",
296+
"docker": "docker:18.06.3",
297+
"mikefarah/yq:3": "danielxlee/yq:2.4.0",
298+
"stedolan/jq": "ibmcom/jq-s390x:latest",
299+
"amd64/ubuntu": "s390x/ubuntu",
300+
"gcr.io/kaniko-project/executor:v1.3.0": getTestImage(kanikoImage),
301+
}
302+
case "ppc64le":
303+
return map[string]string{
304+
"registry": getTestImage(registryImage),
305+
"node": "node:alpine3.11",
306+
"gcr.io/cloud-builders/git": "alpine/git:latest",
307+
"docker:dind": "ibmcom/docker-ppc64le:19.03-dind",
308+
"docker": "docker:18.06.3",
309+
"mikefarah/yq:3": "danielxlee/yq:2.4.0",
310+
"stedolan/jq": "ibmcom/jq-ppc64le:latest",
311+
"gcr.io/kaniko-project/executor:v1.3.0": getTestImage(kanikoImage),
312+
}
313+
}
314+
315+
return make(map[string]string)
316+
}

test/multiarch_utils.go

+2-57
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ package test
1818

1919
import (
2020
"os"
21-
"regexp"
2221
"runtime"
2322
"testing"
2423

2524
"k8s.io/apimachinery/pkg/util/sets"
2625
)
2726

2827
var (
29-
imageNames = initImageNames()
30-
excludedTests = initExcludedTests()
31-
imagesMappingRE map[*regexp.Regexp][]byte
28+
imageNames = initImageNames()
29+
excludedTests = initExcludedTests()
3230
)
3331

3432
const (
@@ -42,10 +40,6 @@ const (
4240
dockerizeImage
4341
)
4442

45-
func init() {
46-
imagesMappingRE = getImagesMappingRE()
47-
}
48-
4943
// getTestArch returns architecture of the cluster where test suites will be executed.
5044
// default value is similar to build architecture, TEST_RUNTIME_ARCH is used when test target cluster has another architecture
5145
func getTestArch() string {
@@ -83,57 +77,8 @@ func initImageNames() map[int]string {
8377
}
8478
}
8579

86-
// getImagesMappingRE generates the map ready to search and replace image names with regexp for examples files.
87-
// search is done using "image: <name>" pattern.
88-
func getImagesMappingRE() map[*regexp.Regexp][]byte {
89-
imageNamesMapping := imageNamesMapping()
90-
imageMappingRE := make(map[*regexp.Regexp][]byte, len(imageNamesMapping))
91-
92-
for existingImage, archSpecificImage := range imageNamesMapping {
93-
imageMappingRE[regexp.MustCompile("(?im)image: "+existingImage+"$")] = []byte("image: " + archSpecificImage)
94-
imageMappingRE[regexp.MustCompile("(?im)default: "+existingImage+"$")] = []byte("default: " + archSpecificImage)
95-
}
96-
97-
return imageMappingRE
98-
}
99-
100-
// imageNamesMapping provides mapping between image name in the examples yaml files and desired image name for specific arch.
101-
// by default empty map is returned.
102-
func imageNamesMapping() map[string]string {
103-
104-
switch getTestArch() {
105-
case "s390x":
106-
return map[string]string{
107-
"registry": getTestImage(registryImage),
108-
"node": "node:alpine3.11",
109-
"gcr.io/cloud-builders/git": "alpine/git:latest",
110-
"docker:dind": "ibmcom/docker-s390x:20.10",
111-
"docker": "docker:18.06.3",
112-
"mikefarah/yq:3": "danielxlee/yq:2.4.0",
113-
"stedolan/jq": "ibmcom/jq-s390x:latest",
114-
"amd64/ubuntu": "s390x/ubuntu",
115-
"gcr.io/kaniko-project/executor:v1.3.0": getTestImage(kanikoImage),
116-
}
117-
case "ppc64le":
118-
return map[string]string{
119-
"registry": getTestImage(registryImage),
120-
"node": "node:alpine3.11",
121-
"gcr.io/cloud-builders/git": "alpine/git:latest",
122-
"docker:dind": "ibmcom/docker-ppc64le:19.03-dind",
123-
"docker": "docker:18.06.3",
124-
"mikefarah/yq:3": "danielxlee/yq:2.4.0",
125-
"stedolan/jq": "ibmcom/jq-ppc64le:latest",
126-
"gcr.io/kaniko-project/executor:v1.3.0": getTestImage(kanikoImage),
127-
}
128-
129-
}
130-
131-
return make(map[string]string)
132-
}
133-
13480
// initExcludedTests provides list of excluded tests for e2e and exanples tests
13581
func initExcludedTests() sets.String {
136-
13782
switch getTestArch() {
13883
case "s390x":
13984
return sets.NewString(

0 commit comments

Comments
 (0)