🌱 re-enable paralleltest linter (#3705)

Signed-off-by: Spencer Schrock <sschrock@google.com>
This commit is contained in:
Spencer Schrock 2023-12-03 18:25:03 -08:00 committed by GitHub
parent 1625b0c578
commit d882fc73e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 104 additions and 38 deletions

View File

@ -75,7 +75,6 @@ linters:
- wrapcheck
disable:
- exhaustruct # initializing every struct makes tests longer without much benefit (spencerschrock)
- paralleltest # need to investigate rate limit issues before re-enabling? (#2527)
- testpackage # tests don't need their own package (spencerschrock)
presets:
- bugs

View File

@ -20,43 +20,41 @@ import (
)
func Test_addSignFlags(t *testing.T) {
t.Parallel()
type args struct {
cmd *cobra.Command
}
testName := "Test addSignFlags"
testArgs := args{
cmd: &cobra.Command{},
}
t.Run(testName, func(t *testing.T) {
addSignFlags(testArgs.cmd)
// persistent flags of Image being set has to be tested in the integration test
if testArgs.cmd.PersistentFlags().Lookup("image") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'image'")
}
if testArgs.cmd.PersistentFlags().Lookup("attestation-project") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'attestation-project'")
}
if testArgs.cmd.PersistentFlags().Lookup("overwrite") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'overwrite'")
}
if testArgs.cmd.PersistentFlags().Lookup("kms-key-name") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'kms-key-name'")
}
if testArgs.cmd.PersistentFlags().Lookup("kms-digest-alg") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'kms-digest-alg'")
}
if testArgs.cmd.PersistentFlags().Lookup("pgp-private-key") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pgp-private-key'")
}
if testArgs.cmd.PersistentFlags().Lookup("pgp-passphrase") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pgp-passphrase'")
}
if testArgs.cmd.PersistentFlags().Lookup("pkix-private-key") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pkix-private-key'")
}
if testArgs.cmd.PersistentFlags().Lookup("pkix-alg") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pkix-alg'")
}
})
addSignFlags(testArgs.cmd)
// persistent flags of Image being set has to be tested in the integration test
if testArgs.cmd.PersistentFlags().Lookup("image") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'image'")
}
if testArgs.cmd.PersistentFlags().Lookup("attestation-project") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'attestation-project'")
}
if testArgs.cmd.PersistentFlags().Lookup("overwrite") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'overwrite'")
}
if testArgs.cmd.PersistentFlags().Lookup("kms-key-name") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'kms-key-name'")
}
if testArgs.cmd.PersistentFlags().Lookup("kms-digest-alg") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'kms-digest-alg'")
}
if testArgs.cmd.PersistentFlags().Lookup("pgp-private-key") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pgp-private-key'")
}
if testArgs.cmd.PersistentFlags().Lookup("pgp-passphrase") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pgp-passphrase'")
}
if testArgs.cmd.PersistentFlags().Lookup("pkix-private-key") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pkix-private-key'")
}
if testArgs.cmd.PersistentFlags().Lookup("pkix-alg") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pkix-alg'")
}
}

View File

@ -18,6 +18,7 @@ import (
)
func Test_logger_Info(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
@ -28,6 +29,7 @@ func Test_logger_Info(t *testing.T) {
}
func Test_logger_Warn(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
@ -38,6 +40,7 @@ func Test_logger_Warn(t *testing.T) {
}
func Test_logger_Flush(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
@ -52,6 +55,7 @@ func Test_logger_Flush(t *testing.T) {
}
func Test_logger_Logs(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
@ -62,6 +66,7 @@ func Test_logger_Logs(t *testing.T) {
}
func Test_logger_Debug(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
@ -72,6 +77,7 @@ func Test_logger_Debug(t *testing.T) {
}
func TestNewLogger(t *testing.T) {
t.Parallel()
l := NewLogger()
if l == nil {
t.Errorf("expected non-nil logger, got nil")

View File

@ -20,6 +20,7 @@ import (
)
func TestFile_Location(t *testing.T) {
t.Parallel()
file := File{
Type: finding.FileTypeSource,
Path: "bar.go",

View File

@ -988,6 +988,7 @@ func Test_addWorkflowPinnedResult(t *testing.T) {
}
func TestGenerateText(t *testing.T) {
t.Parallel()
tests := []struct {
name string
dependency *checker.Dependency
@ -1016,7 +1017,9 @@ func TestGenerateText(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result := generateTextUnpinned(tc.dependency)
if !cmp.Equal(tc.expectedText, result) {
t.Errorf("generateText mismatch (-want +got):\n%s", cmp.Diff(tc.expectedText, result))

View File

@ -26,6 +26,7 @@ import (
)
func TestSignedReleases(t *testing.T) {
t.Parallel()
tests := []struct {
name string
releases []clients.Release
@ -93,7 +94,9 @@ func TestSignedReleases(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
dl := &scut.TestDetailLogger{}
data := &checker.SignedReleasesData{Releases: tc.releases}
actualResult := SignedReleases("Signed-Releases", dl, data)

View File

@ -258,6 +258,7 @@ func TestBinaryArtifacts(t *testing.T) {
}
func TestBinaryArtifacts_workflow_runs_unsupported(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mockRepoClient := mockrepo.NewMockRepoClient(ctrl)
const jarFile = "gradle-wrapper.jar"

View File

@ -105,6 +105,7 @@ func TestOrgContains(t *testing.T) {
}
func TestContributors(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -646,7 +646,6 @@ func TestLicenseFileCheck(t *testing.T) {
},
}
//nolint:paralleltest
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
for _, ext := range tt.extensions {

View File

@ -26,6 +26,7 @@ import (
mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
)
//nolint:paralleltest // need to break into separate tests
func TestMaintained(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -112,6 +112,7 @@ func TestValidateShellFile(t *testing.T) {
}
func Test_isDotNetUnpinnedDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
@ -206,7 +207,9 @@ func Test_isDotNetUnpinnedDownload(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := isNugetUnpinnedDownload(tt.args.cmd); got != tt.want {
t.Errorf("isNugetUnpinnedDownload() = %v, want %v", got, tt.want)
}
@ -215,6 +218,7 @@ func Test_isDotNetUnpinnedDownload(t *testing.T) {
}
func Test_isGoUnpinnedDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
@ -239,7 +243,9 @@ func Test_isGoUnpinnedDownload(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := isGoUnpinnedDownload(tt.args.cmd); got != tt.want {
t.Errorf("isGoUnpinnedDownload() = %v, want %v", got, tt.want)
}
@ -248,6 +254,7 @@ func Test_isGoUnpinnedDownload(t *testing.T) {
}
func Test_isNpmDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
@ -272,7 +279,9 @@ func Test_isNpmDownload(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := isNpmDownload(tt.args.cmd); got != tt.want {
t.Errorf("isNpmDownload() = %v, want %v", got, tt.want)
}
@ -281,6 +290,7 @@ func Test_isNpmDownload(t *testing.T) {
}
func Test_isNpmUnpinnedDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
@ -305,7 +315,9 @@ func Test_isNpmUnpinnedDownload(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := isNpmUnpinnedDownload(tt.args.cmd); got != tt.want {
t.Errorf("isNpmUnpinnedDownload() = %v, want %v", got, tt.want)
}

View File

@ -77,8 +77,8 @@ func createTestRepo(t *testing.T) (path string) {
return dir
}
//nolint:paralleltest
func TestInitRepo(t *testing.T) {
t.Parallel()
tests := []struct { //nolint:govet
name string
uri string
@ -112,6 +112,7 @@ func TestInitRepo(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
uri := fmt.Sprintf(test.uri, repoPath)
client := &Client{}
@ -124,6 +125,7 @@ func TestInitRepo(t *testing.T) {
}
func TestListCommits(t *testing.T) {
t.Parallel()
repoPath := createTestRepo(t)
client := &Client{}
@ -147,8 +149,8 @@ func TestListCommits(t *testing.T) {
}
}
//nolint:paralleltest
func TestSearch(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
request clients.SearchRequest
@ -215,7 +217,9 @@ func TestSearch(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
client := &Client{}
uri := fmt.Sprintf("file://%s", repoPath)
if err := client.InitRepo(uri, "HEAD", 1); err != nil {

View File

@ -22,6 +22,7 @@ import (
)
func Test_init_clearsErr(t *testing.T) {
t.Parallel()
handler := &checkrunsHandler{errSetup: sce.ErrScorecardInternal}
handler.init(context.Background(), nil, 0)
if handler.errSetup != nil {

View File

@ -35,6 +35,7 @@ func (b badGatewayRoundTripper) RoundTrip(*http.Request) (*http.Response, error)
}
func Test_getCommits_retry(t *testing.T) {
t.Parallel()
var nRequests int
rt := badGatewayRoundTripper{requestCounter: &nRequests}
handler := graphqlHandler{

View File

@ -19,6 +19,7 @@ import (
)
func TestMatch(t *testing.T) {
t.Parallel()
tests := []struct {
pattern string
path string

View File

@ -20,7 +20,7 @@ import (
"testing"
)
//nolint:paralleltest
//nolint:paralleltest // test uses t.Setenv
func TestMakeTokenAccessor(t *testing.T) {
tests := []struct {
name string

View File

@ -17,7 +17,7 @@ import (
"testing"
)
//golint:paralleltest
//nolint:paralleltest // order dependent
func TestNext(t *testing.T) {
tokens := []string{"token1", "token2", "token3", "token4", "token5"}
rr := makeRoundRobinAccessor(tokens)
@ -35,6 +35,7 @@ func TestNext(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if tt.releaseID != nil {
rr.Release(*tt.releaseID)

View File

@ -45,6 +45,7 @@ func newMockTokenAccessor(tokens []string) *mockTokenAccessor {
}
func TestTokenOverRPC_Next(t *testing.T) {
t.Parallel()
mockClient := newMockTokenAccessor([]string{"token1", "token2", "token3"})
rpc := NewTokenOverRPC(mockClient)
token := &Token{}
@ -66,6 +67,7 @@ func TestTokenOverRPC_Next(t *testing.T) {
}
func TestTokenOverRPC_Release(t *testing.T) {
t.Parallel()
mockClient := newMockTokenAccessor([]string{"token1", "token2", "token3"})
rpc := NewTokenOverRPC(mockClient)

View File

@ -119,6 +119,7 @@ func TestRepoURL_IsValid(t *testing.T) {
}
func TestRepoURL_MakeGitLabRepo(t *testing.T) {
t.Parallel()
tests := []struct {
repouri string
expected bool

View File

@ -198,6 +198,7 @@ func setupServer(t *testing.T) string {
}
func TestAllClientMethods(t *testing.T) {
t.Parallel()
c := CreateOSSFuzzClient("testURL")
// Test InitRepo

View File

@ -22,6 +22,7 @@ import (
)
func TestResults(t *testing.T) {
t.Parallel()
//nolint:govet // field alignment
tests := []struct {
name string
@ -213,7 +214,9 @@ func TestResults(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := Results(tt.a, tt.b); got != tt.wantEqual {
t.Errorf("Results() = %v, want %v", got, tt.wantEqual)
}

View File

@ -166,6 +166,7 @@ func TestJSON(t *testing.T) {
}
func Test_normalize_nil_safe(t *testing.T) {
t.Parallel()
var x, y *pkg.ScorecardResult
Normalize(x)
Normalize(y)

View File

@ -25,6 +25,7 @@ import (
)
func TestNew(t *testing.T) {
t.Parallel()
r := New(nil)
if len(r.enabledChecks) == 0 {
t.Errorf("runner has no checks to run: %v", r.enabledChecks)
@ -37,6 +38,7 @@ func TestNew(t *testing.T) {
}
func TestRunner_Run(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mockRepo := mockrepo.NewMockRepoClient(ctrl)
commit := []clients.Commit{{SHA: "foo"}}

View File

@ -25,6 +25,7 @@ import (
)
func Test_initRepoAndClientByChecks(t *testing.T) {
t.Parallel()
//nolint:govet
tests := []struct {
name string
@ -57,6 +58,7 @@ func Test_initRepoAndClientByChecks(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := initRepoAndClientByChecks(&tt.dCtx, tt.srcRepo)
if (err != nil) != tt.wantErr {
t.Errorf("initClientByChecks() error = {%v}, want error: %v", err, tt.wantErr)
@ -83,6 +85,7 @@ func Test_initRepoAndClientByChecks(t *testing.T) {
}
func Test_getScorecardCheckResults(t *testing.T) {
t.Parallel()
tests := []struct {
name string
dCtx dependencydiffContext
@ -102,6 +105,7 @@ func Test_getScorecardCheckResults(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := getScorecardCheckResults(&tt.dCtx)
if (err != nil) != tt.wantErr {
t.Errorf("getScorecardCheckResults() error = {%v}, want error: %v", err, tt.wantErr)
@ -112,6 +116,7 @@ func Test_getScorecardCheckResults(t *testing.T) {
}
func Test_mapDependencyEcosystemNaming(t *testing.T) {
t.Parallel()
//nolint:govet
tests := []struct {
name string
@ -167,6 +172,7 @@ func Test_mapDependencyEcosystemNaming(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := mapDependencyEcosystemNaming(tt.deps)
if tt.errWanted != nil && errors.Is(tt.errWanted, err) {
t.Errorf("not a wanted error, want:%v, got:%v", tt.errWanted, err)
@ -177,6 +183,7 @@ func Test_mapDependencyEcosystemNaming(t *testing.T) {
}
func Test_isSpecifiedByUser(t *testing.T) {
t.Parallel()
tests := []struct {
name string
ct pkg.ChangeType
@ -214,6 +221,7 @@ func Test_isSpecifiedByUser(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := isSpecifiedByUser(tt.ct, tt.changeTypesToCheck)
if result != tt.resultWanted {
t.Errorf("result (%v) != result wanted (%v)", result, tt.resultWanted)

View File

@ -25,6 +25,7 @@ import (
"github.com/ossf/scorecard/v4/log"
)
//nolint:paralleltest // avoiding parallel e2e tests due to rate limit concerns (#2527)
func TestE2e(t *testing.T) {
if val, exists := os.LookupEnv("SKIP_GINKGO"); exists && val == "1" {
t.Skip()

View File

@ -21,6 +21,7 @@ import (
)
func TestCreateInternal(t *testing.T) {
t.Parallel()
type args struct {
e error
msg string
@ -39,6 +40,7 @@ func TestCreateInternal(t *testing.T) {
}
t.Run(test.name, func(t *testing.T) {
t.Parallel()
if got := CreateInternal(test.args.e, test.args.msg); got.Error() != test.want.Error() {
t.Errorf("CreateInternal() = %v, want %v", got, test.want)
}

View File

@ -472,6 +472,7 @@ func TestJsonScorecardRawResult_AddMaintainedRawResults(t *testing.T) {
}
func TestSetDefaultCommitData(t *testing.T) {
t.Parallel()
// Define some test data.
changesets := []checker.Changeset{
{
@ -657,6 +658,7 @@ func TestJsonScorecardRawResult_AddCodeReviewRawResults(t *testing.T) {
}
func TestAddCodeReviewRawResults(t *testing.T) {
t.Parallel()
r := &jsonScorecardRawResult{}
cr := &checker.CodeReviewData{
DefaultBranchChangesets: []checker.Changeset{
@ -729,6 +731,7 @@ func TestAddCodeReviewRawResults(t *testing.T) {
}
func TestAddLicenseRawResults(t *testing.T) {
t.Parallel()
// Create a new jsonScorecardRawResult instance
r := &jsonScorecardRawResult{}
@ -793,6 +796,7 @@ func TestAddLicenseRawResults(t *testing.T) {
}
func TestAddBinaryArtifactRawResults(t *testing.T) {
t.Parallel()
r := &jsonScorecardRawResult{}
ba := &checker.BinaryArtifactData{
Files: []checker.File{
@ -831,6 +835,7 @@ func TestAddBinaryArtifactRawResults(t *testing.T) {
}
func TestAddSecurityPolicyRawResults(t *testing.T) {
t.Parallel()
r := &jsonScorecardRawResult{}
sp := &checker.SecurityPolicyData{
PolicyFiles: []checker.SecurityPolicyFile{
@ -917,6 +922,7 @@ func TestAddSecurityPolicyRawResults(t *testing.T) {
}
func TestAddVulnerabilitiesRawResults(t *testing.T) {
t.Parallel()
r := &jsonScorecardRawResult{}
vd := &checker.VulnerabilitiesData{
Vulnerabilities: []clients.Vulnerability{
@ -955,6 +961,7 @@ func TestAddVulnerabilitiesRawResults(t *testing.T) {
}
func TestAddFuzzingRawResults(t *testing.T) {
t.Parallel()
r := &jsonScorecardRawResult{}
fd := &checker.FuzzingData{
Fuzzers: []checker.Tool{
@ -1040,6 +1047,7 @@ func TestAddFuzzingRawResults(t *testing.T) {
}
func TestJsonScorecardRawResult(t *testing.T) {
t.Parallel()
// create a new instance of jsonScorecardRawResult
r := &jsonScorecardRawResult{}
@ -1225,6 +1233,7 @@ func intPtr(i int32) *int32 {
}
func TestScorecardResult_AsRawJSON(t *testing.T) {
t.Parallel()
type fields struct {
Repo RepoInfo
Date time.Time
@ -1254,6 +1263,7 @@ func TestScorecardResult_AsRawJSON(t *testing.T) {
for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
r := &ScorecardResult{
Repo: tt.fields.Repo,
Date: tt.fields.Date,
@ -1343,6 +1353,7 @@ func TestAddBranchProtectionRawResults(t *testing.T) {
}
func TestFillJSONRawResults(t *testing.T) {
t.Parallel()
raw := checker.RawResults{
LicenseResults: checker.LicenseData{
LicenseFiles: []checker.LicenseFile{

View File

@ -22,6 +22,7 @@ import (
. "github.com/onsi/gomega"
)
//nolint:paralleltest // avoiding parallel e2e tests due to rate limit concerns (#2527)
func TestPkg(t *testing.T) {
if val, exists := os.LookupEnv("SKIP_GINKGO"); exists && val == "1" {
t.Skip()

View File

@ -137,6 +137,7 @@ func TestPolicyRead(t *testing.T) {
}
func TestChecksHavePolicies(t *testing.T) {
t.Parallel()
// Create a sample ScorecardPolicy
sp := &ScorecardPolicy{
Version: 1,