Documentation ¶
Overview ¶
Package core is the backbone of the tunnel client, it defines the tunnel lifecycle and allows attaching hooks for functionality as plugins.
Index ¶
- Constants
- Variables
- type AzureClient
- type BlockTestService
- type Cache
- type CacheStore
- type CommandType
- type CommitChangeList
- type ContainerImageConfig
- type ContainerStatus
- type ContainerType
- type CoverageManifest
- type CoverageService
- type CoverageThreshold
- type DiffManager
- type DiscoveryResult
- type DockerRunner
- type EventType
- type ExecutionID
- type ExecutionManager
- type ExecutionResult
- type ExecutionResults
- type GitManager
- type JobInfo
- type LoginDetails
- type Merge
- type Message
- type MessageType
- type Modifier
- type NotifMessage
- type Oauth
- type Payload
- type PayloadManager
- type Pipeline
- type PodType
- type PostMergeStrategyName
- type Requests
- type ResourceStats
- type Run
- type RunnerOptions
- type Secret
- type SecretParser
- type SecretsManager
- type Specs
- type SplitMode
- type Stability
- type StatType
- type Status
- type StatusType
- type SynapseManager
- type TASConfig
- type TASConfigManager
- type Task
- type TaskPayload
- type TaskType
- type TestDiscoveryService
- type TestExecutionService
- type TestPayload
- type TestProcessStats
- type TestReportResponsePayload
- type TestStats
- type TestStatus
- type TestSuitePayload
- type Tier
- type TokenType
- type VaultOpts
- type VaultSecret
- type ZstdCompressor
Constants ¶
const ( // FileAdded file added in commit FileAdded int = iota + 1 // FileRemoved file removed in commit FileRemoved // FileModified file modified in commit FileModified )
const ( // GitHub as git provider GitHub string = "github" // GitLab as git provider GitLab string = "gitlab" // Bitbucket as git provider Bitbucket string = "bitbucket" )
Variables ¶
var TierOpts = map[Tier]Specs{
Internal: {CPU: 0.5, RAM: 384},
XSmall: {CPU: 1, RAM: 2000},
Small: {CPU: 2, RAM: 4000},
Medium: {CPU: 4, RAM: 8000},
Large: {CPU: 8, RAM: 16000},
XLarge: {CPU: 16, RAM: 32000},
}
TierOpts is const map which map each tier to specs
Functions ¶
This section is empty.
Types ¶
type AzureClient ¶
type AzureClient interface { FindUsingSASUrl(ctx context.Context, sasURL string) (io.ReadCloser, error) Find(ctx context.Context, path string) (io.ReadCloser, error) Create(ctx context.Context, path string, reader io.Reader, mimeType string) (string, error) CreateUsingSASURL(ctx context.Context, sasURL string, reader io.Reader, mimeType string) (string, error) GetSASURL(ctx context.Context, containerPath string, containerType ContainerType) (string, error) Exists(ctx context.Context, path string) (bool, error) }
AzureClient defines operation for working with azure store
type BlockTestService ¶
type BlockTestService interface {
GetBlockTests(ctx context.Context, tasConfig *TASConfig, repo, branch string) error
}
BlockTestService is used for fetching blocklisted tests
type Cache ¶
type Cache struct { Key string `yaml:"key" validate:"required"` Paths []string `yaml:"paths" validate:"required"` }
Cache represents the user's cached directories
type CacheStore ¶
type CacheStore interface { // Download downloads cache present at cacheKey Download(ctx context.Context, cacheKey string) error // Upload creates, compresses and uploads cache at cacheKey Upload(ctx context.Context, cacheKey string, itemsToCompress ...string) error // CacheWorkspace caches the workspace onto a mounted volume CacheWorkspace(ctx context.Context) error // ExtractWorkspace extracts the workspace cache from mounted volume ExtractWorkspace(ctx context.Context) error }
CacheStore defines operation for working with the cache
type CommandType ¶
type CommandType string
CommandType defines type of command
const ( PreRun CommandType = "prerun" PostRun CommandType = "postrun" InstallRunners CommandType = "installrunners" Execution CommandType = "execution" Discovery CommandType = "discovery" Zstd CommandType = "zstd" CoverageMerge CommandType = "coveragemerge" InstallNodeVer CommandType = "installnodeversion" InitGit CommandType = "initgit" )
Types of Command string
type CommitChangeList ¶
type CommitChangeList struct { Sha string `json:"Sha"` Link string `json:"Link"` Added []string `json:"added"` Removed []string `json:"removed"` Modified []string `json:"modified"` Message string `json:"message"` }
CommitChangeList defines information related to commits
type ContainerImageConfig ¶
type ContainerImageConfig struct { AuthRegistry string Image string Mode config.ModeType PullPolicy config.PullPolicyType }
ContainerImageConfig contains registry config for docker
type ContainerStatus ¶
ContainerStatus contains status of container
type ContainerType ¶
type ContainerType string
ContainerType defines types of container
const ( CacheContainer ContainerType = "cache" LogsContainer ContainerType = "logs" PayloadContainer ContainerType = "container-payload" )
Types of containers
type CoverageManifest ¶
type CoverageManifest struct { Removedfiles []string `json:"removed_files"` AllFilesExecuted bool `json:"all_files_executed"` CoverageThreshold *CoverageThreshold `json:"coverage_threshold,omitempty"` }
CoverageManifest for post processing coverage job
type CoverageService ¶
CoverageService services coverage of tests
type CoverageThreshold ¶
type CoverageThreshold struct { Branches float64 `yaml:"branches" json:"branches" validate:"number,min=0,max=100"` Lines float64 `yaml:"lines" json:"lines" validate:"number,min=0,max=100"` Functions float64 `yaml:"functions" json:"functions" validate:"number,min=0,max=100"` Statements float64 `yaml:"statements" json:"statements" validate:"number,min=0,max=100"` PerFile bool `yaml:"perFile" json:"perFile"` }
CoverageThreshold reprents the code coverage threshold
type DiffManager ¶
type DiffManager interface {
GetChangedFiles(ctx context.Context, payload *Payload, oauth *Oauth) (map[string]int, error)
}
DiffManager manages the diff findings for the given payload
type DiscoveryResult ¶
type DiscoveryResult struct { Tests []TestPayload `json:"tests"` ImpactedTests []string `json:"impactedTests"` TestSuites []TestSuitePayload `json:"testSuites"` ExecuteAllTests bool `json:"executeAllTests"` Parallelism int `json:"parallelism"` SplitMode SplitMode `json:"splitMode"` RepoID string `json:"repoID"` BuildID string `json:"buildID"` CommitID string `json:"commitID"` TaskID string `json:"taskID"` OrgID string `json:"orgID"` Branch string `json:"branch"` Tier Tier `json:"tier"` ContainerImage string `json:"containerImage"` }
type DockerRunner ¶
type DockerRunner interface { // Creates the execution enging Create(context.Context, *RunnerOptions) ContainerStatus // Run runs the execution engine Run(context.Context, *RunnerOptions) ContainerStatus //WaitForRunning waits for runner to get completed WaitForCompletion(ctx context.Context, r *RunnerOptions) error // Destroy the execution engine Destroy(ctx context.Context, r *RunnerOptions) error // GetInfo will get resources details of the infra GetInfo(context.Context) (float32, int64) // Initiate runs docker containers Initiate(context.Context, *RunnerOptions, chan ContainerStatus) // PullImage will pull image from remote PullImage(containerImageConfig *ContainerImageConfig, r *RunnerOptions) error // KillRunningDocker kills container spawn by synapse KillRunningDocker(ctx context.Context) }
DockerRunner defines operations for docker
type ExecutionManager ¶
type ExecutionManager interface { // ExecuteUserCommands executes the preRun or postRun commands given by user in his yaml. ExecuteUserCommands(ctx context.Context, commandType CommandType, payload *Payload, runConfig *Run, secretData map[string]string) error // ExecuteInternalCommands executes the commands like installing runners and test discovery. ExecuteInternalCommands(ctx context.Context, commandType CommandType, commands []string, cwd string, envMap, secretData map[string]string) error // GetEnvVariables get the environment variables from the env map given by user. GetEnvVariables(envMap, secretData map[string]string) ([]string, error) // StoreCommandLogs stores the command logs in the azure. StoreCommandLogs(ctx context.Context, blobPath string, reader io.Reader) <-chan error }
ExecutionManager has responsibility for executing the preRun, postRun and internal commands
type ExecutionResult ¶
type ExecutionResult struct { TestPayload []TestPayload `json:"testResults"` TestSuitePayload []TestSuitePayload `json:"testSuiteResults"` }
ExecutionResult represents the request body for test and test suite execution
type ExecutionResults ¶
type ExecutionResults struct { TaskID string `json:"taskID"` BuildID string `json:"buildID"` RepoID string `json:"repoID"` OrgID string `json:"orgID"` CommitID string `json:"commitID"` TaskType TaskType `json:"taskType"` Results []ExecutionResult `json:"results"` }
ExecutionResults represents collection of execution results
type GitManager ¶
type GitManager interface { // Clone repository from TAS config Clone(ctx context.Context, payload *Payload, oauth *Oauth) error }
GitManager manages the cloning of git repositories
type JobInfo ¶
type JobInfo struct { Status StatusType `json:"status"` JobID string `json:"job_id"` ID string `json:"id"` Mode string `json:"mode"` BuildID string `json:"build_id"` }
JobInfo stuct for job updates info
type LoginDetails ¶
type LoginDetails struct { Name string `json:"name"` SynapseID string `json:"synapse_id"` SecretKey string `json:"secret_key"` CPU float32 `json:"cpu"` RAM int64 `json:"ram"` }
LoginDetails struct
type Merge ¶
type Merge struct { Patterns []string `yaml:"pattern" validate:"required,gt=0"` EnvMap map[string]string `yaml:"env" validate:"omitempty,gt=0"` }
Merge represents pre and post merge
type Message ¶
type Message struct { Type MessageType `json:"type"` Content []byte `json:"content"` Success bool `json:"success"` }
Message struct
type MessageType ¶
type MessageType string
MessageType defines type of message
const ( MsgLogin MessageType = "login" MsgLogout MessageType = "logout" MsgTask MessageType = "task" MsgInfo MessageType = "info" MsgError MessageType = "error" MsgResourceStats MessageType = "resourcestats" MsgJobInfo MessageType = "jobinfo" )
types of messages
type NotifMessage ¶
NotifMessage defines struct for notification message
type Oauth ¶
type Oauth struct { AccessToken string `json:"access_token"` Expiry time.Time `json:"expiry"` RefreshToken string `json:"refresh_token"` Type TokenType `json:"token_type,omitempty"` }
Oauth represents the sructure of Oauth
type Payload ¶
type Payload struct { RepoSlug string `json:"repo_slug"` ForkSlug string `json:"fork_slug"` RepoLink string `json:"repo_link"` BuildTargetCommit string `json:"build_target_commit"` BuildBaseCommit string `json:"build_base_commit"` TaskID string `json:"task_id"` BranchName string `json:"branch_name"` BuildID string `json:"build_id"` RepoID string `json:"repo_id"` OrgID string `json:"org_id"` GitProvider string `json:"git_provider"` PrivateRepo bool `json:"private_repo"` EventType EventType `json:"event_type"` Diff string `json:"diff_url"` PullRequestNumber int `json:"pull_request_number"` Commits []CommitChangeList `json:"commits"` TasFileName string `json:"tas_file_name"` Locators string `json:"locators"` LocatorAddress string `json:"locator_address"` ParentCommitCoverageExists bool `json:"parent_commit_coverage_exists"` LicenseTier Tier `json:"license_tier"` CollectCoverage bool `json:"collect_coverage"` TaskType TaskType `json:"-"` }
Payload defines structure of payload
type PayloadManager ¶
type PayloadManager interface { // ValidatePayload validates the nucleus payload ValidatePayload(ctx context.Context, payload *Payload) error // FetchPayload used for fetching the payload used for running nucleus FetchPayload(ctx context.Context, payloadAddress string) (*Payload, error) }
PayloadManager defines operations for payload
type Pipeline ¶
type Pipeline struct { Cfg *config.NucleusConfig Payload *Payload Logger lumber.Logger PayloadManager PayloadManager TASConfigManager TASConfigManager GitManager GitManager ExecutionManager ExecutionManager DiffManager DiffManager CacheStore CacheStore TestDiscoveryService TestDiscoveryService BlockTestService BlockTestService TestExecutionService TestExecutionService CoverageService CoverageService TestStats TestStats Task Task SecretParser SecretParser HTTPClient http.Client }
Pipeline defines all attributes of Pipeline
func NewPipeline ¶
NewPipeline creates and returns a new Pipeline instance
type PostMergeStrategyName ¶
type PostMergeStrategyName string
PostMergeStrategyName type
const (
AfterNCommitStrategy PostMergeStrategyName = "after_n_commits"
)
All const of type PostMergeStrategyName
type Requests ¶
type Requests interface { // MakeAPIRequest makes an HTTP request MakeAPIRequest(ctx context.Context, httpMethod, endpoint string, body []byte) ([]byte, error) }
Requests is a util interface for making API Requests
type ResourceStats ¶
type ResourceStats struct { Status StatType `json:"status"` CPU float32 `json:"cpu"` RAM int64 `json:"ram"` }
ResourceStats struct for CPU, RAM details
type Run ¶
type Run struct { Commands []string `yaml:"command" validate:"omitempty,gt=0"` EnvMap map[string]string `yaml:"env" validate:"omitempty,gt=0"` }
Run represents pre and post runs
type RunnerOptions ¶
type RunnerOptions struct { ContainerID string `json:"container_id"` DockerImage string `json:"docker_image"` ContainerPort int `json:"container_port"` HostPort int `json:"host_port"` Label map[string]string `json:"label"` NameSpace string `json:"name_space"` ServiceAccount string `json:"service_account"` PodName string `json:"pod_name"` ContainerName string `json:"container_name"` ContainerArgs []string `json:"container_args"` ContainerCommands []string `json:"container_commands"` HostVolumePath string `json:"host_volume_path"` PersistentVolumeClaimName string `json:"persistent_volume_claim_name"` Env []string `json:"env"` OrgID string `json:"org_id"` Vault *VaultOpts `json:"vault"` LogfilePath string `json:"logfile_path"` PodType PodType `json:"pod_type"` Tier Tier `json:"tier"` }
RunnerOptions provides the the required instructions for execution engine.
type SecretParser ¶
type SecretParser interface { // GetOauthSecret parses the oauth secret for given path GetOauthSecret(filepath string) (*Oauth, error) // GetRepoSecret parses the repo secret for given path GetRepoSecret(string) (map[string]string, error) // SubstituteSecret replace secret placeholders with their respective values SubstituteSecret(command string, secretData map[string]string) (string, error) // Expired reports whether the token is expired. Expired(token *Oauth) bool }
SecretParser defines operation for parsing the vault secrets in given path
type SecretsManager ¶
type SecretsManager interface { // GetLambdatestSecrets returns lambdatest config GetLambdatestSecrets() *config.LambdatestConfig // WriteGitSecrets writes git secrets to file WriteGitSecrets(path string) error // WriteRepoSecrets writes repo secrets to file WriteRepoSecrets(repo string, path string) error // GetDockerSecrets returns Mode , RegistryAuth, and URL for pulling remote docker image GetDockerSecrets(r *RunnerOptions) (ContainerImageConfig, error) // GetSynapseName returns synapse name mentioned in config GetSynapseName() string }
SecretsManager defines operation for secrets
type Stability ¶
type Stability struct {
ConsecutiveRuns int `yaml:"consecutive_runs"`
}
Stability defines struct for stability
type StatusType ¶
type StatusType string
StatusType defines type job status
const ( JobCompleted StatusType = "complete" JobStarted StatusType = "started" JobFailed StatusType = "failed" )
JobInfo types
type SynapseManager ¶
type SynapseManager interface { // InitiateConnection initiates the connection with LT cloud InitiateConnection(ctx context.Context, wg *sync.WaitGroup, connectionFailed chan struct{}) }
SynapseManager denfines operations for synapse client
type TASConfig ¶
type TASConfig struct { SmartRun bool `yaml:"smartRun"` Framework string `yaml:"framework" validate:"required,oneof=jest mocha jasmine"` Blocklist []string `yaml:"blocklist"` Postmerge *Merge `yaml:"postMerge" validate:"omitempty"` Premerge *Merge `yaml:"preMerge" validate:"omitempty"` Cache *Cache `yaml:"cache" validate:"omitempty"` Prerun *Run `yaml:"preRun" validate:"omitempty"` Postrun *Run `yaml:"postRun" validate:"omitempty"` Parallelism int `yaml:"parallelism"` SplitMode SplitMode `yaml:"splitMode" validate:"oneof=test file"` SkipCache bool `yaml:"skipCache"` ConfigFile string `yaml:"configFile" validate:"omitempty"` CoverageThreshold *CoverageThreshold `yaml:"coverageThreshold" validate:"omitempty"` Tier Tier `yaml:"tier" validate:"oneof=xsmall small medium large xlarge"` NodeVersion string `yaml:"nodeVersion" validate:"omitempty,semver"` ContainerImage string `yaml:"containerImage"` }
TASConfig represents the .tas.yml file
type TASConfigManager ¶
type TASConfigManager interface { // LoadAndValidate loads and validates the TASConfig from the given path LoadAndValidate(ctx context.Context, path string, eventType EventType, licenseTier Tier) (*TASConfig, error) }
TASConfigManager defines operations for tas config
type Task ¶
type Task interface { // UpdateStatus updates status of the task UpdateStatus(ctx context.Context, payload *TaskPayload) error }
Task is a service to update task status at neuron
type TaskPayload ¶
type TaskPayload struct { TaskID string `json:"task_id"` Status Status `json:"status"` RepoSlug string `json:"repo_slug"` RepoLink string `json:"repo_link"` RepoID string `json:"repo_id"` OrgID string `json:"org_id"` GitProvider string `json:"git_provider"` CommitID string `json:"commit_id,omitempty"` BuildID string `json:"build_id"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time,omitempty"` Remark string `json:"remark,omitempty"` Type TaskType `json:"type"` }
TaskPayload repersent task response given by nucleus to neuron
type TestDiscoveryService ¶
type TestDiscoveryService interface { // Discover executes the test discovery scripts. Discover(ctx context.Context, tasConfig *TASConfig, payload *Payload, secretData map[string]string, diff map[string]int, diffExists bool) error }
TestDiscoveryService services discovery of tests
type TestExecutionService ¶
type TestExecutionService interface { // Run executes the test execution scripts. Run(ctx context.Context, tasConfig *TASConfig, payload *Payload, coverageDirectory string, secretMap map[string]string) (results *ExecutionResults, err error) // SendResults sends the test execution results to the TAS server. SendResults(ctx context.Context, payload *ExecutionResults) (resp *TestReportResponsePayload, err error) }
TestExecutionService services execution of tests
type TestPayload ¶
type TestPayload struct { TestID string `json:"testID"` Detail string `json:"_detail"` SuiteID string `json:"suiteID"` Suites []string `json:"_suites"` Title string `json:"title"` FullTitle string `json:"fullTitle"` Name string `json:"name"` Duration int `json:"duration"` FilePath string `json:"file"` Line string `json:"line"` Col string `json:"col"` CurrentRetry int `json:"currentRetry"` Status string `json:"status"` CommitID string `json:"commitID"` DAG []string `json:"dependsOn"` Filelocator string `json:"locator"` BlocklistSource string `json:"blocklistSource"` Blocklisted bool `json:"blocklist"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` Stats []TestProcessStats `json:"stats"` }
TestPayload represents the request body for test execution
type TestProcessStats ¶
type TestProcessStats struct { Memory uint64 `json:"memory_consumed,omitempty"` CPU float64 `json:"cpu_percentage,omitempty"` Storage uint64 `json:"storage,omitempty"` RecordTime time.Time `json:"record_time"` }
TestProcessStats process stats associated with each test
type TestReportResponsePayload ¶ added in v0.3.1
type TestReportResponsePayload struct { TaskID string `json:"taskID"` TaskStatus Status `json:"taskStatus"` Remark string `json:"remark,omitempty"` }
TestReportResponsePayload represents the response body for test and test suite report api.
type TestStatus ¶
type TestStatus string
TestStatus stores tests status
const ( Blocklisted TestStatus = "blocklisted" Quarantined TestStatus = "quarantined" )
type TestSuitePayload ¶
type TestSuitePayload struct { SuiteID string `json:"suiteID"` SuiteName string `json:"suiteName"` ParentSuiteID string `json:"parentSuiteID"` BlocklistSource string `json:"blocklistSource"` Blocklisted bool `json:"blocklist"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` Duration int `json:"duration"` Status string `json:"status"` Stats []TestProcessStats `json:"stats"` TotalTests int `json:"totalTests"` }
TestSuitePayload represents the request body for test suite execution
type VaultOpts ¶
type VaultOpts struct { // SecretPath path of the repo secrets. SecretPath string // TokenPath path of the user token. TokenPath string // RoleName vault role name RoleName string // Namespace is the default vault namespace Namespace string }
VaultOpts provides the vault path options
type VaultSecret ¶
type VaultSecret struct {
Secrets Secret `json:"data"`
}
VaultSecret holds secrets in vault format
type ZstdCompressor ¶
type ZstdCompressor interface { Compress(ctx context.Context, compressedFileName string, preservePath bool, workingDirectory string, filesToCompress ...string) error Decompress(ctx context.Context, filePath string, preservePath bool, workingDirectory string) error }
ZstdCompressor performs zstd compression and decompression