Skip to content

Commit

Permalink
Fixed the path of the generated mock files.
Browse files Browse the repository at this point in the history
Signed-off-by: naveensrinivasan <[email protected]>
  • Loading branch information
naveensrinivasan committed Mar 11, 2022
1 parent 1995bc3 commit 7d17953
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ cron/data/metadata.pb.go: cron/data/metadata.proto | $(PROTOC)
protoc --go_out=../../../ cron/data/metadata.proto

generate-mocks: ## Compiles and generates all mocks using mockgen.
generate-mocks: clients/mockclients/repo_client.go clients/mockclients/repo.go clients/mockclients/cii_client.go checks/mockclients/vulnerabilities.go checks/mockclients/packagemanager.go
generate-mocks: clients/mockclients/repo_client.go clients/mockclients/repo.go clients/mockclients/cii_client.go checks/mockclients/vulnerabilities.go cmd/packagemanager_mockclient.go
clients/mockclients/repo_client.go: clients/repo_client.go
# Generating MockRepoClient
$(MOCKGEN) -source=clients/repo_client.go -destination=clients/mockclients/repo_client.go -package=mockrepo -copyright_file=clients/mockclients/license.txt
Expand All @@ -123,9 +123,9 @@ clients/mockclients/cii_client.go: clients/cii_client.go
checks/mockclients/vulnerabilities.go: clients/vulnerabilities.go
# Generating MockCIIClient
$(MOCKGEN) -source=clients/vulnerabilities.go -destination=clients/mockclients/vulnerabilities.go -package=mockrepo -copyright_file=clients/mockclients/license.txt
checks/mockclients/packagemanager.go: cmd/packagemanager_client.go
cmd/packagemanager_mockclient.go: cmd/packagemanager_client.go
# Generating MockPackageManagerClient
$(MOCKGEN) -source=cmd/packagemanager_client.go -destination=clients/mockclients/packagemanager.go -package=mockrepo -copyright_file=clients/mockclients/license.txt
$(MOCKGEN) -source=cmd/packagemanager_client.go -destination=cmd/packagemanager_mockclient.go -package=cmd -copyright_file=clients/mockclients/license.txt
generate-docs: ## Generates docs
generate-docs: validate-docs docs/checks.md
docs/checks.md: docs/checks/internal/checks.yaml docs/checks/internal/*.go docs/checks/internal/generate/*.go
Expand Down
8 changes: 3 additions & 5 deletions cmd/package_managers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"testing"

"github.com/golang/mock/gomock"

mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
)

func Test_fetchGitRepositoryFromNPM(t *testing.T) {
Expand Down Expand Up @@ -135,7 +133,7 @@ func Test_fetchGitRepositoryFromNPM(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
p := mockrepo.NewMockpackageManagerClient(ctrl)
p := NewMockpackageManagerClient(ctrl)
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
DoAndReturn(func(url, packageName string) (*http.Response, error) {
if tt.wantErr && tt.args.result == "" {
Expand Down Expand Up @@ -415,7 +413,7 @@ func Test_fetchGitRepositoryFromPYPI(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
p := mockrepo.NewMockpackageManagerClient(ctrl)
p := NewMockpackageManagerClient(ctrl)
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
DoAndReturn(func(url, packageName string) (*http.Response, error) {
if tt.wantErr && tt.args.result == "" {
Expand Down Expand Up @@ -684,7 +682,7 @@ func Test_fetchGitRepositoryFromRubyGems(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
p := mockrepo.NewMockpackageManagerClient(ctrl)
p := NewMockpackageManagerClient(ctrl)
p.EXPECT().Get(gomock.Any(), tt.args.packageName).
DoAndReturn(func(url, packageName string) (*http.Response, error) {
if tt.wantErr && tt.args.result == "" {
Expand Down
14 changes: 14 additions & 0 deletions cmd/packagemanager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,23 @@
package cmd

import (
"fmt"
"net/http"
"time"
)

type packageManagerClient interface {
Get(URI string, packagename string) (*http.Response, error)
}

type packageManager struct{}

// nolint: noctx
func (c *packageManager) Get(url, packageName string) (*http.Response, error) {
const timeout = 10
client := &http.Client{
Timeout: timeout * time.Second,
}
//nolint
return client.Get(fmt.Sprintf(url, packageName))
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
"context"
"fmt"
"log"
"net/http"
"os"
"sort"
"strings"
"time"

"github.com/spf13/cobra"
"sigs.k8s.io/release-utils/version"
Expand Down Expand Up @@ -73,18 +71,6 @@ func New(o *options.Options) *cobra.Command {
return cmd
}

type packageManager struct{}

// nolint: noctx
func (c *packageManager) Get(url, packageName string) (*http.Response, error) {
const timeout = 10
client := &http.Client{
Timeout: timeout * time.Second,
}
//nolint
return client.Get(fmt.Sprintf(url, packageName))
}

// rootCmd runs scorecard checks given a set of arguments.
func rootCmd(o *options.Options) {
p := &packageManager{}
Expand Down

0 comments on commit 7d17953

Please sign in to comment.