Merge pull request #1169 from crosbymichael/buildfile-tests
Add unit tests for buildfile config instructions
This commit is contained in:
commit
5794857f7a
1 changed files with 79 additions and 21 deletions
|
@ -105,23 +105,11 @@ CMD Hello world
|
||||||
|
|
||||||
func TestBuild(t *testing.T) {
|
func TestBuild(t *testing.T) {
|
||||||
for _, ctx := range testContexts {
|
for _, ctx := range testContexts {
|
||||||
runtime := mkRuntime(t)
|
buildImage(ctx, t)
|
||||||
defer nuke(runtime)
|
|
||||||
|
|
||||||
srv := &Server{
|
|
||||||
runtime: runtime,
|
|
||||||
pullingPool: make(map[string]struct{}),
|
|
||||||
pushingPool: make(map[string]struct{}),
|
|
||||||
}
|
|
||||||
|
|
||||||
buildfile := NewBuildFile(srv, ioutil.Discard, false)
|
|
||||||
if _, err := buildfile.Build(mkTestContext(ctx.dockerfile, ctx.files, t)); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVolume(t *testing.T) {
|
func buildImage(context testContextTemplate, t *testing.T) *Image {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -133,20 +121,27 @@ func TestVolume(t *testing.T) {
|
||||||
pullingPool: make(map[string]struct{}),
|
pullingPool: make(map[string]struct{}),
|
||||||
pushingPool: make(map[string]struct{}),
|
pushingPool: make(map[string]struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
buildfile := NewBuildFile(srv, ioutil.Discard, false)
|
buildfile := NewBuildFile(srv, ioutil.Discard, false)
|
||||||
imgId, err := buildfile.Build(mkTestContext(`
|
|
||||||
|
id, err := buildfile.Build(mkTestContext(context.dockerfile, context.files, t))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
img, err := srv.ImageInspect(id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVolume(t *testing.T) {
|
||||||
|
img := buildImage(testContextTemplate{`
|
||||||
from %s
|
from %s
|
||||||
VOLUME /test
|
volume /test
|
||||||
CMD Hello world
|
cmd Hello world
|
||||||
`, nil, t))
|
`, nil}, t)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
img, err := srv.ImageInspect(imgId)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if len(img.Config.Volumes) == 0 {
|
if len(img.Config.Volumes) == 0 {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
@ -156,3 +151,66 @@ CMD Hello world
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildMaintainer(t *testing.T) {
|
||||||
|
img := buildImage(testContextTemplate{`
|
||||||
|
from %s
|
||||||
|
maintainer dockerio
|
||||||
|
`, nil}, t)
|
||||||
|
|
||||||
|
if img.Author != "dockerio" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEnv(t *testing.T) {
|
||||||
|
img := buildImage(testContextTemplate{`
|
||||||
|
from %s
|
||||||
|
env port 4243
|
||||||
|
`,
|
||||||
|
nil}, t)
|
||||||
|
|
||||||
|
if img.Config.Env[0] != "port=4243" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildCmd(t *testing.T) {
|
||||||
|
img := buildImage(testContextTemplate{`
|
||||||
|
from %s
|
||||||
|
cmd ["/bin/echo", "Hello World"]
|
||||||
|
`,
|
||||||
|
nil}, t)
|
||||||
|
|
||||||
|
if img.Config.Cmd[0] != "/bin/echo" {
|
||||||
|
t.Log(img.Config.Cmd[0])
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if img.Config.Cmd[1] != "Hello World" {
|
||||||
|
t.Log(img.Config.Cmd[1])
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildExpose(t *testing.T) {
|
||||||
|
img := buildImage(testContextTemplate{`
|
||||||
|
from %s
|
||||||
|
expose 4243
|
||||||
|
`,
|
||||||
|
nil}, t)
|
||||||
|
|
||||||
|
if img.Config.PortSpecs[0] != "4243" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildEntrypoint(t *testing.T) {
|
||||||
|
img := buildImage(testContextTemplate{`
|
||||||
|
from %s
|
||||||
|
entrypoint ["/bin/echo"]
|
||||||
|
`,
|
||||||
|
nil}, t)
|
||||||
|
|
||||||
|
if img.Config.Entrypoint[0] != "/bin/echo" {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue