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:
Wink Saville 2020-11-29 21:45:11 -08:00 committed by GitHub
parent b3299ecd30
commit d784bce96a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,68 +31,75 @@ func TestGraphEvent(t *testing.T) {
assert.Equal(t, len(plan.Stages), 0, "stages") 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) { func TestRunEvent(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping integration test") t.Skip("skipping integration test")
} }
tables := []struct { platforms := map[string]string{
workflowPath string "ubuntu-latest": "node:12.6-buster-slim",
eventName string }
errorMessage string tables := []TestJobFileInfo{
}{ {"testdata", "basic", "push", "", platforms},
{"basic", "push", ""}, {"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms},
{"fail", "push", "exit with `FAILURE`: 1"}, {"testdata", "runs-on", "push", "", platforms},
{"runs-on", "push", ""}, {"testdata", "job-container", "push", "", platforms},
{"job-container", "push", ""}, {"testdata", "job-container-non-root", "push", "", platforms},
{"job-container-non-root", "push", ""}, {"testdata", "uses-docker-url", "push", "", platforms},
{"uses-docker-url", "push", ""}, {"testdata", "remote-action-docker", "push", "", platforms},
{"remote-action-docker", "push", ""}, {"testdata", "remote-action-js", "push", "", platforms},
{"remote-action-js", "push", ""}, {"testdata", "local-action-docker-url", "push", "", platforms},
{"local-action-docker-url", "push", ""}, {"testdata", "local-action-dockerfile", "push", "", platforms},
{"local-action-dockerfile", "push", ""}, {"testdata", "local-action-js", "push", "", platforms},
{"local-action-js", "push", ""}, {"testdata", "matrix", "push", "", platforms},
{"matrix", "push", ""}, {"testdata", "commands", "push", "", platforms},
{"commands", "push", ""}, {"testdata", "workdir", "push", "", platforms},
{"workdir", "push", ""}, //{"testdata", "issue-228", "push", "", platforms}, // TODO [igni]: Remove this once everything passes
//{"issue-228", "push", ""}, // TODO [igni]: Remove this once everything passes {"testdata", "defaults-run", "push", "", platforms},
{"defaults-run", "push", ""},
} }
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
ctx := context.Background() ctx := context.Background()
for _, table := range tables { for _, table := range tables {
table := table runTestJobFile(ctx, t, 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)
}
})
} }
} }