Skip to content

Commit

Permalink
Add static analysis to test files (#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino committed Jan 22, 2023
1 parent 27bd4c9 commit b7aaa41
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ jobs:
- name: Install gosec
run: curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- name: Run gosec
# Temporary ignoring G301,G302,G306
run: gosec -exclude=G204,G301,G302,G304,G306 -exclude-dir=\.*test\.* ./...
run: gosec -exclude=G204,G301,G302,G304,G306 -tests -exclude-dir=\.*test\.* ./...
25 changes: 12 additions & 13 deletions artifactory/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestPrepareSearchDownloadDeleteCommands(t *testing.T) {

for _, test := range testRuns {
t.Run(test.name, func(t *testing.T) {
context, buffer := createContext(test.flags, test.args)
context, buffer := createContext(t, test.flags, test.args)
funcArray := []func(c *cli.Context) (*spec.SpecFiles, error){
prepareSearchCommand, prepareDownloadCommand, prepareDeleteCommand,
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestPrepareCopyMoveCommand(t *testing.T) {

for _, test := range testRuns {
t.Run(test.name, func(t *testing.T) {
context, buffer := createContext(test.flags, test.args)
context, buffer := createContext(t, test.flags, test.args)
specFiles, err := prepareCopyMoveCommand(context)
assertGenericCommand(t, err, buffer, test.expectError, test.expectedPattern, test.expectedBuild, test.expectedBundle, specFiles)
})
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestPreparePropsCmd(t *testing.T) {

for _, test := range testRuns {
t.Run(test.name, func(t *testing.T) {
context, buffer := createContext(test.flags, test.args)
context, buffer := createContext(t, test.flags, test.args)
propsCommand, err := preparePropsCmd(context)
var actualSpec *spec.SpecFiles
if propsCommand != nil {
Expand All @@ -119,8 +119,8 @@ func assertGenericCommand(t *testing.T, err error, buffer *bytes.Buffer, expectE
}
}

func createContext(testFlags, testArgs []string) (*cli.Context, *bytes.Buffer) {
flagSet := createFlagSet(testFlags, testArgs)
func createContext(t *testing.T, testFlags, testArgs []string) (*cli.Context, *bytes.Buffer) {
flagSet := createFlagSet(t, testFlags, testArgs)
app := cli.NewApp()
app.Writer = &bytes.Buffer{}
return cli.NewContext(app, flagSet, nil), &bytes.Buffer{}
Expand All @@ -130,17 +130,16 @@ func getSpecPath(spec string) string {
return filepath.Join("..", "testdata", "filespecs", spec)
}

// Create flagset with input flags and arguments.
func createFlagSet(flags []string, args []string) *flag.FlagSet {
// Create flag set with input flags and arguments.
func createFlagSet(t *testing.T, flags []string, args []string) *flag.FlagSet {
flagSet := flag.NewFlagSet("TestFlagSet", flag.ContinueOnError)
flags = append(flags, "url=http://127.0.0.1:8081/artifactory")
cmdFlags := []string{}
for _, flag := range flags {
flagSet.String(strings.Split(flag, "=")[0], "", "")
cmdFlags = append(cmdFlags, "--"+flag)
var cmdFlags []string
for _, curFlag := range flags {
flagSet.String(strings.Split(curFlag, "=")[0], "", "")
cmdFlags = append(cmdFlags, "--"+curFlag)
}
cmdFlags = append(cmdFlags, args...)
flagSet.Parse(cmdFlags)

assert.NoError(t, flagSet.Parse(cmdFlags))
return flagSet
}
1 change: 1 addition & 0 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ func checkForErrDueToMissingProxy(spec *spec.SpecFiles, t *testing.T) {

func checkIfServerIsUp(port, proxyScheme string, useClientCerts bool) error {
tr := &http.Transport{
//#nosec G402
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}

Expand Down
2 changes: 1 addition & 1 deletion distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func initDistributionTest(t *testing.T) {
}

func cleanDistributionTest(t *testing.T) {
distributionCli.Exec("rbdel", tests.BundleName, bundleVersion, "--site=*", "--delete-from-dist", "--quiet", "--sync")
assert.NoError(t, distributionCli.Exec("rbdel", tests.BundleName, bundleVersion, "--site=*", "--delete-from-dist", "--quiet", "--sync"))
inttestutils.CleanDistributionRepositories(t, serverDetails)
tests.CleanFileSystem()
}
Expand Down

0 comments on commit b7aaa41

Please sign in to comment.