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

Fix mock import #429

Merged
merged 1 commit into from
Aug 9, 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
4 changes: 0 additions & 4 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 10 additions & 6 deletions commands/scanpullrequest/scanallpullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)},
Expand All @@ -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)},
Expand All @@ -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)},
Expand All @@ -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)
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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))
}
8 changes: 4 additions & 4 deletions commands/scanpullrequest/scanpullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 7 additions & 1 deletion commands/scanrepository/scanrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
7 changes: 0 additions & 7 deletions commands/utils/testsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down