Skip to content
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 30 additions & 32 deletions attestor/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
}
6 changes: 6 additions & 0 deletions checker/detail_logger_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

func Test_logger_Info(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
Expand All @@ -28,6 +29,7 @@ func Test_logger_Info(t *testing.T) {
}

func Test_logger_Warn(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
Expand All @@ -38,6 +40,7 @@ func Test_logger_Warn(t *testing.T) {
}

func Test_logger_Flush(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
Expand All @@ -52,6 +55,7 @@ func Test_logger_Flush(t *testing.T) {
}

func Test_logger_Logs(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
Expand All @@ -62,6 +66,7 @@ func Test_logger_Logs(t *testing.T) {
}

func Test_logger_Debug(t *testing.T) {
t.Parallel()
l := &logger{
logs: []CheckDetail{},
}
Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions checker/raw_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

func TestFile_Location(t *testing.T) {
t.Parallel()
file := File{
Type: finding.FileTypeSource,
Path: "bar.go",
Expand Down
3 changes: 3 additions & 0 deletions checks/evaluation/pinned_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ func Test_addWorkflowPinnedResult(t *testing.T) {
}

func TestGenerateText(t *testing.T) {
t.Parallel()
tests := []struct {
name string
dependency *checker.Dependency
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions checks/evaluation/signed_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

func TestSignedReleases(t *testing.T) {
t.Parallel()
tests := []struct {
name string
releases []clients.Release
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions checks/raw/binary_artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions checks/raw/contributors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestOrgContains(t *testing.T) {
}

func TestContributors(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand Down
1 change: 0 additions & 1 deletion checks/raw/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions checks/raw/maintained_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions checks/raw/shell_download_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestValidateShellFile(t *testing.T) {
}

func Test_isDotNetUnpinnedDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -215,6 +218,7 @@ func Test_isDotNetUnpinnedDownload(t *testing.T) {
}

func Test_isGoUnpinnedDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
Expand All @@ -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)
}
Expand All @@ -248,6 +254,7 @@ func Test_isGoUnpinnedDownload(t *testing.T) {
}

func Test_isNpmDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
Expand All @@ -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)
}
Expand All @@ -281,6 +290,7 @@ func Test_isNpmDownload(t *testing.T) {
}

func Test_isNpmUnpinnedDownload(t *testing.T) {
t.Parallel()
type args struct {
cmd []string
}
Expand All @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions clients/git/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
Expand All @@ -124,6 +125,7 @@ func TestInitRepo(t *testing.T) {
}

func TestListCommits(t *testing.T) {
t.Parallel()
repoPath := createTestRepo(t)

client := &Client{}
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions clients/githubrepo/checkruns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions clients/githubrepo/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions clients/githubrepo/internal/fnmatch/fnmatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

func TestMatch(t *testing.T) {
t.Parallel()
tests := []struct {
pattern string
path string
Expand Down
2 changes: 1 addition & 1 deletion clients/githubrepo/roundtripper/tokens/accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"
)

//nolint:paralleltest
//nolint:paralleltest // test uses t.Setenv
func TestMakeTokenAccessor(t *testing.T) {
tests := []struct {
name string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions clients/githubrepo/roundtripper/tokens/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions clients/gitlabrepo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestRepoURL_IsValid(t *testing.T) {
}

func TestRepoURL_MakeGitLabRepo(t *testing.T) {
t.Parallel()
tests := []struct {
repouri string
expected bool
Expand Down
Loading