mock

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigQueryMock

type BigQueryMock struct {
	// CreateTableFunc mocks the CreateTable method.
	CreateTableFunc func(ctx context.Context, table types.BQTableID, md *bigquery.TableMetadata) error

	// GetMetadataFunc mocks the GetMetadata method.
	GetMetadataFunc func(ctx context.Context, table types.BQTableID) (*bigquery.TableMetadata, error)

	// InsertFunc mocks the Insert method.
	InsertFunc func(ctx context.Context, tableID types.BQTableID, schema bigquery.Schema, data any) error

	// UpdateTableFunc mocks the UpdateTable method.
	UpdateTableFunc func(ctx context.Context, table types.BQTableID, md bigquery.TableMetadataToUpdate, eTag string) error
	// contains filtered or unexported fields
}

BigQueryMock is a mock implementation of interfaces.BigQuery.

func TestSomethingThatUsesBigQuery(t *testing.T) {

	// make and configure a mocked interfaces.BigQuery
	mockedBigQuery := &BigQueryMock{
		CreateTableFunc: func(ctx context.Context, table types.BQTableID, md *bigquery.TableMetadata) error {
			panic("mock out the CreateTable method")
		},
		GetMetadataFunc: func(ctx context.Context, table types.BQTableID) (*bigquery.TableMetadata, error) {
			panic("mock out the GetMetadata method")
		},
		InsertFunc: func(ctx context.Context, tableID types.BQTableID, schema bigquery.Schema, data any) error {
			panic("mock out the Insert method")
		},
		UpdateTableFunc: func(ctx context.Context, table types.BQTableID, md bigquery.TableMetadataToUpdate, eTag string) error {
			panic("mock out the UpdateTable method")
		},
	}

	// use mockedBigQuery in code that requires interfaces.BigQuery
	// and then make assertions.

}

func (*BigQueryMock) CreateTable

func (mock *BigQueryMock) CreateTable(ctx context.Context, table types.BQTableID, md *bigquery.TableMetadata) error

CreateTable calls CreateTableFunc.

func (*BigQueryMock) CreateTableCalls

func (mock *BigQueryMock) CreateTableCalls() []struct {
	Ctx   context.Context
	Table types.BQTableID
	Md    *bigquery.TableMetadata
}

CreateTableCalls gets all the calls that were made to CreateTable. Check the length with:

len(mockedBigQuery.CreateTableCalls())

func (*BigQueryMock) GetMetadata

func (mock *BigQueryMock) GetMetadata(ctx context.Context, table types.BQTableID) (*bigquery.TableMetadata, error)

GetMetadata calls GetMetadataFunc.

func (*BigQueryMock) GetMetadataCalls

func (mock *BigQueryMock) GetMetadataCalls() []struct {
	Ctx   context.Context
	Table types.BQTableID
}

GetMetadataCalls gets all the calls that were made to GetMetadata. Check the length with:

len(mockedBigQuery.GetMetadataCalls())

func (*BigQueryMock) Insert

func (mock *BigQueryMock) Insert(ctx context.Context, tableID types.BQTableID, schema bigquery.Schema, data any) error

Insert calls InsertFunc.

func (*BigQueryMock) InsertCalls

func (mock *BigQueryMock) InsertCalls() []struct {
	Ctx     context.Context
	TableID types.BQTableID
	Schema  bigquery.Schema
	Data    any
}

InsertCalls gets all the calls that were made to Insert. Check the length with:

len(mockedBigQuery.InsertCalls())

func (*BigQueryMock) UpdateTable

func (mock *BigQueryMock) UpdateTable(ctx context.Context, table types.BQTableID, md bigquery.TableMetadataToUpdate, eTag string) error

UpdateTable calls UpdateTableFunc.

func (*BigQueryMock) UpdateTableCalls

func (mock *BigQueryMock) UpdateTableCalls() []struct {
	Ctx   context.Context
	Table types.BQTableID
	Md    bigquery.TableMetadataToUpdate
	ETag  string
}

UpdateTableCalls gets all the calls that were made to UpdateTable. Check the length with:

len(mockedBigQuery.UpdateTableCalls())

type GitHubMock

type GitHubMock struct {
	// CreateCheckRunFunc mocks the CreateCheckRun method.
	CreateCheckRunFunc func(ctx context.Context, id types.GitHubAppInstallID, repo *model.GitHubRepo, commit string) (int64, error)

	// CreateIssueCommentFunc mocks the CreateIssueComment method.
	CreateIssueCommentFunc func(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, prID int, body string) error

	// GetArchiveURLFunc mocks the GetArchiveURL method.
	GetArchiveURLFunc func(ctx context.Context, input *interfaces.GetArchiveURLInput) (*url.URL, error)

	// ListIssueCommentsFunc mocks the ListIssueComments method.
	ListIssueCommentsFunc func(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, prID int) ([]*model.GitHubIssueComment, error)

	// MinimizeCommentFunc mocks the MinimizeComment method.
	MinimizeCommentFunc func(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, subjectID string) error

	// UpdateCheckRunFunc mocks the UpdateCheckRun method.
	UpdateCheckRunFunc func(ctx context.Context, id types.GitHubAppInstallID, repo *model.GitHubRepo, checkID int64, opt *github.UpdateCheckRunOptions) error
	// contains filtered or unexported fields
}

GitHubMock is a mock implementation of interfaces.GitHub.

func TestSomethingThatUsesGitHub(t *testing.T) {

	// make and configure a mocked interfaces.GitHub
	mockedGitHub := &GitHubMock{
		CreateCheckRunFunc: func(ctx context.Context, id types.GitHubAppInstallID, repo *model.GitHubRepo, commit string) (int64, error) {
			panic("mock out the CreateCheckRun method")
		},
		CreateIssueCommentFunc: func(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, prID int, body string) error {
			panic("mock out the CreateIssueComment method")
		},
		GetArchiveURLFunc: func(ctx context.Context, input *interfaces.GetArchiveURLInput) (*url.URL, error) {
			panic("mock out the GetArchiveURL method")
		},
		ListIssueCommentsFunc: func(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, prID int) ([]*model.GitHubIssueComment, error) {
			panic("mock out the ListIssueComments method")
		},
		MinimizeCommentFunc: func(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, subjectID string) error {
			panic("mock out the MinimizeComment method")
		},
		UpdateCheckRunFunc: func(ctx context.Context, id types.GitHubAppInstallID, repo *model.GitHubRepo, checkID int64, opt *github.UpdateCheckRunOptions) error {
			panic("mock out the UpdateCheckRun method")
		},
	}

	// use mockedGitHub in code that requires interfaces.GitHub
	// and then make assertions.

}

func (*GitHubMock) CreateCheckRun

func (mock *GitHubMock) CreateCheckRun(ctx context.Context, id types.GitHubAppInstallID, repo *model.GitHubRepo, commit string) (int64, error)

CreateCheckRun calls CreateCheckRunFunc.

func (*GitHubMock) CreateCheckRunCalls

func (mock *GitHubMock) CreateCheckRunCalls() []struct {
	Ctx    context.Context
	ID     types.GitHubAppInstallID
	Repo   *model.GitHubRepo
	Commit string
}

CreateCheckRunCalls gets all the calls that were made to CreateCheckRun. Check the length with:

len(mockedGitHub.CreateCheckRunCalls())

func (*GitHubMock) CreateIssueComment

func (mock *GitHubMock) CreateIssueComment(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, prID int, body string) error

CreateIssueComment calls CreateIssueCommentFunc.

func (*GitHubMock) CreateIssueCommentCalls

func (mock *GitHubMock) CreateIssueCommentCalls() []struct {
	Ctx  context.Context
	Repo *model.GitHubRepo
	ID   types.GitHubAppInstallID
	PrID int
	Body string
}

CreateIssueCommentCalls gets all the calls that were made to CreateIssueComment. Check the length with:

len(mockedGitHub.CreateIssueCommentCalls())

func (*GitHubMock) GetArchiveURL

func (mock *GitHubMock) GetArchiveURL(ctx context.Context, input *interfaces.GetArchiveURLInput) (*url.URL, error)

GetArchiveURL calls GetArchiveURLFunc.

func (*GitHubMock) GetArchiveURLCalls

func (mock *GitHubMock) GetArchiveURLCalls() []struct {
	Ctx   context.Context
	Input *interfaces.GetArchiveURLInput
}

GetArchiveURLCalls gets all the calls that were made to GetArchiveURL. Check the length with:

len(mockedGitHub.GetArchiveURLCalls())

func (*GitHubMock) ListIssueComments

func (mock *GitHubMock) ListIssueComments(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, prID int) ([]*model.GitHubIssueComment, error)

ListIssueComments calls ListIssueCommentsFunc.

func (*GitHubMock) ListIssueCommentsCalls

func (mock *GitHubMock) ListIssueCommentsCalls() []struct {
	Ctx  context.Context
	Repo *model.GitHubRepo
	ID   types.GitHubAppInstallID
	PrID int
}

ListIssueCommentsCalls gets all the calls that were made to ListIssueComments. Check the length with:

len(mockedGitHub.ListIssueCommentsCalls())

func (*GitHubMock) MinimizeComment

func (mock *GitHubMock) MinimizeComment(ctx context.Context, repo *model.GitHubRepo, id types.GitHubAppInstallID, subjectID string) error

MinimizeComment calls MinimizeCommentFunc.

func (*GitHubMock) MinimizeCommentCalls

func (mock *GitHubMock) MinimizeCommentCalls() []struct {
	Ctx       context.Context
	Repo      *model.GitHubRepo
	ID        types.GitHubAppInstallID
	SubjectID string
}

MinimizeCommentCalls gets all the calls that were made to MinimizeComment. Check the length with:

len(mockedGitHub.MinimizeCommentCalls())

func (*GitHubMock) UpdateCheckRun

func (mock *GitHubMock) UpdateCheckRun(ctx context.Context, id types.GitHubAppInstallID, repo *model.GitHubRepo, checkID int64, opt *github.UpdateCheckRunOptions) error

UpdateCheckRun calls UpdateCheckRunFunc.

func (*GitHubMock) UpdateCheckRunCalls

func (mock *GitHubMock) UpdateCheckRunCalls() []struct {
	Ctx     context.Context
	ID      types.GitHubAppInstallID
	Repo    *model.GitHubRepo
	CheckID int64
	Opt     *github.UpdateCheckRunOptions
}

UpdateCheckRunCalls gets all the calls that were made to UpdateCheckRun. Check the length with:

len(mockedGitHub.UpdateCheckRunCalls())

type StorageMock

type StorageMock struct {
	Data map[string][]byte
}

func NewStorageMock

func NewStorageMock() *StorageMock

func (*StorageMock) Get

func (s *StorageMock) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get implements Storage.

func (*StorageMock) Put

func (s *StorageMock) Put(ctx context.Context, key string, r io.ReadCloser) error

Put implements Storage.

func (*StorageMock) Unmarshal

func (s *StorageMock) Unmarshal(key string, v interface{}) error

type UseCaseMock

type UseCaseMock struct {
	// InsertScanResultFunc mocks the InsertScanResult method.
	InsertScanResultFunc func(ctx context.Context, meta model.GitHubMetadata, report trivy.Report, cfg model.Config) error

	// ScanGitHubRepoFunc mocks the ScanGitHubRepo method.
	ScanGitHubRepoFunc func(ctx context.Context, input *model.ScanGitHubRepoInput) error
	// contains filtered or unexported fields
}

UseCaseMock is a mock implementation of interfaces.UseCase.

func TestSomethingThatUsesUseCase(t *testing.T) {

	// make and configure a mocked interfaces.UseCase
	mockedUseCase := &UseCaseMock{
		InsertScanResultFunc: func(ctx context.Context, meta model.GitHubMetadata, report trivy.Report, cfg model.Config) error {
			panic("mock out the InsertScanResult method")
		},
		ScanGitHubRepoFunc: func(ctx context.Context, input *model.ScanGitHubRepoInput) error {
			panic("mock out the ScanGitHubRepo method")
		},
	}

	// use mockedUseCase in code that requires interfaces.UseCase
	// and then make assertions.

}

func (*UseCaseMock) InsertScanResult

func (mock *UseCaseMock) InsertScanResult(ctx context.Context, meta model.GitHubMetadata, report trivy.Report, cfg model.Config) error

InsertScanResult calls InsertScanResultFunc.

func (*UseCaseMock) InsertScanResultCalls

func (mock *UseCaseMock) InsertScanResultCalls() []struct {
	Ctx    context.Context
	Meta   model.GitHubMetadata
	Report trivy.Report
	Cfg    model.Config
}

InsertScanResultCalls gets all the calls that were made to InsertScanResult. Check the length with:

len(mockedUseCase.InsertScanResultCalls())

func (*UseCaseMock) ScanGitHubRepo

func (mock *UseCaseMock) ScanGitHubRepo(ctx context.Context, input *model.ScanGitHubRepoInput) error

ScanGitHubRepo calls ScanGitHubRepoFunc.

func (*UseCaseMock) ScanGitHubRepoCalls

func (mock *UseCaseMock) ScanGitHubRepoCalls() []struct {
	Ctx   context.Context
	Input *model.ScanGitHubRepoInput
}

ScanGitHubRepoCalls gets all the calls that were made to ScanGitHubRepo. Check the length with:

len(mockedUseCase.ScanGitHubRepoCalls())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL