act/pkg/runner/runner_test.go

91 lines
2.4 KiB
Go
Raw Normal View History

2020-02-04 18:38:41 -06:00
package runner
2019-01-31 01:53:39 -06:00
import (
"context"
"fmt"
2020-02-24 12:56:49 -06:00
"path/filepath"
2019-01-31 01:53:39 -06:00
"testing"
"github.com/nektos/act/pkg/model"
2019-01-31 01:53:39 -06:00
log "github.com/sirupsen/logrus"
"gotest.tools/assert"
)
func TestGraphEvent(t *testing.T) {
planner, err := model.NewWorkflowPlanner("testdata/basic")
assert.NilError(t, err)
plan := planner.PlanEvent("push")
assert.NilError(t, err)
assert.Equal(t, len(plan.Stages), 3, "stages")
assert.Equal(t, len(plan.Stages[0].Runs), 1, "stage0.runs")
assert.Equal(t, len(plan.Stages[1].Runs), 1, "stage1.runs")
assert.Equal(t, len(plan.Stages[2].Runs), 1, "stage2.runs")
assert.Equal(t, plan.Stages[0].Runs[0].JobID, "check", "jobid")
assert.Equal(t, plan.Stages[1].Runs[0].JobID, "build", "jobid")
assert.Equal(t, plan.Stages[2].Runs[0].JobID, "test", "jobid")
plan = planner.PlanEvent("release")
assert.Equal(t, len(plan.Stages), 0, "stages")
}
2019-01-31 01:53:39 -06:00
func TestRunEvent(t *testing.T) {
2019-02-07 11:09:19 -06:00
if testing.Short() {
t.Skip("skipping integration test")
}
2019-01-31 01:53:39 -06:00
tables := []struct {
workflowPath string
eventName string
errorMessage string
}{
{"basic", "push", ""},
{"fail", "push", "exit with `FAILURE`: 1"},
{"runs-on", "push", ""},
{"job-container", "push", ""},
{"uses-docker-url", "push", ""},
{"remote-action-docker", "push", ""},
{"remote-action-js", "push", ""},
{"local-action-docker-url", "push", ""},
{"local-action-dockerfile", "push", ""},
{"matrix", "push", ""},
{"commands", "push", ""},
2019-01-31 01:53:39 -06:00
}
log.SetLevel(log.DebugLevel)
ctx := context.Background()
2019-01-31 01:53:39 -06:00
for _, table := range tables {
2019-05-22 23:39:57 -05:00
table := table
t.Run(table.workflowPath, func(t *testing.T) {
platforms := map[string]string{
2020-02-22 00:19:59 -06:00
"ubuntu-latest": "node:12.6-buster-slim",
}
2020-02-24 12:56:49 -06:00
workdir, err := filepath.Abs("testdata")
assert.NilError(t, err, table.workflowPath)
runnerConfig := &Config{
2020-02-24 12:56:49 -06:00
Workdir: workdir,
EventName: table.eventName,
Platforms: platforms,
2020-02-22 00:19:59 -06:00
ReuseContainers: false,
2019-05-22 23:39:57 -05:00
}
runner, err := New(runnerConfig)
2019-01-31 01:53:39 -06:00
assert.NilError(t, err, table.workflowPath)
2019-05-22 23:39:57 -05:00
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)
2019-05-22 23:39:57 -05:00
if table.errorMessage == "" {
assert.NilError(t, err, table.workflowPath)
} else {
assert.ErrorContains(t, err, table.errorMessage)
}
})
2019-01-31 01:53:39 -06:00
}
}