Documentation ¶
Index ¶
- Variables
- func LookupConcreteToken(tokenPointer **api.SPIAccessToken) ...
- func PersistConcreteMetadata(metadata *api.TokenMetadata) func(context.Context, client.Client, *api.SPIAccessToken) error
- func StandardFileRequest(namePrefix string) *api.SPIFileContentRequest
- func StandardTestBinding(namePrefix string) *api.SPIAccessTokenBinding
- func StandardTestToken(namePrefix string) *api.SPIAccessToken
- func TriggerReconciliation(object client.Object)
- type ITestBehavior
- type ITestTiming
- type IntegrationTest
- type TestObjects
- func (to TestObjects) GetBinding(key client.ObjectKey) *api.SPIAccessTokenBinding
- func (to TestObjects) GetBindingsByNamePrefix(key client.ObjectKey) []*api.SPIAccessTokenBinding
- func (to TestObjects) GetCheck(key client.ObjectKey) *api.SPIAccessCheck
- func (to TestObjects) GetChecksByNamePrefix(key client.ObjectKey) []*api.SPIAccessCheck
- func (to TestObjects) GetDataUpdate(key client.ObjectKey) *api.SPIAccessTokenDataUpdate
- func (to TestObjects) GetDataUpdatesByNamePrefix(key client.ObjectKey) []*api.SPIAccessTokenDataUpdate
- func (to TestObjects) GetFileContentRequest(key client.ObjectKey) *api.SPIFileContentRequest
- func (to TestObjects) GetFileContentRequestsByNamePrefix(key client.ObjectKey) []*api.SPIFileContentRequest
- func (to TestObjects) GetToken(key client.ObjectKey) *api.SPIAccessToken
- func (to TestObjects) GetTokensByNamePrefix(key client.ObjectKey) []*api.SPIAccessToken
- type TestServiceProvider
- func (t TestServiceProvider) CheckRepositoryAccess(ctx context.Context, cl client.Client, accessCheck *api.SPIAccessCheck) (*api.SPIAccessCheckStatus, error)
- func (t TestServiceProvider) GetBaseUrl() string
- func (t TestServiceProvider) GetDownloadFileCapability() serviceprovider.DownloadFileCapability
- func (t TestServiceProvider) GetOAuthEndpoint() string
- func (t TestServiceProvider) GetType() api.ServiceProviderType
- func (t TestServiceProvider) LookupToken(ctx context.Context, cl client.Client, binding *api.SPIAccessTokenBinding) (*api.SPIAccessToken, error)
- func (t TestServiceProvider) MapToken(ctx context.Context, binding *api.SPIAccessTokenBinding, ...) (serviceprovider.AccessTokenMapper, error)
- func (t TestServiceProvider) OAuthScopesFor(permissions *api.Permissions) []string
- func (t TestServiceProvider) PersistMetadata(ctx context.Context, cl client.Client, token *api.SPIAccessToken) error
- func (t *TestServiceProvider) Reset()
- func (t TestServiceProvider) Validate(ctx context.Context, validated serviceprovider.Validated) (serviceprovider.ValidationResult, error)
- type TestSetup
Constants ¶
This section is empty.
Variables ¶
var ITest = IntegrationTest{}
ITest is the globally accessible integration test "context"
Functions ¶
func LookupConcreteToken ¶ added in v0.3.0
func LookupConcreteToken(tokenPointer **api.SPIAccessToken) func(ctx context.Context, cl client.Client, binding *api.SPIAccessTokenBinding) (*api.SPIAccessToken, error)
LookupConcreteToken returns a function that can be used as the TestServiceProvider.LookupTokenImpl that just returns a freshly loaded version of the provided token. The token is a pointer to a pointer to the token so that this can also support lazily initialized tokens.
func PersistConcreteMetadata ¶ added in v0.3.0
func PersistConcreteMetadata(metadata *api.TokenMetadata) func(context.Context, client.Client, *api.SPIAccessToken) error
PersistConcreteMetadata returns a function that can be used as the TestServiceProvider.PersistMetadataImpl that stores the provided metadata to any token.
func StandardFileRequest ¶ added in v0.9.0
func StandardFileRequest(namePrefix string) *api.SPIFileContentRequest
func StandardTestBinding ¶ added in v0.9.0
func StandardTestBinding(namePrefix string) *api.SPIAccessTokenBinding
StandardTestBinding creates an SPIAccessTokenBinding with the configuration commonly used in the tests.
func StandardTestToken ¶ added in v0.9.0
func StandardTestToken(namePrefix string) *api.SPIAccessToken
StandardTestToken creates an SPIAccessToken with the configuration commonly used in the tests.
func TriggerReconciliation ¶ added in v0.9.0
TriggerReconciliation updates the provided object with a "random-annon-to-trigger-reconcile" annotation (with a random value) so that a new reconciliation is performed.
Types ¶
type ITestBehavior ¶ added in v0.9.0
type ITestBehavior struct { // BeforeObjectsCreated sets up the behavior before any of the desired objects specified in TestSetup.ToCreate are // actually created. BeforeObjectsCreated func() // AfterObjectsCreated sets up the behavior after the objects from TestSetup.ToCreate (and possibly others, like // auto-created tokens for the bindings) have been created. The objects currently existing in the cluster are passed // in as an argument. AfterObjectsCreated func(TestObjects) // DontTriggerReconcileAfterObjectsCreated in the unlikely event, where you DON'T want to trigger the reconciliation // of the objects in the cluster after the ITest behavior was changed in AfterObjectsCreated, set this to true. DontTriggerReconcileAfterObjectsCreated bool }
ITestBehavior configures the ITest for the tests.
type ITestTiming ¶ added in v0.9.0
type ITestTiming struct { // Tokens is the TTL of the tokens Tokens time.Duration // Bindings is the TTL of the bindings Bindings time.Duration // Checks is the TTL of the SPIAccessChecks Checks time.Duration // FileRequests is the TTL of the SPIFileContentRequests FileRequests time.Duration // TokenLookupCache is the TTL of the token metadata TokenLookupCache time.Duration // DeletionGracePeriod is the grace period before tokens in awaiting state are deleted DeletionGracePeriod time.Duration }
ITestTiming collects all the timing configuration. The changes made in ITestBehavior methods (if any) take precedence over what is configured here.
type IntegrationTest ¶ added in v0.9.0
type IntegrationTest struct { // Client is the Kubernetes client to use to talk to the Kubernetes cluster Client client.Client // NoPrivsClient is a Kubernetes client to use to talk to the Kubernetes cluster that doesn't have any permissions NoPrivsClient client.Client // TestEnvironment is the Kubernetes API abstraction that we're using to simulate a full-blown cluster TestEnvironment *envtest.Environment // Context is the context to use with various API requests. It is set up with timeout cancelling to correctly handle // the testsuite timeouts. Use Cancel to force the cancellation of the context yourself, if ever needed. Context context.Context // TokenStorage is the token storage instance that the controllers are using to store the token data. By default, // this is backed the VaultTestCluster. TokenStorage tokenstorage.TokenStorage // Cancel can be used to forcefully cancel the Context, interrupting all the future requests and thus short-circuiting // the testsuite as a whole. Cancel context.CancelFunc // TestServiceProviderProbe is the probing function to identify the service provider to use. This is automagically // setup to recognize the URLs starting with "test-provider://" as handled by the TestServiceProvider. TestServiceProviderProbe serviceprovider.Probe // TestServiceProvider is the service provider that the controllers are set up to use. You can modify its behavior // in the before-each of the tests. TestServiceProvider TestServiceProvider // HostCredsServiceProvider is the fallback provider used when no other service provider is detected for given URL. HostCredsServiceProvider TestServiceProvider // VaultTestCluster is Vault's in-memory test cluster instance. VaultTestCluster *vault.TestCluster // OperatorConfiguration is the "live" configuration used by the controllers. Changing the values here has direct // effect in the controllers as long as they don't cache the values somehow (by storing them in an instance field // for example). OperatorConfiguration *opconfig.OperatorConfiguration // MetricsRegistry is the metrics registry the controllers are configured with. This can be used to check that the // metrics are being collected. MetricsRegistry *prometheus.Registry }
IntegrationTest is meant to be used through the ITest global variable to inspect and configure the behavior of the various subsystems of SPI.
type TestObjects ¶ added in v0.9.0
type TestObjects struct { Tokens []*api.SPIAccessToken Bindings []*api.SPIAccessTokenBinding Checks []*api.SPIAccessCheck FileContentRequests []*api.SPIFileContentRequest DataUpdates []*api.SPIAccessTokenDataUpdate }
TestObjects collects the objects of interest as they are required or exist in the cluster
func (TestObjects) GetBinding ¶ added in v0.9.0
func (to TestObjects) GetBinding(key client.ObjectKey) *api.SPIAccessTokenBinding
func (TestObjects) GetBindingsByNamePrefix ¶ added in v0.9.0
func (to TestObjects) GetBindingsByNamePrefix(key client.ObjectKey) []*api.SPIAccessTokenBinding
func (TestObjects) GetCheck ¶ added in v0.9.0
func (to TestObjects) GetCheck(key client.ObjectKey) *api.SPIAccessCheck
func (TestObjects) GetChecksByNamePrefix ¶ added in v0.9.0
func (to TestObjects) GetChecksByNamePrefix(key client.ObjectKey) []*api.SPIAccessCheck
func (TestObjects) GetDataUpdate ¶ added in v0.9.0
func (to TestObjects) GetDataUpdate(key client.ObjectKey) *api.SPIAccessTokenDataUpdate
func (TestObjects) GetDataUpdatesByNamePrefix ¶ added in v0.9.0
func (to TestObjects) GetDataUpdatesByNamePrefix(key client.ObjectKey) []*api.SPIAccessTokenDataUpdate
func (TestObjects) GetFileContentRequest ¶ added in v0.9.0
func (to TestObjects) GetFileContentRequest(key client.ObjectKey) *api.SPIFileContentRequest
func (TestObjects) GetFileContentRequestsByNamePrefix ¶ added in v0.9.0
func (to TestObjects) GetFileContentRequestsByNamePrefix(key client.ObjectKey) []*api.SPIFileContentRequest
func (TestObjects) GetToken ¶ added in v0.9.0
func (to TestObjects) GetToken(key client.ObjectKey) *api.SPIAccessToken
func (TestObjects) GetTokensByNamePrefix ¶ added in v0.9.0
func (to TestObjects) GetTokensByNamePrefix(key client.ObjectKey) []*api.SPIAccessToken
type TestServiceProvider ¶
type TestServiceProvider struct { LookupTokenImpl func(context.Context, client.Client, *api.SPIAccessTokenBinding) (*api.SPIAccessToken, error) PersistMetadataImpl func(context.Context, client.Client, *api.SPIAccessToken) error GetBaseUrlImpl func() string OAuthScopesForImpl func(permissions *api.Permissions) []string GetTypeImpl func() api.ServiceProviderType GetOauthEndpointImpl func() string CheckRepositoryAccessImpl func(context.Context, client.Client, *api.SPIAccessCheck) (*api.SPIAccessCheckStatus, error) MapTokenImpl func(context.Context, *api.SPIAccessTokenBinding, *api.SPIAccessToken, *api.Token) (serviceprovider.AccessTokenMapper, error) ValidateImpl func(context.Context, serviceprovider.Validated) (serviceprovider.ValidationResult, error) CustomizeReset func(provider *TestServiceProvider) DownloadFileCapability func() serviceprovider.DownloadFileCapability }
TestServiceProvider is an implementation of the serviceprovider.ServiceProvider interface that can be modified by supplying custom implementations of each of the interface methods. It provides dummy implementations of them, too, so that no null pointer dereferences should occur under normal operation.
func (TestServiceProvider) CheckRepositoryAccess ¶ added in v0.5.1
func (t TestServiceProvider) CheckRepositoryAccess(ctx context.Context, cl client.Client, accessCheck *api.SPIAccessCheck) (*api.SPIAccessCheckStatus, error)
func (TestServiceProvider) GetBaseUrl ¶
func (t TestServiceProvider) GetBaseUrl() string
func (TestServiceProvider) GetDownloadFileCapability ¶ added in v0.8.3
func (t TestServiceProvider) GetDownloadFileCapability() serviceprovider.DownloadFileCapability
func (TestServiceProvider) GetOAuthEndpoint ¶
func (t TestServiceProvider) GetOAuthEndpoint() string
func (TestServiceProvider) GetType ¶
func (t TestServiceProvider) GetType() api.ServiceProviderType
func (TestServiceProvider) LookupToken ¶
func (t TestServiceProvider) LookupToken(ctx context.Context, cl client.Client, binding *api.SPIAccessTokenBinding) (*api.SPIAccessToken, error)
func (TestServiceProvider) MapToken ¶ added in v0.5.5
func (t TestServiceProvider) MapToken(ctx context.Context, binding *api.SPIAccessTokenBinding, token *api.SPIAccessToken, tokenData *api.Token) (serviceprovider.AccessTokenMapper, error)
func (TestServiceProvider) OAuthScopesFor ¶ added in v0.6.8
func (t TestServiceProvider) OAuthScopesFor(permissions *api.Permissions) []string
func (TestServiceProvider) PersistMetadata ¶ added in v0.3.0
func (t TestServiceProvider) PersistMetadata(ctx context.Context, cl client.Client, token *api.SPIAccessToken) error
func (*TestServiceProvider) Reset ¶
func (t *TestServiceProvider) Reset()
func (TestServiceProvider) Validate ¶ added in v0.5.5
func (t TestServiceProvider) Validate(ctx context.Context, validated serviceprovider.Validated) (serviceprovider.ValidationResult, error)
type TestSetup ¶ added in v0.9.0
type TestSetup struct { // ToCreate is a list of objects that are expected to be present in the cluster. Once BeforeEach is called, the // true state of those objects is stored in the InCluster field. ToCreate TestObjects // InCluster references all the objects (that we're interested in) that exist in the cluster. It is filled in during // the BeforeEach method and represents the true state of the objects (no need to load them again after BeforeEach // completes). InCluster TestObjects // Behavior is used to set up the behavior of the ITest at various stages (you can modify the service providers, // configuration, etc.) Behavior ITestBehavior // Timing configures the different periods and TTLs desired. By default, everything is set up to never expire so // that the test methods don't need to take into account the disappearance of objects due to unpredictable timing // issues. Timing ITestTiming // contains filtered or unexported fields }
TestSetup is used to express the requirements on the state of the K8s Cluster before the tests. Once an instance with the desired configuration is produced, its BeforeEach and AfterEach methods can be called to bring the cluster to the desired state and tear it back down.
func (*TestSetup) AfterEach ¶ added in v0.9.0
func (ts *TestSetup) AfterEach()
AfterEach cleans up all the objects from the cluster and reverts the behavior of ITest to what it was before the test started (to what BeforeEach stored).
func (*TestSetup) BeforeEach ¶ added in v0.9.0
func (ts *TestSetup) BeforeEach(postCondition func(Gomega))
BeforeEach is where the magic happens. It first checks that the cluster is empty, then stores the configuration of the ITest, resets it, creates the required objects, re-configures the ITest and waits for the cluster state to settle (i.e. wait for the controllers to create all the additional objects and finish all the reconciles). Once this method returns, the TestSetup.InCluster contains the objects of interest as they exist in the cluster after all the reconciliation has been performed at least once with the reconfigured ITest.
The `postCondition` is a (potentially `nil`) check that needs to succeed before we can claim the cluster reached the desired state. If it is `nil`, then only the best effort is made to wait for the controllers to finish the reconciliation (basically the only thing guaranteed is that the objects will have a status, i.e. the reconciliation happened at least once).
NOTE we're not doing anything with the metrics registry so far here...
func (*TestSetup) ReconcileWithCluster ¶ added in v0.9.0
func (ts *TestSetup) ReconcileWithCluster(postCondition func(Gomega))
ReconcileWithCluster triggers the reconciliation and waits for the cluster to settle again. This can be used after a test or a nested Gomega.BeforeEach modifies the behavior and we need to re-sync and wait for the controllers to accommodate for the changed behavior.
The `postCondition` is a (potentially `nil`) check that needs to succeed before we can claim the cluster reached the desired state. If it is `nil`, then only the best effort is made to wait for the controllers to finish the reconciliation (basically the only thing guaranteed is that the objects will have a status, i.e. the reconciliation happened at least once).
The `postCondition` can use the `testSetup.InCluster` to access the current state of the objects (which is being updated during this call).