Skip to content

Commit

Permalink
Create new TestPythonCache
Browse files Browse the repository at this point in the history
Test issue #416. With PR #423 the test passes and fails otherwise.

To facilitate this new test I refactored RunTestJobFile out of
TestRunEvent and use it in TestRunEvent and TestPythonCache
  • Loading branch information
winksaville committed Nov 17, 2020
1 parent 3a4d951 commit 88ba816
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 51 deletions.
124 changes: 73 additions & 51 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,68 +31,90 @@ 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 TestPythonCache(t *testing.T) {
platforms := map[string]string{
"ubuntu-latest": "winksaville/ubuntu-dev:20.04",
}
RunTestJobFile(context.Background(), t,
TestJobFileInfo{
"testdata",
"python-cache",
"push",
"",
platforms,
},
)
}

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)
}
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/runner/testdata/python-cache/python_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: t1

on: push

jobs:
build:

name: Linux build and test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Python cache
id: python-cache
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}

- name: Done
run: echo Done

0 comments on commit 88ba816

Please sign in to comment.