Skip to content

Commit 2adab36

Browse files
authored
Catch unhandled errors and fix warnings (#1332)
Add an error assertion for tests. Catch unhandled errors. Fix some warnings for variables that collide with imported package names.
1 parent c181d7f commit 2adab36

27 files changed

+1049
-1097
lines changed

Diff for: artifactory/cli_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func TestPrepareSearchDownloadDeleteCommands(t *testing.T) {
17-
tests := []struct {
17+
testRuns := []struct {
1818
name string
1919
args []string
2020
flags []string
@@ -27,12 +27,12 @@ func TestPrepareSearchDownloadDeleteCommands(t *testing.T) {
2727
{"withPattern", []string{"TestPattern"}, []string{}, "TestPattern", "", "", false},
2828
{"withBuild", []string{}, []string{"build=buildName/buildNumber"}, "", "buildName/buildNumber", "", false},
2929
{"withBundle", []string{}, []string{"bundle=bundleName/bundleVersion"}, "", "", "bundleName/bundleVersion", false},
30-
{"withSpec", []string{}, []string{"spec=" + getSpecPath(t, tests.SearchAllRepo1)}, "${REPO1}/*", "", "", false},
31-
{"withSpecAndPattern", []string{"TestPattern"}, []string{"spec=" + getSpecPath(t, tests.SearchAllRepo1)}, "", "", "", true},
30+
{"withSpec", []string{}, []string{"spec=" + getSpecPath(tests.SearchAllRepo1)}, "${REPO1}/*", "", "", false},
31+
{"withSpecAndPattern", []string{"TestPattern"}, []string{"spec=" + getSpecPath(tests.SearchAllRepo1)}, "", "", "", true},
3232
{"withBuildAndPattern", []string{"TestPattern"}, []string{"build=buildName/buildNumber"}, "TestPattern", "buildName/buildNumber", "", false},
3333
}
3434

35-
for _, test := range tests {
35+
for _, test := range testRuns {
3636
t.Run(test.name, func(t *testing.T) {
3737
context, buffer := createContext(test.flags, test.args)
3838
funcArray := []func(c *cli.Context) (*spec.SpecFiles, error){
@@ -47,7 +47,7 @@ func TestPrepareSearchDownloadDeleteCommands(t *testing.T) {
4747
}
4848

4949
func TestPrepareCopyMoveCommand(t *testing.T) {
50-
tests := []struct {
50+
testRuns := []struct {
5151
name string
5252
args []string
5353
flags []string
@@ -59,13 +59,13 @@ func TestPrepareCopyMoveCommand(t *testing.T) {
5959
}{
6060
{"withoutArguments", []string{}, []string{}, "", "", "", "", true},
6161
{"withPatternAndTarget", []string{"TestPattern", "TestTarget"}, []string{}, "TestPattern", "TestTarget", "", "", false},
62-
{"withSpec", []string{}, []string{"spec=" + getSpecPath(t, tests.CopyItemsSpec)}, "${REPO1}/*/", "${REPO2}/", "", "", false},
63-
{"withSpecAndPattern", []string{"TestPattern"}, []string{"spec=" + getSpecPath(t, tests.CopyItemsSpec)}, "", "", "", "", true},
62+
{"withSpec", []string{}, []string{"spec=" + getSpecPath(tests.CopyItemsSpec)}, "${REPO1}/*/", "${REPO2}/", "", "", false},
63+
{"withSpecAndPattern", []string{"TestPattern"}, []string{"spec=" + getSpecPath(tests.CopyItemsSpec)}, "", "", "", "", true},
6464
{"withPatternTargetAndBuild", []string{"TestPattern", "TestTarget"}, []string{"build=buildName/buildNumber"}, "TestPattern", "", "buildName/buildNumber", "", false},
6565
{"withPatternTargetAndBundle", []string{"TestPattern", "TestTarget"}, []string{"bundle=bundleName/bundleVersion"}, "TestPattern", "", "", "bundleName/bundleVersion", false},
6666
}
6767

68-
for _, test := range tests {
68+
for _, test := range testRuns {
6969
t.Run(test.name, func(t *testing.T) {
7070
context, buffer := createContext(test.flags, test.args)
7171
specFiles, err := prepareCopyMoveCommand(context)
@@ -75,7 +75,7 @@ func TestPrepareCopyMoveCommand(t *testing.T) {
7575
}
7676

7777
func TestPreparePropsCmd(t *testing.T) {
78-
tests := []struct {
78+
testRuns := []struct {
7979
name string
8080
args []string
8181
flags []string
@@ -89,12 +89,12 @@ func TestPreparePropsCmd(t *testing.T) {
8989
{"withPattern", []string{"TestPattern", "key1=val1"}, []string{}, "key1=val1", "TestPattern", "", "", false},
9090
{"withBuild", []string{"key1=val1"}, []string{"build=buildName/buildNumber"}, "key1=val1", "*", "buildName/buildNumber", "", false},
9191
{"withBundle", []string{"key1=val1"}, []string{"bundle=bundleName/bundleVersion"}, "key1=val1", "*", "", "bundleName/bundleVersion", false},
92-
{"withSpec", []string{"key1=val1"}, []string{"spec=" + getSpecPath(t, tests.SetDeletePropsSpec)}, "key1=val1", "${REPO1}/", "", "", false},
93-
{"withSpecAndPattern", []string{"TestPattern", "key1=val1"}, []string{"spec=" + getSpecPath(t, tests.SetDeletePropsSpec)}, "key1=val1", "", "", "", true},
92+
{"withSpec", []string{"key1=val1"}, []string{"spec=" + getSpecPath(tests.SetDeletePropsSpec)}, "key1=val1", "${REPO1}/", "", "", false},
93+
{"withSpecAndPattern", []string{"TestPattern", "key1=val1"}, []string{"spec=" + getSpecPath(tests.SetDeletePropsSpec)}, "key1=val1", "", "", "", true},
9494
{"withPatternAndBuild", []string{"TestPattern", "key1=val1"}, []string{"build=buildName/buildNumber"}, "key1=val1", "TestPattern", "buildName/buildNumber", "", false},
9595
}
9696

97-
for _, test := range tests {
97+
for _, test := range testRuns {
9898
t.Run(test.name, func(t *testing.T) {
9999
context, buffer := createContext(test.flags, test.args)
100100
propsCommand, err := preparePropsCmd(context)
@@ -126,7 +126,7 @@ func createContext(testFlags, testArgs []string) (*cli.Context, *bytes.Buffer) {
126126
return cli.NewContext(app, flagSet, nil), &bytes.Buffer{}
127127
}
128128

129-
func getSpecPath(t *testing.T, spec string) string {
129+
func getSpecPath(spec string) string {
130130
return filepath.Join("..", "testdata", "filespecs", spec)
131131
}
132132

0 commit comments

Comments
 (0)