Add unit tests for build no cache
This commit is contained in:
parent
3a123bc479
commit
b9f0695924
|
@ -195,21 +195,23 @@ func mkTestingFileServer(files [][2]string) (*httptest.Server, error) {
|
||||||
|
|
||||||
func TestBuild(t *testing.T) {
|
func TestBuild(t *testing.T) {
|
||||||
for _, ctx := range testContexts {
|
for _, ctx := range testContexts {
|
||||||
buildImage(ctx, t)
|
buildImage(ctx, t, nil, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildImage(context testContextTemplate, t *testing.T) *Image {
|
func buildImage(context testContextTemplate, t *testing.T, srv *Server, useCache bool) *Image {
|
||||||
runtime, err := newTestRuntime()
|
if srv == nil {
|
||||||
if err != nil {
|
runtime, err := newTestRuntime()
|
||||||
t.Fatal(err)
|
if err != nil {
|
||||||
}
|
t.Fatal(err)
|
||||||
defer nuke(runtime)
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
srv := &Server{
|
srv = &Server{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
pullingPool: make(map[string]struct{}),
|
pullingPool: make(map[string]struct{}),
|
||||||
pushingPool: make(map[string]struct{}),
|
pushingPool: make(map[string]struct{}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpServer, err := mkTestingFileServer(context.remoteFiles)
|
httpServer, err := mkTestingFileServer(context.remoteFiles)
|
||||||
|
@ -224,10 +226,10 @@ func buildImage(context testContextTemplate, t *testing.T) *Image {
|
||||||
}
|
}
|
||||||
port := httpServer.URL[idx+1:]
|
port := httpServer.URL[idx+1:]
|
||||||
|
|
||||||
ip := runtime.networkManager.bridgeNetwork.IP
|
ip := srv.runtime.networkManager.bridgeNetwork.IP
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||||
|
|
||||||
buildfile := NewBuildFile(srv, ioutil.Discard, false, true)
|
buildfile := NewBuildFile(srv, ioutil.Discard, false, useCache)
|
||||||
id, err := buildfile.Build(mkTestContext(dockerfile, context.files, t))
|
id, err := buildfile.Build(mkTestContext(dockerfile, context.files, t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -245,7 +247,7 @@ func TestVolume(t *testing.T) {
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
volume /test
|
volume /test
|
||||||
cmd Hello world
|
cmd Hello world
|
||||||
`, nil, nil}, t)
|
`, nil, nil}, t, nil, true)
|
||||||
|
|
||||||
if len(img.Config.Volumes) == 0 {
|
if len(img.Config.Volumes) == 0 {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -261,7 +263,7 @@ func TestBuildMaintainer(t *testing.T) {
|
||||||
img := buildImage(testContextTemplate{`
|
img := buildImage(testContextTemplate{`
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
maintainer dockerio
|
maintainer dockerio
|
||||||
`, nil, nil}, t)
|
`, nil, nil}, t, nil, true)
|
||||||
|
|
||||||
if img.Author != "dockerio" {
|
if img.Author != "dockerio" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -273,7 +275,7 @@ func TestBuildEnv(t *testing.T) {
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
env port 4243
|
env port 4243
|
||||||
`,
|
`,
|
||||||
nil, nil}, t)
|
nil, nil}, t, nil, true)
|
||||||
hasEnv := false
|
hasEnv := false
|
||||||
for _, envVar := range img.Config.Env {
|
for _, envVar := range img.Config.Env {
|
||||||
if envVar == "port=4243" {
|
if envVar == "port=4243" {
|
||||||
|
@ -291,7 +293,7 @@ func TestBuildCmd(t *testing.T) {
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
cmd ["/bin/echo", "Hello World"]
|
cmd ["/bin/echo", "Hello World"]
|
||||||
`,
|
`,
|
||||||
nil, nil}, t)
|
nil, nil}, t, nil, true)
|
||||||
|
|
||||||
if img.Config.Cmd[0] != "/bin/echo" {
|
if img.Config.Cmd[0] != "/bin/echo" {
|
||||||
t.Log(img.Config.Cmd[0])
|
t.Log(img.Config.Cmd[0])
|
||||||
|
@ -308,7 +310,7 @@ func TestBuildExpose(t *testing.T) {
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
expose 4243
|
expose 4243
|
||||||
`,
|
`,
|
||||||
nil, nil}, t)
|
nil, nil}, t, nil, true)
|
||||||
|
|
||||||
if img.Config.PortSpecs[0] != "4243" {
|
if img.Config.PortSpecs[0] != "4243" {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -320,8 +322,70 @@ func TestBuildEntrypoint(t *testing.T) {
|
||||||
from {IMAGE}
|
from {IMAGE}
|
||||||
entrypoint ["/bin/echo"]
|
entrypoint ["/bin/echo"]
|
||||||
`,
|
`,
|
||||||
nil, nil}, t)
|
nil, nil}, t, nil, true)
|
||||||
|
|
||||||
if img.Config.Entrypoint[0] != "/bin/echo" {
|
if img.Config.Entrypoint[0] != "/bin/echo" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildImageWithCache(t *testing.T) {
|
||||||
|
runtime, err := newTestRuntime()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{
|
||||||
|
runtime: runtime,
|
||||||
|
pullingPool: make(map[string]struct{}),
|
||||||
|
pushingPool: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
template := testContextTemplate{`
|
||||||
|
from {IMAGE}
|
||||||
|
maintainer dockerio
|
||||||
|
`,
|
||||||
|
nil, nil}
|
||||||
|
|
||||||
|
img := buildImage(template, t, srv, true)
|
||||||
|
imageId := img.ID
|
||||||
|
|
||||||
|
img = nil
|
||||||
|
img = buildImage(template, t, srv, true)
|
||||||
|
|
||||||
|
if imageId != img.ID {
|
||||||
|
t.Logf("Image ids should match: %s != %s", imageId, img.ID)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildImageWithoutCache(t *testing.T) {
|
||||||
|
runtime, err := newTestRuntime()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{
|
||||||
|
runtime: runtime,
|
||||||
|
pullingPool: make(map[string]struct{}),
|
||||||
|
pushingPool: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
template := testContextTemplate{`
|
||||||
|
from {IMAGE}
|
||||||
|
maintainer dockerio
|
||||||
|
`,
|
||||||
|
nil, nil}
|
||||||
|
|
||||||
|
img := buildImage(template, t, srv, true)
|
||||||
|
imageId := img.ID
|
||||||
|
|
||||||
|
img = nil
|
||||||
|
img = buildImage(template, t, srv, false)
|
||||||
|
|
||||||
|
if imageId == img.ID {
|
||||||
|
t.Logf("Image ids should not match: %s == %s", imageId, img.ID)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue