testing

package
v2.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: Apache-2.0 Imports: 38 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AuthLoginPath = "/api/v1/auth/login"
	//nolint:gosec // not a secret
	SecretsCredentialPoliciesPath = "/api/v1/secrets/credential-policies"
	//nolint:gosec // not a secret
	SecretsCredentialPoliciesIDPath  = "/api/v1/secrets/credential-policies/{id}"
	DeploymentTemplatesRemovePath    = "/api/v1/deployment/templates/remove"
	DeploymentTemplatesPath          = "/api/v1/deployment/templates"
	DeploymentInstancesCreate        = "/api/v1/deployment/instances/create"
	DeploymentInstancesDeploy        = "/api/v1/deployment/instances/deploy"
	DeploymentInstancesRemovePath    = "/api/v1/deployment/instances/remove"
	DeploymentInstancesPlanningPath  = "/api/v1/deployment/instances/planning"
	DeploymentReadinessPath          = "/api/v1/deployment/readiness"
	InventoryCloudServicesPath       = "/api/v1/inventory/cloud-services"
	InventoryCloudServicesRemovePath = "/api/v1/inventory/cloud-services/remove"
	InventoryCloudServicesIDPath     = "/api/v1/inventory/cloud-services/{id}"
	InventoryDevicesRemovePath       = "/api/v1/inventory/devices/remove"
	InventoryDevicesIDUpdatePath     = "/api/v1/inventory/devices/{id}/update"
	InventoryDeviceProfilesPath      = "/api/v1/inventory/device-profiles"
	InventoryRepositoryPath          = "/api/v1/inventory/repository"
	InventorySitesPath               = "/api/v1/inventory/sites"
	InventorySitesID                 = "/api/v1/inventory/sites/{id}"
	InventorySitesRemovePath         = "/api/v1/inventory/sites/remove"
	DeploymentInstancesIDPath        = "/api/v1/deployment/instances/{id}"
	DeploymentInstancesPath          = "/api/v1/deployment/instances"
	InventoryDevicesPath             = "/api/v1/inventory/devices"
	TaskManagementTasksIDPath        = "/api/v1/task-management/tasks/{id}"
)
View Source
const (
	InstancesByIDResponse = "loca_api_deployment_instances_id.json"

	InventoryCloudServicesByIDGet = "loca_api_inventory_cloud_services_by_id.json"
	InventoryCloudServicesPost    = "loca_api_inventory_cloud_services_post.json"
)
View Source
const (
	ExtraVarsOSResourceID = "os_resource_id"

	StageInstalled             = "installed"
	StageActive                = "active"
	OperationDeploy            = "Deploy"
	StatusFinishedSuccessfully = "Finished successfully"
	SiteID                     = "66d5a4a57bc832e5fbf72705"
	SecondaryInstanceID        = "870c483ef445a55d541460db"
	SecondaryRawUUID           = "12BD576A2E8233DD837C3A5B5468BDE3"
	SecondarySerialNumber      = "AAAA1111"

	ValidToken = "some-valid-dummy-authentication-token"
	//nolint:gosec // dummy value, not used in the production
	RefreshToken    = "some-dummy-refresh-token"
	DefaultUsername = "admin"
	DefaultPassword = "admin"

	ServerModel = "ThinkEdge SE360 V2"
)
View Source
const (
	TestTimeout2S            = 2 * time.Second
	TestTimeout5S            = 5 * time.Second
	TestReconciliationPeriod = 1 * time.Second
	ProvisioningWeight       = 45  // %
	TotalWeight              = 100 // %

	LocaSecret            = "loca-secret"
	LocaDeviceSN          = "J900VN44"
	LocaDeviceRawUUID     = "57ED598C4B9411EE806C3A7C7693AAC3"
	LocaDeviceID          = "658c3b86f445a55d541460cf"
	LocaInstanceFlavor    = "Ubuntu 22.04.3"
	LocaInstanceID        = "658c483ef445a55d541460db"
	LocaSiteID            = "66d5a4a57bc832e5fbf72705"
	LocaSiteName          = "SANTA-CLARA"
	LocaTaskUUID          = "b3b36443-aac1-4847-aed1-80dea17226ea"
	CloudServiceTaskUUID  = "e83c81ab-415a-4377-ae47-e7355702764e"
	DefaultProviderName   = "LOC-A"
	HostStatusRunning     = "Running"
	InstanceStatusRunning = "Running"
	TaskStatusRunning     = "running"
	TaskStatusSuccessful  = "successful"

	Tenant1 = "11111111-1111-1111-1111-111111111111"
	Tenant2 = "22222222-2222-2222-2222-222222222222"
)

Variables

View Source
var (
	LocaRMClient       client.TenantAwareInventoryClient
	LocaRMEventsClient chan *client.WatchEvents
)
View Source
var (
	Responses map[string][]byte
)
View Source
var SecretServiceMock = &MockSecretsService{}

SecretServiceMock is a LOC-A specific mock of a secret service.

Functions

func ActiveDevice

func ActiveDevice(res http.ResponseWriter, req *http.Request)

func AssertHost

func AssertHost(
	t *testing.T,
	tenantID string,
	providerAPI, hostSN, hostUUID string,
	desiredState computev1.HostState,
	currentState computev1.HostState,
	onboardingStatus string,
	statusIndicator statusv1.StatusIndication,
	hostStatus string,
	hostStatusIndicator statusv1.StatusIndication,
)

func AssertInstance

func AssertInstance(
	t *testing.T,
	tenantID string,
	providerAPI, locaInstanceName string,
	desiredState computev1.InstanceState,
	currentState computev1.InstanceState,
	provisioningStatus string,
	statusIndicator statusv1.StatusIndication,
	instanceStatus string,
	instanceStatusIndicator statusv1.StatusIndication,
)

func AssertNumberHostsForProvider

func AssertNumberHostsForProvider(t *testing.T, tenantID, apiEndpoint string, numHosts int)

func AssertNumberInstancesForProvider

func AssertNumberInstancesForProvider(t *testing.T, tenantID, apiEndpoint string, numInstances int)

func BootstrapProductionEnvironment

func BootstrapProductionEnvironment(t *testing.T, tenantID, hostID, instanceID string)

BootstrapProductionEnvironment function bootstraps unit test environment to match production environment. It updates Current states of the Host and Instance to be PROVISIONED and RUNNING correspondingly and simulates the Node Agent action, i.e., setting the Host Status and the Instance Status to be both 'Running'. It also updates Onboarding and Provisioning statuses of Host and Instance to be 'active' and 'installed successfully' in order to match real situation in the running production.

func CSCrudFuncs

func CSCrudFuncs(ms *MockServer, prepopulate bool, cs *model.DtoCloudServiceListElement)

func CloseInventoryClientChannel

func CloseInventoryClientChannel(clientName string)

func CloudServicesByID2XX

func CloudServicesByID2XX(res http.ResponseWriter, req *http.Request)

func DeletedDevice

func DeletedDevice(res http.ResponseWriter, req *http.Request)

func DeletedInstanceFunc

func DeletedInstanceFunc(res http.ResponseWriter, req *http.Request)

func DeploymentInstancesCreated

func DeploymentInstancesCreated(res http.ResponseWriter, req *http.Request)

func DeploymentInstancesDeployFunc

func DeploymentInstancesDeployFunc(res http.ResponseWriter, req *http.Request)

func DeploymentInstancesPlanning

func DeploymentInstancesPlanning(res http.ResponseWriter, req *http.Request)

func DevicesFunc

func DevicesFunc(res http.ResponseWriter, req *http.Request)

func FailedRemoveDevicesFunc

func FailedRemoveDevicesFunc(res http.ResponseWriter, req *http.Request)

func FailedRemoveInstancesFunc

func FailedRemoveInstancesFunc(res http.ResponseWriter, req *http.Request)

func GetCloudServices2XX

func GetCloudServices2XX(res http.ResponseWriter, req *http.Request)

func HostCleanupByUUID

func HostCleanupByUUID(t *testing.T, c client.TenantAwareInventoryClient, tenantID, uuID string)

func HostProvisioned

func HostProvisioned(t *testing.T, tenantID, hostID string)

HostProvisioned sets the Current state of the Host to be PROVISIONED and Onboarding Status and its Indicator to correspond to the Device status 'active' reported by LOC-A. This function should be solely used only for bootstrapping unit test environment to production state, i.e., when Host is provisioned. A use case is to prepare unit test environment to the scenario: - Host was removed from LOC-A or had any other failure; - LOC-A server outage.

func InitializeInventoryClient

func InitializeInventoryClient(clientName string)

func InstanceCleanupByName

func InstanceCleanupByName(t *testing.T, c client.TenantAwareInventoryClient, tenantID, name string)

func InstanceRunning

func InstanceRunning(t *testing.T, tenantID, instanceID string)

InstanceRunning sets the Current state of the Instance to be RUNNING and Provisioning Status and its Indicator to correspond to the 'Finished successfully' status at stage 'installed' in operation 'Deploy'. This function should be solely used only for bootstrapping unit test environment to production state, i.e., when Instance is onboarded and running. A use case is to prepare unit test environment to the scenario: - Instance was removed from LOC-A or had any other failure; - LOC-A server outage.

func InstancesByIDFunc

func InstancesByIDFunc(res http.ResponseWriter, req *http.Request)

func InstancesByIDWithModify

func InstancesByIDWithModify(
	res http.ResponseWriter, _ *http.Request,
	modifyFunc func(res http.ResponseWriter, instanceResponse *model.DtoInstanceQryResponse), osResourceID string,
)

func InvalidateHost

func InvalidateHost(t *testing.T, tenantID, hostID string)

func InvalidateInstance

func InvalidateInstance(t *testing.T, tenantID, instanceID string)

func ParseUUID

func ParseUUID(t *testing.T, rawUUID string) string

func PopulateInventoryWithInstanceAndOSResource

func PopulateInventoryWithInstanceAndOSResource(
	t *testing.T,
	locaMocks []*MockServer,
	tenantID string,
	host *computev1.HostResource,
	cleanup bool,
) (
	*computev1.InstanceResource,
	*osv1.OperatingSystemResource,
)

func PopulateInventoryWithLOCAProvider

func PopulateInventoryWithLOCAProvider(t *testing.T, tenantID, providerName, locaTSURL string) *providerv1.ProviderResource

func PopulateInventoryWithOSResource

func PopulateInventoryWithOSResource(t *testing.T, locaMocks []*MockServer, tenantID string) *osv1.OperatingSystemResource

func PopulateInventoryWithSite

func PopulateInventoryWithSite(t *testing.T, tenantID, siteName string) *location_v1.SiteResource

func PopulateProviderCredentials

func PopulateProviderCredentials()

func ProvisionInstanceFunc

func ProvisionInstanceFunc(res http.ResponseWriter, req *http.Request)

func RemoveDevicesFunc

func RemoveDevicesFunc(res http.ResponseWriter, req *http.Request)

func RemoveInstancesFunc

func RemoveInstancesFunc(res http.ResponseWriter, req *http.Request)

func RequireIsNotFound

func RequireIsNotFound(t *testing.T, tenantID, resourceID string)

func ReturnEmptyResponse

func ReturnEmptyResponse(res http.ResponseWriter, _ *http.Request)

func ReturnNoInstanceByInstanceID

func ReturnNoInstanceByInstanceID(res http.ResponseWriter, _ *http.Request)

func ReturnServerUnavailable

func ReturnServerUnavailable(res http.ResponseWriter, req *http.Request)

func RunningGetTask

func RunningGetTask(res http.ResponseWriter, req *http.Request)

func SetupTenantGetterTest

func SetupTenantGetterTest()

func SimulateNodeAgentAction

func SimulateNodeAgentAction(t *testing.T, tenantID, hostID, instanceID string)

SimulateNodeAgentAction simulates the Node Agent action which happens after the Host was successfully provisioned and Instance was deployed on the Host. This function emulates the update that HRM does to the Inventory when the Node Agent kicks in and interfaces with SBI (through HRM).

func SitesCrudFuncs

func SitesCrudFuncs(ms *MockServer, prepopulate bool, site *locationv1.SiteResource)

func StartMockSecretService

func StartMockSecretService()

func StopTestingEnvironment

func StopTestingEnvironment(locaTS *MockServer, clientName string)

func SuccessfulGetTask

func SuccessfulGetTask(res http.ResponseWriter, req *http.Request)

func UpdateHostProductName

func UpdateHostProductName(t *testing.T, tenantID, resourceID, productName string) error

func UpdateHostSerialNumber

func UpdateHostSerialNumber(t *testing.T, tenantID, resourceID, sn string) error

func UpdateHostSite

func UpdateHostSite(t *testing.T, tenantID, resourceID string, site *location_v1.SiteResource) error

func UpdateInstanceCurrentStateStatusAndStatusIndicator

func UpdateInstanceCurrentStateStatusAndStatusIndicator(
	t *testing.T,
	instInv *computev1.InstanceResource,
	state computev1.InstanceState,
	provisioningStatus string,
	statusIndicator statusv1.StatusIndication,
) (
	*computev1.InstanceResource, error,
)

func UpdateOnboardingStatusAndStatusIndicator

func UpdateOnboardingStatusAndStatusIndicator(
	t *testing.T,
	hostInv *computev1.HostResource,
	onboardingStatus string,
	statusIndicator statusv1.StatusIndication,
) (
	*computev1.HostResource, error,
)

func WriteFileToResponse

func WriteFileToResponse[t any](res http.ResponseWriter, _ *http.Request, data *t, filename string, statusCode int)

func WriteFileToResponseWithModify

func WriteFileToResponseWithModify[t any](
	res http.ResponseWriter, _ *http.Request, data *t, filename string, modifyFunc func(*t),
)

func WriteStructToResponse

func WriteStructToResponse[t any](res http.ResponseWriter, _ *http.Request, data *t, statusCode int)

Types

type Credentials

type Credentials struct {
	Username string `json:"name"`
	Password string `json:"password"`
}

Credentials structure is used solely for Mock server purposes. It allows to perform a credentials check at authorization call. Default credentials are Global constants that can be exported to the other packages for unit testing purposes.

type MockSecretsService

type MockSecretsService struct {
	mock.Mock
}

func (*MockSecretsService) Logout

func (m *MockSecretsService) Logout(_ context.Context)

func (*MockSecretsService) ReadSecret

func (m *MockSecretsService) ReadSecret(_ context.Context, _ string) (map[string]interface{}, error)

func (*MockSecretsService) WriteSecret

func (m *MockSecretsService) WriteSecret(_ context.Context, _ string, _ map[string]interface{}) (map[string]interface{}, error)

type MockServer

type MockServer struct {
	TestServer *httptest.Server
	Router     *gorilla.Router
	// contains filtered or unexported fields
}

func StartDummyLOCAServer

func StartDummyLOCAServer() (*MockServer, error)

If no configuration provided, returns an empty HTTP Server.

func StartTestingEnvironment

func StartTestingEnvironment(policyPath, migrationsDir, clientName string) *MockServer

func (*MockServer) GetURL

func (ms *MockServer) GetURL() string

func (*MockServer) Override

func (ms *MockServer) Override(endpoint string, f func(http.ResponseWriter, *http.Request), methods ...string)

func (*MockServer) SeedOSResourceID

func (ms *MockServer) SeedOSResourceID(resourceID string)

func (*MockServer) SeedSiteResourceID

func (ms *MockServer) SeedSiteResourceID(siteID string)

func (*MockServer) StopDummyLOCAServer

func (ms *MockServer) StopDummyLOCAServer()

Gracefully shutdown LOC-A Mock Server.

Jump to

Keyboard shortcuts

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