test

package
v0.0.0-...-a196a74 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SentByPrCreator = func(pullRequest *gogh.PullRequest) *gogh.User {
	return pullRequest.User
}

SentByPrCreator creates a user that is stored as a creator of the mocked PR

View Source
var SentByRepoOwner = func(pullRequest *gogh.PullRequest) *gogh.User {
	return pullRequest.Base.Repo.Owner
}

SentByRepoOwner creates a user that is stored as a owner of the mocked PR's repository

View Source
var SentByReviewer = func(pullRequest *gogh.PullRequest) *gogh.User {
	return pullRequest.RequestedReviewers[0]
}

SentByReviewer creates a user that is stored at the first place in the list of requested reviewers of the mocked PR

View Source
var (
	// ToBe as a wrapper for a status matcher
	ToBe = func(status, description, detailsLink string) BuilderMatcher {
		return func(builder *MockPrBuilder) SoftMatcher {
			docStatusRoot := fmt.Sprintf("%s/status/%s", plugin.DocumentationURL, builder.pluginName)

			return SoftlySatisfyAll(
				HaveState(status),
				HaveDescription(description),
				HaveContext(strings.Join([]string{"alien-ike", builder.pluginName}, "/")),
				HaveTargetURL(fmt.Sprintf("%s/%s/%s.html", docStatusRoot, strings.ToLower(status), detailsLink)),
			)
		}
	}
)

Functions

func Admin

func Admin(name string) func(pr *gogh.PullRequest) *GhUser

Admin creates an instance of GhUser with read admin

func ConfigYaml

func ConfigYaml(content string) func(builder *MockPrBuilder)

ConfigYaml creates a representation of a config file with yaml suffix

func ConfigYml

func ConfigYml(content string) func(builder *MockPrBuilder)

ConfigYml creates a representation of a config file with yml suffix

func Containing

func Containing(params ...KeyValue) string

Containing creates a json content of a config file from the given params

func EnsureGockRequestsHaveBeenMatched

func EnsureGockRequestsHaveBeenMatched()

EnsureGockRequestsHaveBeenMatched checks if all requests have been matched in the test

func ExpectPayload

func ExpectPayload(matchers ...SoftMatcher) gock.Matcher

ExpectPayload creates a gock.Matcher with the given SoftMatchers that asserts a retrieved payload

func ExternalUser

func ExternalUser(name string) func(pr *gogh.PullRequest) *GhUser

ExternalUser creates an instance of GhUser with read permission

func FromFile

func FromFile(filePath string) io.Reader

nolint

func LoadFromFile

func LoadFromFile(filePath string) []byte

nolint

func LoadIssueCommentEvent

func LoadIssueCommentEvent(filePath string) *gogh.IssueCommentEvent

LoadIssueCommentEvent creates an instance of gogh.PullRequestEvent with the given values

func LoadPullRequestEvent

func LoadPullRequestEvent(filePath string) *gogh.PullRequestEvent

LoadPullRequestEvent creates an instance of gogh.PullRequestEvent with the given values

func LoadedFrom

func LoadedFrom(filePath string) string

nolint

func NewDefaultGitHubClient

func NewDefaultGitHubClient() ghclient.Client

NewDefaultGitHubClient creates a GH client with default go-github client (without any authentication token)

func NewPullRequest

func NewPullRequest(repoOwner, repoName, sha, creator string) *gogh.PullRequest

NewPullRequest creates an instance of gogh.PullRequest with the given values

func NonExistingRawGitHubFiles

func NonExistingRawGitHubFiles(pathSuffixes ...string)

NonExistingRawGitHubFiles mocks any matching path suffix when calling "https://raw.githubusercontent.com" with 404 response

func PrCreator

func PrCreator(name string) func(pr *gogh.PullRequest) *GhUser

PrCreator creates an instance of GhUser with the given name and the name sets as PR's creator login

func RequestedReviewer

func RequestedReviewer(name string) func(pr *gogh.PullRequest) *GhUser

RequestedReviewer creates an instance of GhUser with the given name and appends the user to the list of PR's reviewers

func SpyOnCalls

func SpyOnCalls(counter *int) gock.Matcher

SpyOnCalls checks the number of calls

Types

type BuilderMatcher

type BuilderMatcher func(builder *MockPrBuilder) SoftMatcher

BuilderMatcher creates a SoftMatcher for the given builder

func ContainingStatusMessage

func ContainingStatusMessage(description string) BuilderMatcher

ContainingStatusMessage verifies that the comment should contain status message with the given description

func To

func To(matchers ...SoftMatcher) BuilderMatcher

To softly satisfies all the given matchers and creates a BuilderMatcher from it

type GhUser

type GhUser struct {
	// contains filtered or unexported fields
}

GhUser keeps name and user's permission

type GhUserCreator

type GhUserCreator func(pullRequest *gogh.PullRequest) *GhUser

GhUserCreator creates an instance of GhUser

type KeyValue

type KeyValue func() (string, string)

KeyValue is a function returning key and value

func Param

func Param(key, value string) KeyValue

Param represents a key-value pair

type MockCreator

type MockCreator func(builder *MockPrBuilder)

MockCreator creates a gock mock

func AddedLabel

func AddedLabel(labelContent string) MockCreator

AddedLabel creates a gock matcher to check that there is a Post request for the given label sent

func ChangedComment

func ChangedComment(commendID int, matherForPlugin BuilderMatcher) MockCreator

ChangedComment creates a gock matcher to check that there is a Patch request for the given comment id and containing a comment that complies with the given restrictions

func ChangedTitle

func ChangedTitle(newTitleContent string) MockCreator

ChangedTitle creates a gock matcher to check that there is a Patch request containing a new changed title

func Comment

func Comment(matherForPlugin BuilderMatcher) MockCreator

Comment creates a gock matcher to check that there is a Post with a comment that complies with the given restrictions

func NoComment

func NoComment() MockCreator

NoComment creates a gock matcher to check that there is no Post comment request sent

func NoStatus

func NoStatus() MockCreator

NoStatus creates a gock matcher to check that there is no Post status request sent

func RemovedLabel

func RemovedLabel(labelName, response string) MockCreator

RemovedLabel creates a gock matcher to check that there is a Delete request for the given label sent

func Status

func Status(matherForPlugin BuilderMatcher) MockCreator

Status creates a gock matcher to check that there is a Post with a status that complies with the given restrictions

type MockPluginTemplate

type MockPluginTemplate struct {
	// contains filtered or unexported fields
}

MockPluginTemplate keeps plugin name information

func NewMockPluginTemplate

func NewMockPluginTemplate(pluginName string) MockPluginTemplate

NewMockPluginTemplate creates an instance of MockPluginTemplate

func (MockPluginTemplate) AddConfig

func (t MockPluginTemplate) AddConfig(configMock func(builder *MockPrBuilder)) *SubMockBuilder

AddConfig creates an instance of SubMockBuilder for the given configuration

func (MockPluginTemplate) MockPr

MockPr creates a builder for mocking a pull request calls

type MockPrBuilder

type MockPrBuilder struct {
	// contains filtered or unexported fields
}

MockPrBuilder keeps information about pr, plugin and all mock creators to be initialized

func (*MockPrBuilder) Create

func (b *MockPrBuilder) Create() *PrMock

Create initializes the gock mocks based on the predefined information

func (*MockPrBuilder) Expecting

func (b *MockPrBuilder) Expecting(mockCreators ...MockCreator) *MockPrBuilder

Expecting creates mocks for the given matchers

func (*MockPrBuilder) WithComments

func (b *MockPrBuilder) WithComments(jsonContent string, options ...RequestOption) *MockPrBuilder

WithComments sets the given payload containing comments to the mocked PR

func (*MockPrBuilder) WithConfigFile

func (b *MockPrBuilder) WithConfigFile(configMock func(builder *MockPrBuilder)) *MockPrBuilder

WithConfigFile sets that the associated mocked PR should contain the given configuration file

func (*MockPrBuilder) WithDescription

func (b *MockPrBuilder) WithDescription(body string) *MockPrBuilder

WithDescription sets the given description to the mocked pull request

func (*MockPrBuilder) WithFiles

func (b *MockPrBuilder) WithFiles(jsonContent string, options ...RequestOption) *MockPrBuilder

WithFiles sets the given payload containing changed files to the mocked PR

func (*MockPrBuilder) WithLabels

func (b *MockPrBuilder) WithLabels(labelNames ...string) *MockPrBuilder

WithLabels sets the given payload containing list of labels to the mocked PR

func (*MockPrBuilder) WithRawFile

func (b *MockPrBuilder) WithRawFile(fileName, content string) *MockPrBuilder

WithRawFile sets that the associated mocked PR should contain the given files

func (*MockPrBuilder) WithReviews

func (b *MockPrBuilder) WithReviews(jsonContent string, options ...RequestOption) *MockPrBuilder

WithReviews sets the given payload containing list of reviews to the mocked PR

func (*MockPrBuilder) WithSize

func (b *MockPrBuilder) WithSize(size int) *MockPrBuilder

WithSize sets the given size to the mocked pull request changed files

func (*MockPrBuilder) WithTitle

func (b *MockPrBuilder) WithTitle(title string) *MockPrBuilder

WithTitle sets the given title to the mocked pull request

func (*MockPrBuilder) WithUsers

func (b *MockPrBuilder) WithUsers(userCreators ...GhUserCreator) *MockPrBuilder

WithUsers sets the users to be mock as part of the MockPrBuilder

func (*MockPrBuilder) WithoutComments

func (b *MockPrBuilder) WithoutComments(options ...RequestOption) *MockPrBuilder

WithoutComments sets an empty array as a payload representing pr/issue comments

func (*MockPrBuilder) WithoutConfigFiles

func (b *MockPrBuilder) WithoutConfigFiles() *MockPrBuilder

WithoutConfigFiles sets that the associated mocked PR shouldn't contain any configuration file for the before-set plugin

func (*MockPrBuilder) WithoutConfigFilesForPlugin

func (b *MockPrBuilder) WithoutConfigFilesForPlugin(pluginName string) *MockPrBuilder

WithoutConfigFilesForPlugin sets that the associated mocked PR shouldn't contain any configuration file for the given plugin

func (*MockPrBuilder) WithoutFiles

func (b *MockPrBuilder) WithoutFiles(options ...RequestOption) *MockPrBuilder

WithoutFiles sets an empty array as a payload representing changed files

func (*MockPrBuilder) WithoutLabels

func (b *MockPrBuilder) WithoutLabels() *MockPrBuilder

WithoutLabels sets an empty array as a payload representing pr/issue labels

func (*MockPrBuilder) WithoutMessageFiles

func (b *MockPrBuilder) WithoutMessageFiles(fileNames ...string) *MockPrBuilder

WithoutMessageFiles sets that the associated mocked PR shouldn't contain status messages with the given names

func (*MockPrBuilder) WithoutRawFiles

func (b *MockPrBuilder) WithoutRawFiles(fileNames ...string) *MockPrBuilder

WithoutRawFiles sets that the associated mocked PR should not contain the given files

func (*MockPrBuilder) WithoutReviews

func (b *MockPrBuilder) WithoutReviews(options ...RequestOption) *MockPrBuilder

WithoutReviews sets an empty array as a payload representing pr reviews

type MockPrBuilderLoader

type MockPrBuilderLoader struct {
	// contains filtered or unexported fields
}

MockPrBuilderLoader is an endpoint used for loading a PR

func MockPr

func MockPr() *MockPrBuilderLoader

MockPr creates a builder for mocking a pull request calls

func (*MockPrBuilderLoader) LoadedFrom

func (l *MockPrBuilderLoader) LoadedFrom(jsonPath string) *MockPrBuilder

LoadedFrom loads json content representing a PR from the given place

func (*MockPrBuilderLoader) LoadedFromDefaultJSON

func (l *MockPrBuilderLoader) LoadedFromDefaultJSON() *MockPrBuilder

LoadedFromDefaultJSON loads json from a location test_fixtures/github_calls/prs/pr_details.json

func (*MockPrBuilderLoader) LoadedFromDefaultStruct

func (l *MockPrBuilderLoader) LoadedFromDefaultStruct() *MockPrBuilder

LoadedFromDefaultStruct loads a marshaled instance of default pull request

type NamedGomegaMatcher

type NamedGomegaMatcher struct {
	types.GomegaMatcher
	ElementName string
}

NamedGomegaMatcher keeps a GomegaMatcher instance along with an element name the matchers matches

type PermissionServiceMocker

type PermissionServiceMocker struct {
	// contains filtered or unexported fields
}

PermissionServiceMocker keeps user name and pr used for mocking user permissions

func (*PermissionServiceMocker) ThatIs

ThatIs is just a semantic sugar providing a opportunity to evaluate particular role on the mocked user permission

type PrMock

type PrMock struct {
	PullRequest *gogh.PullRequest
}

PrMock keeps the mocked pull request

func (*PrMock) CreateCommentEvent

func (pr *PrMock) CreateCommentEvent(userCreator SenderCreator, content, action string) *gogh.IssueCommentEvent

CreateCommentEvent based on the mocked PR information creates an IssueCommentEvent

func (*PrMock) CreatePullRequestEvent

func (pr *PrMock) CreatePullRequestEvent(action string) *gogh.PullRequestEvent

CreatePullRequestEvent based on the mocked PR information creates a PullRequestEvent

func (*PrMock) PermissionForUser

func (pr *PrMock) PermissionForUser(userName string) *PermissionServiceMocker

PermissionForUser based on the mocked PR information creates an instance of PermissionService

type RequestOption

type RequestOption = func(request *gock.Request)

RequestOption add a option to a associated request

type SenderCreator

type SenderCreator func(pullRequest *gogh.PullRequest) *gogh.User

SenderCreator creates a gogh.User

func SentBy

func SentBy(name string) SenderCreator

SentBy creates a user with the given name

type SoftAssertion

type SoftAssertion struct {
	// contains filtered or unexported fields
}

SoftAssertion wraps GomegaAssertion instance

func ExpectPermissionStatus

func ExpectPermissionStatus(status *command.PermissionStatus) *SoftAssertion

ExpectPermissionStatus wraps the given PermissionStatus allowing assertions to be made on it

func NewSoftAssertion

func NewSoftAssertion(assertion gomega.GomegaAssertion) *SoftAssertion

NewSoftAssertion creates a new instance of SoftAssertion with the given GomegaAssertion

func (*SoftAssertion) NotTo

func (m *SoftAssertion) NotTo(matchers ...SoftMatcher) bool

NotTo expects that none of the given matchers should pass

func (*SoftAssertion) To

func (m *SoftAssertion) To(matchers ...SoftMatcher) bool

To expects that all of the given matchers should pass

type SoftMatcher

type SoftMatcher interface {
	types.GomegaMatcher
	// contains filtered or unexported methods
}

SoftMatcher is a types.GomegaMatcher that can be used in SoftlySatisfyAll(...) matching

func HaveApprovedRoles

func HaveApprovedRoles(roles ...string) SoftMatcher

HaveApprovedRoles asserts if the PermissionStatus contains the given approved roles

func HaveApprovedUser

func HaveApprovedUser(expUserName string) SoftMatcher

HaveApprovedUser asserts if the PermissionStatus contains an approved user with the given name

func HaveBody

func HaveBody(expectedBody string) SoftMatcher

HaveBody gets "body" key from map[string]interface{} and compares its value with expectedBody This matcher is used to verify body content sent in request to GitHub API

func HaveBodyThatContains

func HaveBodyThatContains(content string) SoftMatcher

HaveBodyThatContains gets "body" key from map[string]interface{} or first element from []interface{} and checks if its value contains the given string. This matcher is used to verify body content sent in request to GitHub API

func HaveContext

func HaveContext(expectedContext string) SoftMatcher

HaveContext gets "context" key from map[string]interface{} and compares its value with expectedContext This matcher is used to verify status context sent to GitHub API

func HaveDescription

func HaveDescription(expectedReason string) SoftMatcher

HaveDescription gets "description" key from map[string]interface{} and compares its value with expectedReason This matcher is used to verify status description sent to GitHub API

func HaveNoApprovedRoles

func HaveNoApprovedRoles() SoftMatcher

HaveNoApprovedRoles asserts if the PermissionStatus doesn't contain any role that would be approved

func HaveNoRejectedRoles

func HaveNoRejectedRoles() SoftMatcher

HaveNoRejectedRoles asserts if the PermissionStatus doesn't contain any role that would be rejected

func HaveRejectedRoles

func HaveRejectedRoles(roles ...string) SoftMatcher

HaveRejectedRoles asserts if the PermissionStatus contains the given rejected roles

func HaveRejectedUser

func HaveRejectedUser(expUserName string) SoftMatcher

HaveRejectedUser asserts if the PermissionStatus contains a rejected user with the given name

func HaveState

func HaveState(expectedState string) SoftMatcher

HaveState gets "state" key from map[string]interface{} and compares its value with expectedState This matcher is used to verify status update sent to GitHub API

func HaveTargetURL

func HaveTargetURL(expectedTargetURL string) SoftMatcher

HaveTargetURL gets "target_url" key from map[string]interface{} and compares its value with expectedTargetURL This matcher is used to verify status target URL sent to GitHub API

func HaveTitle

func HaveTitle(expectedBody string) SoftMatcher

HaveTitle gets "title" key from map[string]interface{} and compares its value with expectedTitle This matcher is used to verify title content sent in request to GitHub API

func SoftlySatisfyAll

func SoftlySatisfyAll(matchers ...SoftMatcher) SoftMatcher

SoftlySatisfyAll succeeds only if all of the given matchers succeed. The matchers are tried in order, and all errors are collected instead of stopping at the first one.

func TransformWithName

func TransformWithName(transform interface{}, matcher types.GomegaMatcher, elementName string) SoftMatcher

TransformWithName creates a new instance of NamedGomegaMatcher with GomegaMatcher retrieved by transforming of the given transform and matcher values

type SoftlyAllMatcher

type SoftlyAllMatcher struct {
	Matchers []SoftMatcher
	// contains filtered or unexported fields
}

SoftlyAllMatcher as a GomegaMatcher implementation for soft assertions

func (*SoftlyAllMatcher) FailureMessage

func (m *SoftlyAllMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage creates a failure message

func (*SoftlyAllMatcher) Match

func (m *SoftlyAllMatcher) Match(actual interface{}) (success bool, err error)

Match matches all available matchers and divides them into two arrays based on the information if the match was successful or not

func (*SoftlyAllMatcher) NegatedFailureMessage

func (m *SoftlyAllMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage creates a negated failure message

type SubMockBuilder

type SubMockBuilder struct {
	// contains filtered or unexported fields
}

SubMockBuilder represents a builder to be used for mocking of a particular PR parameter

func (*SubMockBuilder) ToChange

func (b *SubMockBuilder) ToChange(change scm.RepositoryChange)

ToChange defines that the predefined information should be applicable for the given scm.RepositoryChange

Jump to

Keyboard shortcuts

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