This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from taskcluster/docker-integration-test
Docker integration test
- Loading branch information
Showing
6 changed files
with
271 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// +build linux,docker | ||
|
||
package dockertest | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/taskcluster/slugid-go/slugid" | ||
"github.com/taskcluster/taskcluster-worker/worker/workertest" | ||
) | ||
|
||
func TestArtifacts(t *testing.T) { | ||
debug("### Testing artifact plugin with docker engine") | ||
filename := slugid.Nice() | ||
debug("generated filename: %s", filename) | ||
|
||
workertest.Case{ | ||
Engine: "docker", | ||
Concurrency: 1, | ||
EngineConfig: engineConfig, | ||
PluginConfig: pluginConfig, | ||
Tasks: workertest.Tasks([]workertest.Task{{ | ||
Title: "Artifact File", | ||
Success: true, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "echo 'hello-world' && echo 42 > /my-file-` + filename + `.txt"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes", | ||
"artifacts": [ | ||
{ | ||
"name": "public/result.txt", | ||
"type": "file", | ||
"path": "/my-file-` + filename + `.txt" | ||
} | ||
] | ||
}`, | ||
Artifacts: workertest.ArtifactAssertions{ | ||
"public/logs/live.log": workertest.ReferenceArtifact(), | ||
"public/logs/live_backing.log": workertest.GrepArtifact("hello-world"), | ||
"public/result.txt": workertest.GrepArtifact("42"), | ||
}, | ||
}, { | ||
Title: "Artifact Directory", | ||
Success: true, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "` + strings.Join([]string{ | ||
"echo 'hello-world'", | ||
"mkdir -p /sub/subsub/subsubsub", | ||
"echo 42 > /sub/subsub/result.txt", | ||
"echo -n '<html></html>' > /sub/subsub/subsubsub/result.html", | ||
}, " && ") + `"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes", | ||
"artifacts": [ | ||
{ | ||
"name": "public", | ||
"type": "directory", | ||
"path": "/sub" | ||
} | ||
] | ||
}`, | ||
Artifacts: workertest.ArtifactAssertions{ | ||
"public/logs/live.log": workertest.ReferenceArtifact(), | ||
"public/logs/live_backing.log": workertest.GrepArtifact("hello-world"), | ||
"public/subsub/result.txt": workertest.GrepArtifact("42"), | ||
"public/subsub/subsubsub/result.html": workertest.MatchArtifact("<html></html>", "text/html; charset=utf-8"), | ||
}, | ||
}, { | ||
Title: "Artifact Directory Is File", | ||
Success: false, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "echo 42 > /notafolder"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes", | ||
"artifacts": [ | ||
{ | ||
"name": "public/myfolder", | ||
"type": "directory", | ||
"path": "/notafolder" | ||
} | ||
] | ||
}`, | ||
Artifacts: workertest.ArtifactAssertions{ | ||
"public/logs/live.log": workertest.ReferenceArtifact(), | ||
"public/logs/live_backing.log": workertest.GrepArtifact("/notafolder"), | ||
"public/myfolder": workertest.ErrorArtifact(), | ||
}, | ||
}, { | ||
Title: "Artifact File Is Directory", | ||
Success: false, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "mkdir -p /sub/subsub/ && echo 42 > /sub/subsub/result.txt"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes", | ||
"artifacts": [ | ||
{ | ||
"name": "public/subsub", | ||
"type": "file", | ||
"path": "/sub/subsub" | ||
} | ||
] | ||
}`, | ||
Artifacts: workertest.ArtifactAssertions{ | ||
// Expect some error message saying "sub/subsub" | ||
"public/logs/live.log": workertest.ReferenceArtifact(), | ||
"public/logs/live_backing.log": workertest.GrepArtifact("/sub/subsub"), | ||
"public/subsub": workertest.ErrorArtifact(), | ||
}, | ||
}, { | ||
Title: "Artifact File Not Found", | ||
Success: false, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["true"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes", | ||
"artifacts": [ | ||
{ | ||
"name": "public/result.txt", | ||
"type": "file", | ||
"path": "/no-such-file-` + filename + `.txt" | ||
} | ||
] | ||
}`, | ||
Artifacts: workertest.ArtifactAssertions{ | ||
"public/logs/live.log": workertest.ReferenceArtifact(), | ||
"public/logs/live_backing.log": workertest.GrepArtifact("/no-such-file-" + filename + ".txt"), | ||
"public/result.txt": workertest.ErrorArtifact(), | ||
}, | ||
}, { | ||
Title: "Artifact Directory Not Found", | ||
Success: false, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "true"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes", | ||
"artifacts": [ | ||
{ | ||
"name": "public/myfolder", | ||
"type": "directory", | ||
"path": "/no-such-folder/no-sub-folder" | ||
} | ||
] | ||
}`, | ||
Artifacts: workertest.ArtifactAssertions{ | ||
"public/logs/live.log": workertest.ReferenceArtifact(), | ||
"public/logs/live_backing.log": workertest.GrepArtifact("/no-such-folder/no-sub-folder"), | ||
"public/myfolder": workertest.ErrorArtifact(), | ||
}, | ||
// NOTE: If anyone can come up with an artifact path is illegal please add a test case | ||
}}), | ||
}.Test(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Package dockertest provides integration tests for a few common configuration | ||
// of docker engine and common plugins. | ||
package dockertest | ||
|
||
import ( | ||
"github.com/taskcluster/taskcluster-worker/runtime/util" | ||
) | ||
|
||
var debug = util.Debug("dockertest") | ||
|
||
var engineConfig = `{ | ||
"privileged": "never" | ||
}` | ||
|
||
const pluginConfig = `{ | ||
"disabled": ["reboot"], | ||
"artifacts": {}, | ||
"env": {}, | ||
"livelog": {}, | ||
"success": {}, | ||
"watchdog": {}, | ||
"maxruntime": { | ||
"perTaskLimit": "require", | ||
"maxRunTime": "3 hours" | ||
} | ||
}` | ||
|
||
const dockerImageName = "alpine:3.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// +build linux,docker | ||
|
||
package dockertest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/taskcluster/taskcluster-worker/worker/workertest" | ||
) | ||
|
||
func TestEnv(t *testing.T) { | ||
workertest.Case{ | ||
Engine: "docker", | ||
Concurrency: 1, | ||
EngineConfig: engineConfig, | ||
PluginConfig: pluginConfig, | ||
Tasks: workertest.Tasks([]workertest.Task{{ | ||
Title: "Access Env Vars", | ||
Success: true, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "echo $MY_ENV_VAR"], | ||
"env": { | ||
"MY_ENV_VAR": "hello-world" | ||
}, | ||
"maxRunTime": "10 minutes" | ||
}`, | ||
AllowAdditional: true, // Ignore additional artifacts | ||
Artifacts: workertest.ArtifactAssertions{ | ||
"public/logs/live_backing.log": workertest.GrepArtifact("hello-world"), | ||
}, | ||
}, { | ||
Title: "TASK_ID and RUN_ID", | ||
Success: true, | ||
Payload: `{ | ||
"image": "` + dockerImageName + `", | ||
"command": ["sh", "-c", "test -n \"$TASK_ID\" && test \"$RUN_ID\" = 0"], | ||
"env": {}, | ||
"maxRunTime": "10 minutes" | ||
}`, | ||
AllowAdditional: true, // Ignore additional artifacts | ||
}}), | ||
}.Test(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dockertest | ||
|
||
import ( | ||
_ "github.com/taskcluster/taskcluster-worker/engines/docker" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/artifacts" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/env" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/livelog" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/maxruntime" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/reboot" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/stoponerror" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/success" | ||
_ "github.com/taskcluster/taskcluster-worker/plugins/watchdog" | ||
) |