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 ¶
This section is empty.
Types ¶
type Project ¶
type Project struct {
// contains filtered or unexported fields
}
Project represents a testing project for E2E tests.
func GetTestProject ¶
GetTestProject 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.
Example ¶
package main
import (
"fmt"
"os"
"testing"
"github.com/keboola/go-utils/pkg/testproject"
)
func main() {
// In some test ...
t := &testing.T{}
// 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 := testproject.GetTestProject(t)
fmt.Printf("Project %d locked.\n", project1.ID())
project2 := testproject.GetTestProject(t)
fmt.Printf("Project %d locked.\n", project2.ID())
project3 := testproject.GetTestProject(t)
fmt.Printf("Project %d locked.\n", project3.ID())
// Project lock will be automatically released at the end of the test.
}
Output: Project 1234 locked. Project 3456 locked. Project 5678 locked.
func (*Project) StorageAPIHost ¶
StorageAPIHost returns Storage API host of the project stack.
func (*Project) StorageAPIToken ¶
StorageAPIToken returns Storage API token of the project.