Extract runTestJobFile from TestRunEvent (#429)
This will allow other tests to be created in runner_test.go that can be tested individually.
This commit is contained in:
parent
b3299ecd30
commit
d784bce96a
1 changed files with 58 additions and 51 deletions
|
@ -31,68 +31,75 @@ func TestGraphEvent(t *testing.T) {
|
|||
assert.Equal(t, len(plan.Stages), 0, "stages")
|
||||
}
|
||||
|
||||
type TestJobFileInfo struct {
|
||||
workdir string
|
||||
workflowPath string
|
||||
eventName string
|
||||
errorMessage string
|
||||
platforms map[string]string
|
||||
}
|
||||
|
||||
func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
|
||||
t.Run(tjfi.workflowPath, func(t *testing.T) {
|
||||
workdir, err := filepath.Abs(tjfi.workdir)
|
||||
assert.NilError(t, err, workdir)
|
||||
fullWorkflowPath := filepath.Join(workdir, tjfi.workflowPath)
|
||||
runnerConfig := &Config{
|
||||
Workdir: workdir,
|
||||
BindWorkdir: true,
|
||||
EventName: tjfi.eventName,
|
||||
Platforms: tjfi.platforms,
|
||||
ReuseContainers: false,
|
||||
}
|
||||
runner, err := New(runnerConfig)
|
||||
assert.NilError(t, err, tjfi.workflowPath)
|
||||
|
||||
planner, err := model.NewWorkflowPlanner(fullWorkflowPath)
|
||||
assert.NilError(t, err, fullWorkflowPath)
|
||||
|
||||
plan := planner.PlanEvent(tjfi.eventName)
|
||||
|
||||
err = runner.NewPlanExecutor(plan)(ctx)
|
||||
if tjfi.errorMessage == "" {
|
||||
assert.NilError(t, err, fullWorkflowPath)
|
||||
} else {
|
||||
assert.ErrorContains(t, err, tjfi.errorMessage)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunEvent(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
tables := []struct {
|
||||
workflowPath string
|
||||
eventName string
|
||||
errorMessage string
|
||||
}{
|
||||
{"basic", "push", ""},
|
||||
{"fail", "push", "exit with `FAILURE`: 1"},
|
||||
{"runs-on", "push", ""},
|
||||
{"job-container", "push", ""},
|
||||
{"job-container-non-root", "push", ""},
|
||||
{"uses-docker-url", "push", ""},
|
||||
{"remote-action-docker", "push", ""},
|
||||
{"remote-action-js", "push", ""},
|
||||
{"local-action-docker-url", "push", ""},
|
||||
{"local-action-dockerfile", "push", ""},
|
||||
{"local-action-js", "push", ""},
|
||||
{"matrix", "push", ""},
|
||||
{"commands", "push", ""},
|
||||
{"workdir", "push", ""},
|
||||
//{"issue-228", "push", ""}, // TODO [igni]: Remove this once everything passes
|
||||
{"defaults-run", "push", ""},
|
||||
platforms := map[string]string{
|
||||
"ubuntu-latest": "node:12.6-buster-slim",
|
||||
}
|
||||
tables := []TestJobFileInfo{
|
||||
{"testdata", "basic", "push", "", platforms},
|
||||
{"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms},
|
||||
{"testdata", "runs-on", "push", "", platforms},
|
||||
{"testdata", "job-container", "push", "", platforms},
|
||||
{"testdata", "job-container-non-root", "push", "", platforms},
|
||||
{"testdata", "uses-docker-url", "push", "", platforms},
|
||||
{"testdata", "remote-action-docker", "push", "", platforms},
|
||||
{"testdata", "remote-action-js", "push", "", platforms},
|
||||
{"testdata", "local-action-docker-url", "push", "", platforms},
|
||||
{"testdata", "local-action-dockerfile", "push", "", platforms},
|
||||
{"testdata", "local-action-js", "push", "", platforms},
|
||||
{"testdata", "matrix", "push", "", platforms},
|
||||
{"testdata", "commands", "push", "", platforms},
|
||||
{"testdata", "workdir", "push", "", platforms},
|
||||
//{"testdata", "issue-228", "push", "", platforms}, // TODO [igni]: Remove this once everything passes
|
||||
{"testdata", "defaults-run", "push", "", platforms},
|
||||
}
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.workflowPath, func(t *testing.T) {
|
||||
platforms := map[string]string{
|
||||
"ubuntu-latest": "node:12.6-buster-slim",
|
||||
}
|
||||
|
||||
workdir, err := filepath.Abs("testdata")
|
||||
assert.NilError(t, err, table.workflowPath)
|
||||
runnerConfig := &Config{
|
||||
Workdir: workdir,
|
||||
BindWorkdir: true,
|
||||
EventName: table.eventName,
|
||||
Platforms: platforms,
|
||||
ReuseContainers: false,
|
||||
}
|
||||
runner, err := New(runnerConfig)
|
||||
assert.NilError(t, err, table.workflowPath)
|
||||
|
||||
planner, err := model.NewWorkflowPlanner(fmt.Sprintf("testdata/%s", table.workflowPath))
|
||||
assert.NilError(t, err, table.workflowPath)
|
||||
|
||||
plan := planner.PlanEvent(table.eventName)
|
||||
|
||||
err = runner.NewPlanExecutor(plan)(ctx)
|
||||
if table.errorMessage == "" {
|
||||
assert.NilError(t, err, table.workflowPath)
|
||||
} else {
|
||||
assert.ErrorContains(t, err, table.errorMessage)
|
||||
}
|
||||
})
|
||||
runTestJobFile(ctx, t, table)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue