diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index be4374d7a..e8e20ca38 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -35,10 +35,6 @@ jobs: with: go-version: 1.20.x - # Generate mocks - - name: Generate mocks - run: go generate ./... - - name: Run Gosec Security Scanner uses: securego/gosec@master with: diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 07967acc5..665ca3866 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -23,7 +23,7 @@ jobs: env: # Generated and maintained by GitHub GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # JFrog organization secret + # JFrog's organization secret PERSONAL_ACCESS_TOKEN: ${{ secrets.CLA_SIGN_TOKEN }} with: path-to-signatures: "signed_clas.json" diff --git a/commands/scanpullrequest/scanallpullrequests_test.go b/commands/scanpullrequest/scanallpullrequests_test.go index 3140a70db..0b09e7431 100644 --- a/commands/scanpullrequest/scanallpullrequests_test.go +++ b/commands/scanpullrequest/scanallpullrequests_test.go @@ -38,7 +38,7 @@ type MockParams struct { //go:generate go run github.com/golang/mock/mockgen@v1.6.0 -destination=../testdata/vcsclientmock.go -package=testdata github.com/jfrog/froggit-go/vcsclient VcsClient func TestShouldScanPullRequestNewPR(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) prID := 0 client.EXPECT().ListPullRequestComments(context.Background(), gitParams.RepoOwner, gitParams.RepoName, prID).Return([]vcsclient.CommentInfo{}, nil) // Run handleFrogbotLabel @@ -49,7 +49,7 @@ func TestShouldScanPullRequestNewPR(t *testing.T) { func TestShouldScanPullRequestReScan(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) prID := 0 client.EXPECT().ListPullRequestComments(context.Background(), gitParams.RepoOwner, gitParams.RepoName, prID).Return([]vcsclient.CommentInfo{ {Content: outputwriter.GetSimplifiedTitle(outputwriter.VulnerabilitiesPrBannerSource) + "text \n table\n text text text", Created: time.Unix(1, 0)}, @@ -62,7 +62,7 @@ func TestShouldScanPullRequestReScan(t *testing.T) { func TestShouldNotScanPullRequestReScan(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) prID := 0 client.EXPECT().ListPullRequestComments(context.Background(), gitParams.RepoOwner, gitParams.RepoName, prID).Return([]vcsclient.CommentInfo{ {Content: outputwriter.GetSimplifiedTitle(outputwriter.VulnerabilitiesPrBannerSource) + "text \n table\n text text text", Created: time.Unix(1, 0)}, @@ -76,7 +76,7 @@ func TestShouldNotScanPullRequestReScan(t *testing.T) { func TestShouldNotScanPullRequest(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) prID := 0 client.EXPECT().ListPullRequestComments(context.Background(), gitParams.RepoOwner, gitParams.RepoName, prID).Return([]vcsclient.CommentInfo{ {Content: outputwriter.GetSimplifiedTitle(outputwriter.NoVulnerabilityPrBannerSource) + "text \n table\n text text text", Created: time.Unix(3, 0)}, @@ -88,7 +88,7 @@ func TestShouldNotScanPullRequest(t *testing.T) { func TestShouldNotScanPullRequestError(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) prID := 0 client.EXPECT().ListPullRequestComments(context.Background(), gitParams.RepoOwner, gitParams.RepoName, prID).Return([]vcsclient.CommentInfo{}, fmt.Errorf("Bad Request")) shouldScan, err := shouldScanPullRequest(*gitParams, client, prID) @@ -191,7 +191,7 @@ func TestScanAllPullRequests(t *testing.T) { func getMockClient(t *testing.T, frogbotMessages *[]string, mockParams ...MockParams) *testdata.MockVcsClient { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) for _, params := range mockParams { sourceBranchInfo := vcsclient.BranchInfo{Name: params.sourceBranchName, Repository: params.repoName, Owner: params.repoOwner} targetBranchInfo := vcsclient.BranchInfo{Name: params.targetBranchName, Repository: params.repoName, Owner: params.repoOwner} @@ -224,3 +224,7 @@ func fakeRepoDownload(_ context.Context, _, _, testProject, targetDir string) er } return fileutils.CopyDir(sourceDir, targetDir, true, []string{}) } + +func CreateMockVcsClient(t *testing.T) *testdata.MockVcsClient { + return testdata.NewMockVcsClient(gomock.NewController(t)) +} diff --git a/commands/scanpullrequest/scanpullrequest_test.go b/commands/scanpullrequest/scanpullrequest_test.go index 39b86cf5e..6c1b9b95b 100644 --- a/commands/scanpullrequest/scanpullrequest_test.go +++ b/commands/scanpullrequest/scanpullrequest_test.go @@ -521,7 +521,7 @@ func testScanPullRequest(t *testing.T, configPath, projectName string, failOnSec func TestVerifyGitHubFrogbotEnvironment(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) environment := "frogbot" client.EXPECT().GetRepositoryInfo(context.Background(), gitParams.RepoOwner, gitParams.RepoName).Return(vcsclient.RepositoryInfo{}, nil) client.EXPECT().GetRepositoryEnvironmentInfo(context.Background(), gitParams.RepoOwner, gitParams.RepoName, environment).Return(vcsclient.RepositoryEnvironmentInfo{Reviewers: []string{"froggy"}}, nil) @@ -538,7 +538,7 @@ func TestVerifyGitHubFrogbotEnvironmentNoEnv(t *testing.T) { defer log.SetLogger(previousLogger) // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) environment := "frogbot" client.EXPECT().GetRepositoryInfo(context.Background(), gitParams.RepoOwner, gitParams.RepoName).Return(vcsclient.RepositoryInfo{}, nil) client.EXPECT().GetRepositoryEnvironmentInfo(context.Background(), gitParams.RepoOwner, gitParams.RepoName, environment).Return(vcsclient.RepositoryEnvironmentInfo{}, errors.New("404")) @@ -551,7 +551,7 @@ func TestVerifyGitHubFrogbotEnvironmentNoEnv(t *testing.T) { func TestVerifyGitHubFrogbotEnvironmentNoReviewers(t *testing.T) { // Init mock - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) environment := "frogbot" client.EXPECT().GetRepositoryInfo(context.Background(), gitParams.RepoOwner, gitParams.RepoName).Return(vcsclient.RepositoryInfo{}, nil) client.EXPECT().GetRepositoryEnvironmentInfo(context.Background(), gitParams.RepoOwner, gitParams.RepoName, environment).Return(vcsclient.RepositoryEnvironmentInfo{}, nil) @@ -764,7 +764,7 @@ func TestDeletePreviousPullRequestMessages(t *testing.T) { }, OutputWriter: &outputwriter.StandardOutput{}, } - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) // Test with comment returned client.EXPECT().ListPullRequestComments(context.Background(), "owner", "repo", 17).Return([]vcsclient.CommentInfo{ diff --git a/commands/scanrepository/scanrepository_test.go b/commands/scanrepository/scanrepository_test.go index ed942896b..0c62facd3 100644 --- a/commands/scanrepository/scanrepository_test.go +++ b/commands/scanrepository/scanrepository_test.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + "github.com/golang/mock/gomock" + "github.com/jfrog/frogbot/commands/testdata" "github.com/jfrog/frogbot/commands/utils" "github.com/jfrog/frogbot/commands/utils/outputwriter" "github.com/jfrog/froggit-go/vcsclient" @@ -245,7 +247,7 @@ pr body }, RepoName: test.testName, } // Set up mock VCS responses - client := utils.CreateMockVcsClient(t) + client := CreateMockVcsClient(t) client.EXPECT().ListOpenPullRequestsWithBody(context.Background(), "", gitTestParams.RepoName).Return(test.mockPullRequestResponse, nil) if test.expectedUpdate { client.EXPECT().UpdatePullRequest(context.Background(), "", gitTestParams.RepoName, outputwriter.GetAggregatedPullRequestTitle(coreutils.Npm), "", "", int(mockPrId), vcsutils.Open).Return(nil) @@ -686,3 +688,7 @@ func verifyDependencyFileDiff(baseBranch string, fixBranch string, packageDescri } return } + +func CreateMockVcsClient(t *testing.T) *testdata.MockVcsClient { + return testdata.NewMockVcsClient(gomock.NewController(t)) +} diff --git a/commands/utils/testsutils.go b/commands/utils/testsutils.go index 15b55f8a9..e4c8045b9 100644 --- a/commands/utils/testsutils.go +++ b/commands/utils/testsutils.go @@ -2,8 +2,6 @@ package utils import ( "fmt" - "github.com/golang/mock/gomock" - "github.com/jfrog/frogbot/commands/testdata" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-client-go/utils/io/fileutils" "os" @@ -92,8 +90,3 @@ func VerifyEnv(t *testing.T) (server config.ServerDetails, restoreFunc func()) { } return } - -func CreateMockVcsClient(t *testing.T) *testdata.MockVcsClient { - mockCtrl := gomock.NewController(t) - return testdata.NewMockVcsClient(mockCtrl) -} diff --git a/go.mod b/go.mod index 68d6db909..155c92f16 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.7 github.com/xeipuuv/gojsonschema v1.2.0 - golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b + golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index f98a7c917..5f983c288 100644 --- a/go.sum +++ b/go.sum @@ -1116,8 +1116,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI= -golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U= +golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=