Documentation
¶
Index ¶
- Constants
- Variables
- func CreateCACertificatePEM(t *testing.T) []byte
- func CreateCertificateChain(t *testing.T, subject pkix.Name, pkey *rsa.PrivateKey) string
- func CreateCertificatePEM(t *testing.T, csr *x509.CertificateRequest, pkey *rsa.PrivateKey) []byte
- func CreateCtxWithTenant(tenant string) context.Context
- func CreateDBTenant(tb testing.TB, dbCon *multitenancy.DB, tenant *model.Tenant)
- func CreateTestEntities(ctx context.Context, tb testing.TB, r repo.Repo, entities ...repo.Resource)
- func DeleteTestEntities(ctx context.Context, tb testing.TB, r repo.Repo, entities ...repo.Resource)
- func GetFreePort() (int, error)
- func GetFreePortString() (string, error)
- func GetJSONBody[t any](tb testing.TB, w *httptest.ResponseRecorder) t
- func GetPluginDir(dir string) string
- func GetTestURL(tb testing.TB, tenant, path string) string
- func InjectClientDataIntoContext(ctx context.Context, identifier string, groups []string) context.Context
- func MakeHTTPRequest(tb testing.TB, server cmkapi.ServeMux, opt RequestOptions) *httptest.ResponseRecorder
- func NewAMQPClient(tb testing.TB, amqpCfg AMQPCfg) (*amqp.Client, config.AMQP)
- func NewAPIServer(tb testing.TB, dbCon *multitenancy.DB, testCfg TestAPIServerConfig) cmkapi.ServeMux
- func NewCertificate(m func(*model.Certificate)) *model.Certificate
- func NewGRPCSuite(tb testing.TB, registrars ...ServiceRegistrar) (*grpc.Server, *commongrpc.DynamicClientConn)
- func NewGroup(m func(*model.Group)) *model.Group
- func NewHTTPRequest(tb testing.TB, opt RequestOptions) *http.Request
- func NewImportParams(m func(*model.ImportParams)) *model.ImportParams
- func NewIsolatedDB(tb testing.TB, cfg config.Database) config.Database
- func NewKey(m func(*model.Key)) *model.Key
- func NewKeyConfig(m func(*model.KeyConfiguration)) *model.KeyConfiguration
- func NewKeyLabel(m func(l *model.KeyLabel)) *model.KeyLabel
- func NewKeyVersion(m func(*model.KeyVersion)) *model.KeyVersion
- func NewKeystore(m func(*model.Keystore)) *model.Keystore
- func NewKeystoreConfig(m func(*model.KeystoreConfig)) *model.KeystoreConfig
- func NewMigrator() db.Migrator
- func NewMutator[T any](baseProv func() T) func(mutatorFn ...func(*T)) T
- func NewSystem(m func(*model.System)) *model.System
- func NewTag(m func(*model.Tag)) *model.Tag
- func NewTenant(m func(t *model.Tenant)) *model.Tenant
- func NewTestDB(tb testing.TB, cfg TestDBConfig, opts ...TestDBConfigOpt) (*multitenancy.DB, []string, config.Database)
- func NewUserManager() manager.User
- func NewWorkflow(m func(*model.Workflow)) *model.Workflow
- func NewWorkflowApprover(m func(approver *model.WorkflowApprover)) *model.WorkflowApprover
- func NewWorkflowConfig(m func(m *model.TenantConfig)) *model.TenantConfig
- func RegionsToMapSlice(regions []config.Region) []map[string]string
- func RunTestQuery(db *multitenancy.DB, tenant string, queries ...string)
- func SetupLoggerWithBuffer() *slog.Logger
- func SetupMockPlugins(mocks ...MockPlugin) []plugincatalog.PluginConfig
- func StartPostgresSQL(tb testing.TB, cfg *config.Database, ...)
- func StartRabbitMQ(tb testing.TB, opts ...testcontainers.ContainerCustomizer) string
- func StartRedis(tb testing.TB, cfg *config.Scheduler, ...)
- func WithJSON(tb testing.TB, i any) io.Reader
- func WithString(tb testing.TB, i any) io.Reader
- func WithTenantID(ctx context.Context, db *multitenancy.DB, tenantID string, ...) error
- type AMQPCfg
- type CryptoCert
- type ErrorForced
- func (e *ErrorForced) Register()
- func (e *ErrorForced) Unregister()
- func (e *ErrorForced) WithCreate() *ErrorForced
- func (e *ErrorForced) WithDelete() *ErrorForced
- func (e *ErrorForced) WithQuery() *ErrorForced
- func (e *ErrorForced) WithRaw() *ErrorForced
- func (e *ErrorForced) WithRow() *ErrorForced
- func (e *ErrorForced) WithUpdate() *ErrorForced
- type IdentityManagementUserRef
- type MockPlugin
- type OrbitalJob
- type RequestOptions
- type ServiceRegistrar
- type TLSFiles
- type TestAPIServerConfig
- type TestDBConfig
- type TestDBConfigOpt
- type TestMockAMQPOperator
- type TestModel
Constants ¶
const ( DaysToExpiration = 7 TestLocalityID = "12345678-90ab-cdef-1234-567890abcdef" TestDefaultKeystoreCommonName = "default.kms.cmk" TestRoleArn = "arn:aws:iam::123456789012:role/ExampleRole" TestTrustAnchorArn = "arn:aws:rolesanywhere:eu-west-2:123456789012:trust-anchor/12345678-90ab-cdef-1234" TestProfileArn = "arn:aws:rolesanywhere:eu-west-2:123456789012:profile/12345678-90ab-cdef-1234" )
const (
DefaultThrottleInterval = 5 * time.Second
)
const MaxPSQLSchemaName = 64
const TestCertURL = "https://aia.pki.co.test.com/aia/TEST%20Cloud%20Root%20CA.crt"
const TestHostPrefix = "https://kms.test/cmk/v1/"
const (
TestTenant = "test"
)
Variables ¶
var ( ErrRegisterFailed = errors.New("failed to register callback") ErrUnregisterFailed = errors.New("failed to unregister callback") )
var CertIssuer = MockPlugin{ // contains filtered or unexported fields }
var ErrFailedConversion = errors.New("failed to convert to TCPAddr")
var IdentityManagementGroupMembership = map[string][]IdentityManagementUserRef{
"SCIM-Group-ID-001": {
{"00000000-0000-0000-0000-100000000001", "user1@example.com"},
{"00000000-0000-0000-0000-100000000002", "user2@example.com"},
},
"SCIM-Group-ID-002": {
{"00000000-0000-0000-0000-100000000003", "user3@example.com"},
{"00000000-0000-0000-0000-100000000004", "user4@example.com"},
},
}
var IdentityManagementGroups = map[string]string{
"KMS_001": "SCIM-Group-ID-001",
"KMS_002": "SCIM-Group-ID-002",
}
var IdentityPlugin = MockPlugin{ // contains filtered or unexported fields }
var KeyStorePlugin = MockPlugin{ // contains filtered or unexported fields }
var KeystoreProviderPlugin = MockPlugin{ // contains filtered or unexported fields }
var Notification = MockPlugin{ // contains filtered or unexported fields }
var SupportedRegions = []config.Region{
{Name: "Region 1", TechnicalName: "region-1"},
{Name: "Region 2", TechnicalName: "region-2"},
}
var SupportedRegionsMap = RegionsToMapSlice(SupportedRegions)
var SystemInfo = MockPlugin{ // contains filtered or unexported fields }
var TestBaseConfig = commoncfg.BaseConfig{ Logger: commoncfg.Logger{ Format: "json", Level: "info", }, }
var TestDB = config.Database{ Host: commoncfg.SourceRef{ Source: commoncfg.EmbeddedSourceValue, Value: "localhost", }, User: commoncfg.SourceRef{ Source: commoncfg.EmbeddedSourceValue, Value: "postgres", }, Secret: commoncfg.SourceRef{ Source: commoncfg.EmbeddedSourceValue, Value: "secret", }, Name: "cmk", Port: "5433", }
var TestModelName = "test_models"
var TestRegistryConfig = &commoncfg.GRPCClient{ Enabled: true, Address: "localhost:9092", SecretRef: &commoncfg.SecretRef{ Type: commoncfg.InsecureSecretType, }, }
TestRegistryConfig is a default registry config for testing purposes
var TestSessionManagerConfig = &commoncfg.GRPCClient{ Enabled: true, Address: "localhost:9091", SecretRef: &commoncfg.SecretRef{ Type: commoncfg.InsecureSecretType, }, }
TestSessionManagerConfig is a default session manager config for testing purposes
var ValidKeystoreAccountInfo = map[string]string{
"AccountID": "111122223333",
"UserID": "123456789012",
}
Functions ¶
func CreateCACertificatePEM ¶
func CreateCertificateChain ¶
func CreateCertificatePEM ¶
func CreateCertificatePEM( t *testing.T, csr *x509.CertificateRequest, pkey *rsa.PrivateKey, ) []byte
func CreateCtxWithTenant ¶
func CreateDBTenant ¶
func CreateTestEntities ¶
func DeleteTestEntities ¶
func GetFreePort ¶
GetFreePort asks the kernel for a free open port that is ready to use.
func GetFreePortString ¶
func GetJSONBody ¶
func GetJSONBody[t any](tb testing.TB, w *httptest.ResponseRecorder) t
GetJSONBody is used to get a response out of an HTTP Body encoded as JSON For error responses use cmkapi.ErrorMessage as it's type
func GetPluginDir ¶
func InjectClientDataIntoContext ¶
func InjectClientDataIntoContext(ctx context.Context, identifier string, groups []string) context.Context
InjectClientDataIntoContext adds identifier, groups to the context for testing.
func MakeHTTPRequest ¶
func MakeHTTPRequest(tb testing.TB, server cmkapi.ServeMux, opt RequestOptions) *httptest.ResponseRecorder
MakeHTTPRequest creates an HTTP method and gets its response for it On POST/PATCH methods, RequestOptions body should use WithString/WithJSON methods
func NewAMQPClient ¶
func NewAPIServer ¶
func NewAPIServer( tb testing.TB, dbCon *multitenancy.DB, testCfg TestAPIServerConfig, ) cmkapi.ServeMux
NewAPIServer creates a new API server with the given database connection
func NewCertificate ¶
func NewCertificate(m func(*model.Certificate)) *model.Certificate
func NewGRPCSuite ¶
func NewGRPCSuite( tb testing.TB, registrars ...ServiceRegistrar, ) ( *grpc.Server, *commongrpc.DynamicClientConn, )
NewGRPCSuite creates a new gRPC server and client connection for testing purposes. Returns the server and client connection for use in tests.
func NewHTTPRequest ¶
func NewHTTPRequest(tb testing.TB, opt RequestOptions) *http.Request
NewHTTPRequest builds an HTTP Request it sets default content-types for certain Methods
func NewImportParams ¶
func NewImportParams(m func(*model.ImportParams)) *model.ImportParams
func NewIsolatedDB ¶
NewIsolatedDB creates a new database on a postgres instance and returns it
This is intended only for tests that call functions establishing DB connection
func NewKeyConfig ¶
func NewKeyConfig(m func(*model.KeyConfiguration)) *model.KeyConfiguration
func NewKeyVersion ¶
func NewKeyVersion(m func(*model.KeyVersion)) *model.KeyVersion
func NewKeystoreConfig ¶
func NewKeystoreConfig(m func(*model.KeystoreConfig)) *model.KeystoreConfig
func NewMigrator ¶
func NewMutator ¶
func NewMutator[T any](baseProv func() T) func(mutatorFn ...func(*T)) T
NewMutator provides a function that can be used in table driven tests. It returns a function that can be used to mutate an object, where the object is provided by initTProv.
func NewTestDB ¶
func NewTestDB(tb testing.TB, cfg TestDBConfig, opts ...TestDBConfigOpt) (*multitenancy.DB, []string, config.Database)
NewTestDB sets up a test database connection and creates tenants as needed. It returns a pointer to the multitenancy.DB instance, a slice of tenant IDs and it's config. By default, it uses TestDB configuration. Use opts to customize the setup. This function is intended for use in unit tests.
func NewUserManager ¶
func NewWorkflowApprover ¶
func NewWorkflowApprover(m func(approver *model.WorkflowApprover)) *model.WorkflowApprover
func NewWorkflowConfig ¶
func NewWorkflowConfig(m func(m *model.TenantConfig)) *model.TenantConfig
func RunTestQuery ¶
func RunTestQuery(db *multitenancy.DB, tenant string, queries ...string)
RunTestQuery runs a query in the database with the specified tenant context
func SetupLoggerWithBuffer ¶
SetupLoggerWithBuffer returns a logger that writes to a buffer
func SetupMockPlugins ¶
func SetupMockPlugins(mocks ...MockPlugin) []plugincatalog.PluginConfig
func StartPostgresSQL ¶
func StartPostgresSQL( tb testing.TB, cfg *config.Database, opts ...testcontainers.ContainerCustomizer, )
func StartRabbitMQ ¶
func StartRabbitMQ( tb testing.TB, opts ...testcontainers.ContainerCustomizer, ) string
func StartRedis ¶
func StartRedis( tb testing.TB, cfg *config.Scheduler, opts ...testcontainers.ContainerCustomizer, )
func WithJSON ¶
WithJSON is a helper function that marshals an object to JSON and returns an io.Reader. It is intended to be used as the Body field in RequestOptions when making HTTP requests in tests.
func WithString ¶
WithString is a helper function that converts a string to an io.Reader. It is intended to be used as the Body field in RequestOptions when making HTTP requests in tests.
func WithTenantID ¶
func WithTenantID(ctx context.Context, db *multitenancy.DB, tenantID string, fn func(tx *multitenancy.DB) error) error
Types ¶
type CryptoCert ¶
type ErrorForced ¶
type ErrorForced struct {
// contains filtered or unexported fields
}
ErrorForced - a helper to force an error in the database using gorm
func NewDBErrorForced ¶
func NewDBErrorForced(db *multitenancy.DB, forcedErr error) *ErrorForced
NewDBErrorForced - creates a new ErrorForced instance.
func (*ErrorForced) Register ¶
func (e *ErrorForced) Register()
Register - registers the error callback.
func (*ErrorForced) Unregister ¶
func (e *ErrorForced) Unregister()
Unregister - unregisters the error callback.
func (*ErrorForced) WithCreate ¶
func (e *ErrorForced) WithCreate() *ErrorForced
WithCreate - forces the error in the create callback.
func (*ErrorForced) WithDelete ¶
func (e *ErrorForced) WithDelete() *ErrorForced
WithDelete - forces the error in the delete callback.
func (*ErrorForced) WithQuery ¶
func (e *ErrorForced) WithQuery() *ErrorForced
WithQuery - forces the error in the query callback.
func (*ErrorForced) WithRaw ¶
func (e *ErrorForced) WithRaw() *ErrorForced
WithRaw - forces the error in the raw callback.
func (*ErrorForced) WithRow ¶
func (e *ErrorForced) WithRow() *ErrorForced
WithRow - forces the error in the row callback.
func (*ErrorForced) WithUpdate ¶
func (e *ErrorForced) WithUpdate() *ErrorForced
WithUpdate - forces the error in the update callback.
type MockPlugin ¶
type MockPlugin struct {
// contains filtered or unexported fields
}
type OrbitalJob ¶
type OrbitalJob struct {
ID uuid.UUID
ExternalID string
Data []byte
Type string
Status string
ErrorMessage string
UpdatedAt int64
CreatedAt int64
}
func (OrbitalJob) IsSharedModel ¶
func (OrbitalJob) IsSharedModel() bool
func (OrbitalJob) TableName ¶
func (OrbitalJob) TableName() string
type RequestOptions ¶
type ServiceRegistrar ¶
ServiceRegistrar registers a service with a gRPC server
type TLSFiles ¶
type TLSFiles struct {
Dir string
RootCACertPath string
RootCAKeyPath string
ServerCertPath string
ServerKeyPath string
ClientCertPath string
ClientKeyPath string
}
func CreateTLSFiles ¶
type TestAPIServerConfig ¶
type TestAPIServerConfig struct {
Plugins []MockPlugin // HashiCorp plugins only set if needed
GRPCCon *commongrpc.DynamicClientConn // GRPCClient only set if needed
Config config.Config
}
type TestDBConfig ¶
type TestDBConfig struct {
// WithOrbital creates an entry for an orbital tenant
// This should only be used in tests where we want to access orbital table entries with the repo interface
WithOrbital bool
// If true create DB instance for test instead of tenant
// This should be used whenever each test is testing either:
// - Shared Tables
// - Multiple Tenants
CreateDatabase bool
// If true create an isolated PSQL instance
// In most cases this should not be set as it will take a longer time
// as the container needs to build and startup
WithIsolatedService bool
// If it's nil migrate to latest version
SharedVersion *int64
// Tenant schema version to migrate up to
// If it's nil migrate to latest version
TenantVersion *int64
// GORM Logger
Logger logger.Interface
// contains filtered or unexported fields
}
type TestDBConfigOpt ¶
type TestDBConfigOpt func(*TestDBConfig)
func WithGenerateTenants ¶
func WithGenerateTenants(count int) TestDBConfigOpt
WithGenerateTenants creates count tenants on a separate database
func WithInitTenants ¶
func WithInitTenants(tenants ...model.Tenant) TestDBConfigOpt
WithInitTenants creates the provided tenants on the DB No default tenants are generated on provided tenants
type TestMockAMQPOperator ¶
type TestMockAMQPOperator struct {
// contains filtered or unexported fields
}
func NewMockAMQPOperator ¶
func NewMockAMQPOperator( t *testing.T, numReconcile int, success bool, connConfig amqp.ConnectionInfo, opts ...amqp.ClientOption, ) *TestMockAMQPOperator
func (*TestMockAMQPOperator) Reset ¶
func (o *TestMockAMQPOperator) Reset()
Reset clears the internal state for test isolation
func (*TestMockAMQPOperator) Start ¶
func (o *TestMockAMQPOperator) Start(ctx context.Context)
func (*TestMockAMQPOperator) Stop ¶
func (o *TestMockAMQPOperator) Stop(ctx context.Context)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
testplugins
|
|
|
certificateissuer
command
|
|
|
identitymanagement
command
|
|
|
keystoreman
command
|
|
|
keystoreop
command
|
|
|
notification
command
|
|
|
systeminformation
command
|