Skip to content
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

Add static analysis to test files #1809

Merged
merged 1 commit into from
Jan 22, 2023
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
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 @@ -1720,6 +1720,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