testapi

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Dstore              = mockdatastore.DataStorer{}
	DstoreNotFound      = mockdatastore.DataStorer{NotFound: true}
	DstoreInternalError = mockdatastore.DataStorer{InternalError: true}
)

List of mocked datastores returning different results

Functions

func CreateRequestWithAuth

func CreateRequestWithAuth(method, URL string, body io.Reader) (*http.Request, error)

CreateRequestWithAuth adds authentication to request

func CreateRequestWithOutAuth

func CreateRequestWithOutAuth(method, URL string, body io.Reader) (*http.Request, error)

CreateRequestWithOutAuth builds request without authentication

Types

type JobServiceMock

type JobServiceMock struct {
	// CreateJobFunc mocks the CreateJob method.
	CreateJobFunc func(ctx context.Context, job *models.Job) (*models.Job, error)

	// UpdateJobFunc mocks the UpdateJob method.
	UpdateJobFunc func(ctx context.Context, jobID string, job *models.Job) error
	// contains filtered or unexported fields
}

JobServiceMock is a mock implementation of api.JobService.

    func TestSomethingThatUsesJobService(t *testing.T) {

        // make and configure a mocked api.JobService
        mockedJobService := &JobServiceMock{
            CreateJobFunc: func(ctx context.Context, job *models.Job) (*models.Job, error) {
	               panic("mock out the CreateJob method")
            },
            UpdateJobFunc: func(ctx context.Context, jobID string, job *models.Job) error {
	               panic("mock out the UpdateJob method")
            },
        }

        // use mockedJobService in code that requires api.JobService
        // and then make assertions.

    }

func (*JobServiceMock) CreateJob

func (mock *JobServiceMock) CreateJob(ctx context.Context, job *models.Job) (*models.Job, error)

CreateJob calls CreateJobFunc.

func (*JobServiceMock) CreateJobCalls

func (mock *JobServiceMock) CreateJobCalls() []struct {
	Ctx context.Context
	Job *models.Job
}

CreateJobCalls gets all the calls that were made to CreateJob. Check the length with:

len(mockedJobService.CreateJobCalls())

func (*JobServiceMock) UpdateJob

func (mock *JobServiceMock) UpdateJob(ctx context.Context, jobID string, job *models.Job) error

UpdateJob calls UpdateJobFunc.

func (*JobServiceMock) UpdateJobCalls

func (mock *JobServiceMock) UpdateJobCalls() []struct {
	Ctx   context.Context
	JobID string
	Job   *models.Job
}

UpdateJobCalls gets all the calls that were made to UpdateJob. Check the length with:

len(mockedJobService.UpdateJobCalls())

Jump to

Keyboard shortcuts

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