integrationutils

package
v0.0.0-...-f20ac65 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 73 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllAPIVersions

func AllAPIVersions() []string

AllAPIVersions returns a sorted list of all registered API versions. IMPORTANT: When adding a new API version to frontend/pkg/frontend/frontend.go, also add a RegisterVersion call here.

func CalculateClusterServiceIDFromExternalAuthResourceID

func CalculateClusterServiceIDFromExternalAuthResourceID(
	ctx context.Context,
	resourcesDBClient database.ResourcesDBClient,
	resourceIDString string,
) (string, error)

CalculateClusterServiceIDFromExternalAuthResourceID returns the Cluster Service internal ID for an external auth, derived from the parent cluster's stored ClusterServiceID.

func CalculateClusterServiceIDFromNodePoolResourceID

func CalculateClusterServiceIDFromNodePoolResourceID(
	ctx context.Context,
	resourcesDBClient database.ResourcesDBClient,
	resourceIDString string,
) (string, error)

CalculateClusterServiceIDFromNodePoolResourceID returns the Cluster Service internal ID for a node pool, derived from the parent cluster's stored ClusterServiceID.

func DefaultLogger

func DefaultLogger(t *testing.T) logr.Logger

func GenerateRandomClusterClusterServiceHREF

func GenerateRandomClusterClusterServiceHREF() string

GenerateRandomClusterClusterServiceHREF returns a Cluster Service cluster HREF with a random 10-character ID, matching the cluster-service mock PostCluster behavior.

func Get20240610ClientFactory

func Get20240610ClientFactory(frontendURL string, subscriptionID string) *hcpsdk20240610preview.ClientFactory

func JSONOnly

func JSONOnly(entry fs.DirEntry) bool

func LoadAllContent

func LoadAllContent(ctx context.Context, contentLoader ContentLoader, createDir fs.FS) error

func LoadCosmosContent

func LoadCosmosContent(ctx context.Context, cosmosContainer *azcosmos.ContainerClient, content []byte) error

func LoadCosmosContentFromFS

func LoadCosmosContentFromFS(ctx context.Context, cosmosContainer *azcosmos.ContainerClient, stepDir fs.FS, filterFn func(fs.DirEntry) bool) error

func MarkOperationsCompleteForName

func MarkOperationsCompleteForName(ctx context.Context, resourcesDBClient database.ResourcesDBClient, subscriptionID, resourceName string) error

func SetClusterServiceID

func SetClusterServiceID(
	ctx context.Context,
	resourcesDBClient database.ResourcesDBClient,
	resourceIDString string,
	clusterServiceID string,
) error

SetClusterServiceID updates the Cosmos document for a cluster, node pool, or external auth with the given Cluster Service internal ID.

func StampRandomClusterServiceID

func StampRandomClusterServiceID(
	ctx context.Context,
	resourcesDBClient database.ResourcesDBClient,
	clusterResourceIDString string,
) error

StampRandomClusterServiceID assigns a random Cluster Service cluster HREF to the cluster document.

func VerifyNoNewGoLeaks

func VerifyNoNewGoLeaks(t *testing.T)

func WithAndWithoutCosmos

func WithAndWithoutCosmos(t *testing.T, testFn func(t *testing.T, withMock bool))

Types

type ClusterServiceMock

type ClusterServiceMock struct {
	ArtifactsDir string

	MockClusterServiceClient *ocm.MockClusterServiceClientSpec
	// contains filtered or unexported fields
}

func NewClusterServiceMock

func NewClusterServiceMock(t *testing.T, artifactsDir string) *ClusterServiceMock

func (*ClusterServiceMock) AddContent

func (s *ClusterServiceMock) AddContent(t *testing.T, initialDataDir fs.FS) error

func (*ClusterServiceMock) Cleanup

func (s *ClusterServiceMock) Cleanup(ctx context.Context)

func (*ClusterServiceMock) GetMergedClusters

func (s *ClusterServiceMock) GetMergedClusters(testName string) ([]map[string]any, error)

GetMergedClusters returns all clusters stored in the mock, each merged from its full mutation history and serialized to a JSON map. The testName should be t.Name() from the test that created the mock.

func (*ClusterServiceMock) GetOrCreateMockData

func (s *ClusterServiceMock) GetOrCreateMockData(dataName string) map[string][]any

type ContentLoader

type ContentLoader interface {
	// LoadContent loads a single JSON document into the database.
	LoadContent(ctx context.Context, content []byte) error
}

ContentLoader is an interface for loading test content into a database. This abstraction allows tests to run against either a real Cosmos DB or a mock database implementation.

type CosmosContentLoader

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

CosmosContentLoader implements ContentLoader and DocumentLister using a real Cosmos DB container.

func NewCosmosContentLoader

func NewCosmosContentLoader(container *azcosmos.ContainerClient) *CosmosContentLoader

NewCosmosContentLoader creates a new CosmosContentLoader from a Cosmos container.

func (*CosmosContentLoader) ListAllDocuments

func (c *CosmosContentLoader) ListAllDocuments(ctx context.Context) ([]*database.TypedDocument, error)

ListAllDocuments returns all documents in the Cosmos container.

func (*CosmosContentLoader) LoadContent

func (c *CosmosContentLoader) LoadContent(ctx context.Context, content []byte) error

LoadContent loads a single JSON document into Cosmos DB.

type CosmosIntegrationTestInfo

type CosmosIntegrationTestInfo struct {
	ArtifactsDir string

	CosmosDatabaseClient *azcosmos.DatabaseClient
	// contains filtered or unexported fields
}

func (*CosmosIntegrationTestInfo) BillingDBClient

func (s *CosmosIntegrationTestInfo) BillingDBClient() database.BillingDBClient

func (*CosmosIntegrationTestInfo) Cleanup

func (s *CosmosIntegrationTestInfo) Cleanup(ctx context.Context)

func (*CosmosIntegrationTestInfo) CosmosResourcesContainer

func (s *CosmosIntegrationTestInfo) CosmosResourcesContainer() *azcosmos.ContainerClient

func (*CosmosIntegrationTestInfo) FleetDBClient

func (*CosmosIntegrationTestInfo) GetArtifactDir

func (s *CosmosIntegrationTestInfo) GetArtifactDir() string

func (*CosmosIntegrationTestInfo) ListAllDocuments

func (s *CosmosIntegrationTestInfo) ListAllDocuments(ctx context.Context) ([]*database.TypedDocument, error)

func (*CosmosIntegrationTestInfo) LoadContent

func (s *CosmosIntegrationTestInfo) LoadContent(ctx context.Context, content []byte) error

func (*CosmosIntegrationTestInfo) ResourcesDBClient

func (s *CosmosIntegrationTestInfo) ResourcesDBClient() database.ResourcesDBClient

type DocumentLister

type DocumentLister interface {
	// ListAllDocuments returns all documents in the database.
	ListAllDocuments(ctx context.Context) ([]*database.TypedDocument, error)
}

DocumentLister is an interface for listing all documents from a database. This is used by the cosmosCompare step to verify database contents.

type FakeOTELClient

type FakeOTELClient struct{}

func (*FakeOTELClient) Send

func (t *FakeOTELClient) Send(ctx context.Context, msg msgs.Msg, options ...base.SendOption) error

type GenericMutationTest

type GenericMutationTest struct {
	CreateJSON []byte
	UpdateJSON []byte
	PatchJSON  []byte
	// contains filtered or unexported fields
}

func ReadGenericMutationTest

func ReadGenericMutationTest(testDir fs.FS) (*GenericMutationTest, error)

func (*GenericMutationTest) ExpectsResult

func (h *GenericMutationTest) ExpectsResult() bool

func (*GenericMutationTest) Initialize

func (h *GenericMutationTest) Initialize(ctx context.Context, testInfo *IntegrationTestInfo) error

func (*GenericMutationTest) IsPatchTest

func (h *GenericMutationTest) IsPatchTest() bool

func (*GenericMutationTest) IsUpdateTest

func (h *GenericMutationTest) IsUpdateTest() bool

func (*GenericMutationTest) VerifyActualError

func (h *GenericMutationTest) VerifyActualError(t *testing.T, actualErr error)

func (*GenericMutationTest) VerifyActualResult

func (h *GenericMutationTest) VerifyActualResult(t *testing.T, actualCreated any)

type IntegrationTestInfo

type IntegrationTestInfo struct {
	StorageIntegrationTestInfo
	*ClusterServiceMock

	ArtifactsDir string

	FrontendURL string
	Frontend    *frontend.Frontend
	AdminURL    string
	AdminAPI    *server.AdminAPI

	KubernetesClientSets *KubernetesClientSets
	// contains filtered or unexported fields
}

func NewIntegrationTestInfoFromEnv

func NewIntegrationTestInfoFromEnv(ctx context.Context, t *testing.T, withMock bool) (*IntegrationTestInfo, error)

func (*IntegrationTestInfo) Cleanup

func (s *IntegrationTestInfo) Cleanup(ctx context.Context)

type KubernetesClientSets

type KubernetesClientSets struct {
	FakeClientSet          *fake.Clientset
	SessiongateClientset   *sessiongatefake.Clientset
	CoreInformerFactory    kubeinformers.SharedInformerFactory
	SessionInformerFactory sessiongateinformers.SharedInformerFactory
	// contains filtered or unexported fields
}

KubernetesClientSets provides fake clientsets with informer support for testing.

Uses the pattern from kubernetes/client-go/examples/fake-client to properly synchronize fake clients with informers. The key is waiting for the watcher to start before injecting events. See: https://github.com/kubernetes/client-go/blob/master/examples/fake-client/main_test.go

func NewKubernetesClientSets

func NewKubernetesClientSets(sessionNamespace string) *KubernetesClientSets

NewKubernetesClientSets creates fake clientsets with informer support. Informers are started and synchronized before returning.

func (*KubernetesClientSets) Apply

func (k *KubernetesClientSets) Apply(ctx context.Context, data []byte) error

func (*KubernetesClientSets) Create

func (k *KubernetesClientSets) Create(ctx context.Context, data []byte) error

func (*KubernetesClientSets) GetTrackedObject

func (*KubernetesClientSets) Stop

func (k *KubernetesClientSets) Stop()

type MockCosmosIntegrationTestInfo

type MockCosmosIntegrationTestInfo struct {
	ArtifactsDir string
	// contains filtered or unexported fields
}

func (*MockCosmosIntegrationTestInfo) BillingDBClient

func (*MockCosmosIntegrationTestInfo) Cleanup

func (*MockCosmosIntegrationTestInfo) FleetDBClient

func (*MockCosmosIntegrationTestInfo) GetArtifactDir

func (m *MockCosmosIntegrationTestInfo) GetArtifactDir() string

func (*MockCosmosIntegrationTestInfo) ListAllDocuments

func (*MockCosmosIntegrationTestInfo) LoadContent

func (m *MockCosmosIntegrationTestInfo) LoadContent(ctx context.Context, content []byte) error

func (*MockCosmosIntegrationTestInfo) ResourcesDBClient

type StorageIntegrationTestInfo

type StorageIntegrationTestInfo interface {
	ContentLoader
	DocumentLister

	GetArtifactDir() string
	ResourcesDBClient() database.ResourcesDBClient
	BillingDBClient() database.BillingDBClient
	FleetDBClient() database.FleetDBClient

	Cleanup(ctx context.Context)
}

func NewCosmosFromTestingEnv

func NewCosmosFromTestingEnv(ctx context.Context, t *testing.T) (StorageIntegrationTestInfo, error)

func NewMockCosmosFromTestingEnv

func NewMockCosmosFromTestingEnv(ctx context.Context, t *testing.T) (StorageIntegrationTestInfo, error)

Jump to

Keyboard shortcuts

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