Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StageHarness ¶
type StageHarness struct {
// Logger is to be used for all logs generated from the test function.
Logger *logger.Logger
// Executable is the program to be tested.
Executable *executable.Executable
// contains filtered or unexported fields
}
StageHarness is passed to your Stage's TestFunc.
If the program is a long-lived program that must be alive during the duration of the test (like a Redis server), do something like this at the start of your test function:
if err := stageHarness.Executable.Start(); err != nil {
return err
}
stageHarness.RegisterTeardownFunc(func() { stageHarness.Executable.Kill() })
If the program is a script that must be executed and then checked for output (like a Git command), use it like this:
result, err := stageHarness.Executable.Run("cat-file", "-p", "sha")
if err != nil {
return err
}
func (*StageHarness) RegisterTeardownFunc ¶ added in v0.1.13
func (s *StageHarness) RegisterTeardownFunc(teardownFunc func())
func (StageHarness) RunTeardownFuncs ¶ added in v0.1.13
func (s StageHarness) RunTeardownFuncs()
type TestCase ¶ added in v0.2.0
type TestCase struct {
// Slug is the unique identifier for this test case. For now, it must match the slug of the stage from the course's YAML definition.
Slug string
// TestFunc is the function that'll be run against the user's code.
TestFunc func(stageHarness *StageHarness) error
// Timeout is the maximum amount of time that the test case can run for.
Timeout time.Duration
}
TestCase represents a test case that'll be run against the user's code.
For now, we only support one test case per stage. This may change in the future.
We enforce the one-test-case-per-stage rule by requiring that the test case's slug matches the stage's slug (from the YAML definition).
func (TestCase) CustomOrDefaultTimeout ¶ added in v0.2.0
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
func NewTester ¶
func NewTester(env map[string]string, definition TesterDefinition) (Tester, error)
NewTester creates a Tester based on the TesterDefinition provided
func (Tester) PrintDebugContext ¶
func (tester Tester) PrintDebugContext()
func (Tester) RunAntiCheatStages ¶
RunAntiCheatStages runs any anti-cheat stages specified in the TesterDefinition. Only critical logs are emitted. If the stages pass, the user won't see any visible output.
type TesterDefinition ¶
type TesterDefinition struct {
// Example: spawn_redis_server.sh
ExecutableFileName string
TestCases []TestCase
AntiCheatTestCases []TestCase
}
func (TesterDefinition) TestCaseBySlug ¶ added in v0.2.0
func (t TesterDefinition) TestCaseBySlug(slug string) TestCase