mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
Fixed the path of the generated mock files.
Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
This commit is contained in:
parent
1995bc3b9c
commit
7d1795384c
6
Makefile
6
Makefile
@ -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
|
||||
@ -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
|
||||
|
@ -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) {
|
||||
@ -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 == "" {
|
||||
@ -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 == "" {
|
||||
@ -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 == "" {
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: cmd/packagemanager_client.go
|
||||
|
||||
// Package mockrepo is a generated GoMock package.
|
||||
package mockrepo
|
||||
// Package cmd is a generated GoMock package.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
http "net/http"
|
14
cmd/root.go
14
cmd/root.go
@ -19,11 +19,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/release-utils/version"
|
||||
@ -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{}
|
||||
|
Loading…
Reference in New Issue
Block a user