testproject

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 9 Imported by: 3

Documentation

Overview

Package testproject implements locking of Keboola Projects for E2E parallel tests.

Project is locked: - at the host level (flock.Flock) - at the goroutines level (sync.Mutex)

Only one test can access the project at a time. See GetTestProject function. If there is no unlocked project, the function waits until a project is released. Project lock is automatically released at the end of the test.

Package can be safely used in parallel tests that run on a single host. Locking between multiple hosts is not provided.

The state of the project does not change automatically, if you need an empty project use storageapi.CleanProjectRequest.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTestProject

func GetTestProject() (*Project, UnlockFn, error)

GetTestProject locks and returns a testing project specified in TEST_KBC_PROJECTS environment variable. The returned UnlockFn function must be called to free project, when the project is no longer used (e.g. defer unlockFn()) If no project is available, the function waits until a project is released.

Example
// There is TEST_KBC_PROJECTS environment variable.
// Format is: <storage_api_host>|<project_id>|<token>;...
def1 := "connection.keboola.com|1234|1234-abcdef;"
def2 := "connection.keboola.com|3456|3456-abcdef;"
def3 := "connection.keboola.com|5678|5678-abcdef;"
_ = os.Setenv("TEST_KBC_PROJECTS", def1+def2+def3)

// Acquire exclusive access to the project.
project1, unlockFn1, _ := GetTestProject()
defer unlockFn1()
fmt.Printf("Project %d locked.\n", project1.ID())
project2, unlockFn2, _ := GetTestProject()
defer unlockFn2()
fmt.Printf("Project %d locked.\n", project2.ID())
project3, unlockFn3, _ := GetTestProject()
defer unlockFn3()
fmt.Printf("Project %d locked.\n", project3.ID())

// The returned UnlockFn function must be called to free project, when the project is no longer used (e.g. defer unlockFn())

// See also TestGetTestProjectForTest for usage in a test.
Output:

Project 1234 locked.
Project 3456 locked.
Project 5678 locked.

Types

type Project

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

Project represents a testing project for E2E tests.

func GetTestProjectForTest added in v0.3.0

func GetTestProjectForTest(t *testing.T) (*Project, error)

GetTestProjectForTest locks and returns a testing project specified in TEST_KBC_PROJECTS environment variable. Project lock is automatically released at the end of the test. If no project is available, the function waits until a project is released.

func (*Project) ID

func (p *Project) ID() int

ID returns id of the project.

func (*Project) StorageAPIHost

func (p *Project) StorageAPIHost() string

StorageAPIHost returns Storage API host of the project stack.

func (*Project) StorageAPIToken

func (p *Project) StorageAPIToken() string

StorageAPIToken returns Storage API token of the project.

type UnlockFn added in v0.3.0

type UnlockFn func()

Jump to

Keyboard shortcuts

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