Documentation
¶
Index ¶
- Constants
- Variables
- func AssertConditionsMatch(t T, actual []toolchainv1alpha1.Condition, ...)
- func AssertConditionsMatchAndRecentTimestamps(t T, actual []toolchainv1alpha1.Condition, ...)
- func AssertContainsCondition(t T, conditions []toolchainv1alpha1.Condition, ...)
- func AssertContainsMember(t T, members []toolchainv1alpha1.Member, contains toolchainv1alpha1.Member)
- func AssertHostOperatorStatusMatch(t T, actual toolchainv1alpha1.HostOperatorStatus, ...)
- func AssertMembersMatch(t T, actual []toolchainv1alpha1.Member, expected ...toolchainv1alpha1.Member)
- func AssertRegistrationServiceDeploymentStatusMatch(t T, actual toolchainv1alpha1.RegistrationServiceDeploymentStatus, ...)
- func AssertRegistrationServiceHealthStatusMatch(t T, actual toolchainv1alpha1.RegistrationServiceHealth, ...)
- func AssertRegistrationServiceResourcesStatusMatch(t T, actual toolchainv1alpha1.RegistrationServiceResourcesStatus, ...)
- func AssertRegistrationServiceRevisionMatch(t T, actual toolchainv1alpha1.RevisionCheck, ...)
- func AssertRegistrationServiceStatusMatch(t T, actual toolchainv1alpha1.HostRegistrationServiceStatus, ...)
- func AssertTimestampsAreRecent(t T, conditions []toolchainv1alpha1.Condition)
- func ConditionsMatch(actual []toolchainv1alpha1.Condition, expected ...toolchainv1alpha1.Condition) bool
- func ContainsCondition(conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition) bool
- func Create(ctx context.Context, cl *FakeClient, obj client.Object, ...) error
- func CreateSecret(name, namespace string, data map[string][]byte) *v1.Secret
- func CreateTemplate(innerObjects TemplateObjects, params TemplateParams) string
- func DecodeTemplate(decoder runtime.Decoder, tmplContent string) (*templatev1.Template, error)
- func MockGitHubClientForRepositoryCommits(githubCommitSHA string, commitTimestamp time.Time) client.GetGitHubClientFunc
- func MockGithubRepositoryCommit(repositoryCommit *github.RepositoryCommit) *http.Client
- func NamespacedName(namespace, name string) types.NamespacedName
- func NewClusterStatus(conType toolchainv1alpha1.ConditionType, conStatus corev1.ConditionStatus) toolchainv1alpha1.ToolchainClusterStatus
- func NewMockedGithubCommit(commitSHA string, commitTimestamp time.Time) *github.RepositoryCommit
- func NewRESTClient(token, apiEndpoint string) (*rest.RESTClient, error)
- func NewToolchainCluster(t *testing.T, name, tcNs, operatorNs, secName string, ...) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret)
- func NewToolchainClusterWithEndpoint(t *testing.T, name, tcNs, operatorNs, secName, apiEndpoint string, ...) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret)
- func SetEnvVarAndRestore(t *testing.T, key, newValue string) func()
- func SetEnvVarsAndRestore(t *testing.T, envs ...EnvVariable) func()
- func SetupGockForServiceAccounts(t *testing.T, apiEndpoint string, sas ...types.NamespacedName)
- func SetupGockWithCleanup(t *testing.T, apiEndpoint string, path string, body string, statusCode int) *gock.Response
- func UnsetEnvVarAndRestore(t *testing.T, key string) func()
- func Update(ctx context.Context, cl *FakeClient, obj client.Object, ...) error
- type EnvVariable
- type FakeClient
- func (c *FakeClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
- func (c *FakeClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
- func (c *FakeClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
- func (c *FakeClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (c *FakeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c *FakeClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, ...) error
- func (c *FakeClient) Status() client.StatusWriter
- func (c *FakeClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
- type MockT
- func (t *MockT) CalledErrorf() bool
- func (t *MockT) CalledFailNow() bool
- func (t *MockT) CalledFatalf() bool
- func (t *MockT) CalledLogf() bool
- func (t *MockT) Errorf(_ string, _ ...interface{})
- func (t *MockT) Fail()
- func (t *MockT) FailNow()
- func (t *MockT) Fatalf(_ string, _ ...interface{})
- func (t *MockT) Log(_ ...interface{})
- func (t *MockT) Logf(_ string, _ ...interface{})
- type T
- type TemplateObject
- type TemplateObjects
- type TemplateParam
- type TemplateParams
Constants ¶
const ( NameHost = "dsaas" NameMember = "east" )
const ( HostClusterName = "host-cluster" MemberOperatorNs = "toolchain-member-operator" MemberClusterName = "member-cluster" Member2ClusterName = "member2-cluster" HostOperatorNs = "toolchain-host-operator" )
Variables ¶
var GetReposCommitsByOwnerByRepoByRef mock.EndpointPattern = mock.EndpointPattern{
Pattern: "/repos/{owner}/{repo}/commits/{ref}",
Method: "GET",
}
Functions ¶
func AssertConditionsMatch ¶
func AssertConditionsMatch(t T, actual []toolchainv1alpha1.Condition, expected ...toolchainv1alpha1.Condition)
AssertConditionsMatch asserts that the specified list A of conditions is equal to specified list B of conditions ignoring the order of the elements. We can't use assert.ElementsMatch because the LastTransitionTime of the actual conditions can be modified but the conditions still should be treated as matched
func AssertConditionsMatchAndRecentTimestamps ¶
func AssertConditionsMatchAndRecentTimestamps(t T, actual []toolchainv1alpha1.Condition, expected ...toolchainv1alpha1.Condition)
AssertConditionsMatchAndRecentTimestamps asserts that the specified list of conditions match AND asserts that the timestamps are recent
func AssertContainsCondition ¶
func AssertContainsCondition(t T, conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition)
AssertContainsCondition asserts that the specified list of conditions contains the specified condition. LastTransitionTime is ignored.
func AssertContainsMember ¶
func AssertContainsMember(t T, members []toolchainv1alpha1.Member, contains toolchainv1alpha1.Member)
AssertContainsMember asserts that the specified list of members contains the specified member. It compares only the list of conditions and resource usage. LastTransitionTime is ignored.
func AssertHostOperatorStatusMatch ¶
func AssertHostOperatorStatusMatch(t T, actual toolchainv1alpha1.HostOperatorStatus, expected toolchainv1alpha1.HostOperatorStatus)
AssertHostOperatorStatusMatch asserts that the specified host operator status matches the expected host operator status
func AssertMembersMatch ¶
func AssertMembersMatch(t T, actual []toolchainv1alpha1.Member, expected ...toolchainv1alpha1.Member)
AssertMembersMatch asserts that the specified list A of members is equal to specified list B of members ignoring the order of the elements. It compares only the list of conditions and resource usage. We can't use assert.ElementsMatch because the LastTransitionTime of the actual conditions can be modified but the conditions still should be treated as matched
func AssertRegistrationServiceDeploymentStatusMatch ¶
func AssertRegistrationServiceDeploymentStatusMatch(t T, actual toolchainv1alpha1.RegistrationServiceDeploymentStatus, expected toolchainv1alpha1.RegistrationServiceDeploymentStatus)
AssertRegistrationServiceDeploymentStatusMatch asserts that the specified registration service deployment status matches the expected one
func AssertRegistrationServiceHealthStatusMatch ¶
func AssertRegistrationServiceHealthStatusMatch(t T, actual toolchainv1alpha1.RegistrationServiceHealth, expected toolchainv1alpha1.RegistrationServiceHealth)
AssertRegistrationServiceHealthStatusMatch asserts that the specified registration service health status matches the expected one
func AssertRegistrationServiceResourcesStatusMatch ¶
func AssertRegistrationServiceResourcesStatusMatch(t T, actual toolchainv1alpha1.RegistrationServiceResourcesStatus, expected toolchainv1alpha1.RegistrationServiceResourcesStatus)
AssertRegistrationServiceResourcesStatusMatch asserts that the specified registration service resources status matches the expected one
func AssertRegistrationServiceRevisionMatch ¶
func AssertRegistrationServiceRevisionMatch(t T, actual toolchainv1alpha1.RevisionCheck, expected toolchainv1alpha1.RevisionCheck)
AssertRegistrationServiceRevisionMatch asserts that the specified registration service revision check matches the expected one
func AssertRegistrationServiceStatusMatch ¶
func AssertRegistrationServiceStatusMatch(t T, actual toolchainv1alpha1.HostRegistrationServiceStatus, expected toolchainv1alpha1.HostRegistrationServiceStatus)
AssertRegistrationServiceStatusMatch asserts that the specified registration service status matches the expected one
func AssertTimestampsAreRecent ¶
func AssertTimestampsAreRecent(t T, conditions []toolchainv1alpha1.Condition)
AssertTimestampsAreRecent asserts that the timestamps for the provided list of conditions are recent
func ConditionsMatch ¶
func ConditionsMatch(actual []toolchainv1alpha1.Condition, expected ...toolchainv1alpha1.Condition) bool
ConditionsMatch returns true if the specified list A of conditions is equal to specified list B of conditions ignoring the order of the elements
func ContainsCondition ¶
func ContainsCondition(conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition) bool
ContainsCondition returns true if the specified list of conditions contains the specified condition. LastTransitionTime is ignored.
func Create ¶
func Create(ctx context.Context, cl *FakeClient, obj client.Object, opts ...client.CreateOption) error
func CreateTemplate ¶
func CreateTemplate(innerObjects TemplateObjects, params TemplateParams) string
CreateTemplate joins template skeleton with the given template objects and template params and returns a string containing YAML template
func DecodeTemplate ¶
DecodeTemplate decodes the given string using the given decoder to an instance of a Template
func MockGitHubClientForRepositoryCommits ¶
func MockGitHubClientForRepositoryCommits(githubCommitSHA string, commitTimestamp time.Time) client.GetGitHubClientFunc
MockGitHubClientForRepositoryCommits provides a GitHub client which will return the given commit and commit timestamp as a response.
func MockGithubRepositoryCommit ¶
func MockGithubRepositoryCommit(repositoryCommit *github.RepositoryCommit) *http.Client
MockGithubRepositoryCommit creates a http handler that returns a commit for a given org/repo.
func NamespacedName ¶
func NamespacedName(namespace, name string) types.NamespacedName
func NewClusterStatus ¶
func NewClusterStatus(conType toolchainv1alpha1.ConditionType, conStatus corev1.ConditionStatus) toolchainv1alpha1.ToolchainClusterStatus
func NewMockedGithubCommit ¶
func NewMockedGithubCommit(commitSHA string, commitTimestamp time.Time) *github.RepositoryCommit
NewMockedGithubCommit create a GitHub.Commit object with given SHA and timestamp
func NewRESTClient ¶
func NewRESTClient(token, apiEndpoint string) (*rest.RESTClient, error)
NewRESTClient returns a new kube api rest client.
func NewToolchainCluster ¶
func NewToolchainCluster(t *testing.T, name, tcNs, operatorNs, secName string, status toolchainv1alpha1.ToolchainClusterStatus, insecure bool) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret)
func NewToolchainClusterWithEndpoint ¶
func NewToolchainClusterWithEndpoint(t *testing.T, name, tcNs, operatorNs, secName, apiEndpoint string, status toolchainv1alpha1.ToolchainClusterStatus, insecureTls bool) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret)
func SetEnvVarAndRestore ¶
SetEnvVarAndRestore sets the given environment variable with the key to the given value. It returns a function to be called whenever you want to restore the original environment (ideally using defer).
In a test you can use this to set an environment variable:
func TestFoo(t *testing.T) { restoreFunc := SetEnvVarAndRestore(t, "foo", "bar") defer restoreFunc() // continue as if foo=bar }
func SetEnvVarsAndRestore ¶
func SetEnvVarsAndRestore(t *testing.T, envs ...EnvVariable) func()
SetEnvVarsAndRestore sets the given environment variables with the keys to the given values. It returns a function to be called whenever you want to restore the original environment (ideally using defer).
In a test you can use this to set an environment variables:
func TestFoo(t *testing.T) { restoreFunc := SetEnvVarsAndRestore(t, Env("foo", "bar"), Env("boo", "far")) defer restoreFunc() // continue as if foo=bar and boo=far }
func SetupGockForServiceAccounts ¶
func SetupGockForServiceAccounts(t *testing.T, apiEndpoint string, sas ...types.NamespacedName)
SetupGockForServiceAccounts registers the /namespaces/<namespace>/serviceaccounts/<serviceaccount>/token endpoint with gock. so that token request are intercepted by gock.
func SetupGockWithCleanup ¶
func UnsetEnvVarAndRestore ¶
UnsetEnvVarAndRestore unsets the given environment variable with the key (if present). It returns a function to be called whenever you want to restore the original environment (ideally using defer).
In a test you can use this to temporarily set an environment variable:
func TestFoo(t *testing.T) { restoreFunc := UnsetEnvVarAndRestore(t, "foo") defer restoreFunc() os.Setenv(key, "bar") // continue as if foo=bar }
func Update ¶
func Update(ctx context.Context, cl *FakeClient, obj client.Object, opts ...client.UpdateOption) error
Types ¶
type EnvVariable ¶
type EnvVariable func() (key, value string)
func Env ¶
func Env(key, value string) EnvVariable
type FakeClient ¶
type FakeClient struct { client.Client T T MockGet func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error MockList func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error MockCreate func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error MockUpdate func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error MockPatch func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error MockStatusCreate func(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceCreateOption) error MockStatusUpdate func(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error MockStatusPatch func(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error MockDelete func(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error MockDeleteAllOf func(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error }
func NewFakeClient ¶
func NewFakeClient(t T, initObjs ...client.Object) *FakeClient
NewFakeClient creates a fake K8s client with ability to override specific Get/List/Create/Update/StatusUpdate/Delete functions
func (*FakeClient) Create ¶
func (c *FakeClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
func (*FakeClient) Delete ¶
func (c *FakeClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
func (*FakeClient) DeleteAllOf ¶
func (c *FakeClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
func (*FakeClient) List ¶
func (c *FakeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
func (*FakeClient) Patch ¶
func (c *FakeClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
func (*FakeClient) Status ¶
func (c *FakeClient) Status() client.StatusWriter
func (*FakeClient) Update ¶
func (c *FakeClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
type MockT ¶
type MockT struct {
// contains filtered or unexported fields
}
func (*MockT) CalledErrorf ¶
func (*MockT) CalledFailNow ¶
func (*MockT) CalledFatalf ¶
func (*MockT) CalledLogf ¶
type T ¶
type T interface { Log(args ...interface{}) Logf(format string, args ...interface{}) Errorf(format string, args ...interface{}) FailNow() Fail() Fatalf(format string, args ...interface{}) }
T our minimal testing interface for our custom assertions
type TemplateObject ¶
type TemplateObject string
const ( Namespace TemplateObject = `` /* 288-byte string literal not displayed */ ServiceAccount TemplateObject = `` /* 152-byte string literal not displayed */ RoleBinding TemplateObject = `` /* 268-byte string literal not displayed */ RoleBindingWithExtraUser TemplateObject = `` /* 303-byte string literal not displayed */ Service TemplateObject = `` /* 230-byte string literal not displayed */ ConfigMap TemplateObject = `` /* 212-byte string literal not displayed */ NamespaceObj TemplateObject = `` /* 350-byte string literal not displayed */ RolebindingObj TemplateObject = `` /* 347-byte string literal not displayed */ )
template objects
type TemplateObjects ¶
type TemplateObjects string
func WithObjects ¶
func WithObjects(innerObjects ...TemplateObject) TemplateObjects
WithObjects takes list of template objects and joins them together
type TemplateParam ¶
type TemplateParam string
const ( UsernameParam TemplateParam = ` - name: USERNAME value: toolchain-dev required: true` UsernameParamWithoutValue TemplateParam = ` - name: USERNAME required: true` CommitParam TemplateParam = ` - name: COMMIT value: 123abc required: true` NamespaceParam TemplateParam = ` - name: NAMESPACE value: toolchain-host-operator` ServSelectorParam TemplateParam = ` - name: SERVICE_SELECTOR value: registration-service` )
template parameters
type TemplateParams ¶
type TemplateParams string
func WithParams ¶
func WithParams(parameters ...TemplateParam) TemplateParams
WithParams takes list of template parameters and joins them together