Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new test suite for build #4464

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/e2e/build/basicalpine/Containerfile
@@ -0,0 +1 @@
FROM alpine
Empty file.
2 changes: 2 additions & 0 deletions test/e2e/build/squash/Dockerfile.squash-a
@@ -0,0 +1,2 @@
FROM busybox:latest
ADD alpinetest.tgz /data
2 changes: 2 additions & 0 deletions test/e2e/build/squash/Dockerfile.squash-b
@@ -0,0 +1,2 @@
FROM test-squash-a:latest
RUN rm -rf /data
3 changes: 3 additions & 0 deletions test/e2e/build/squash/Dockerfile.squash-c
@@ -0,0 +1,3 @@
FROM busybox:latest
ADD alpinetest.tgz /data
RUN rm -rf /data
Binary file added test/e2e/build/squash/alpinetest.tgz
Binary file not shown.
108 changes: 108 additions & 0 deletions test/e2e/build_test.go
@@ -0,0 +1,108 @@
// +build !remoteclient

package integration

import (
"os"
"strings"

. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Podman build", func() {
var (
tempdir string
err error
podmanTest *PodmanTestIntegration
)

BeforeEach(func() {
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)
}
podmanTest = PodmanTestCreate(tempdir)
podmanTest.Setup()
podmanTest.RestoreAllArtifacts()
})

AfterEach(func() {
podmanTest.Cleanup()
f := CurrentGinkgoTestDescription()
processTestResult(f)
})

// Let's first do the most simple build possible to make sure stuff is
// happy and then clean up after ourselves to make sure that works too.
It("podman build and remove basic alpine", func() {
session := podmanTest.PodmanNoCache([]string{"build", "build/basicalpine"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.PodmanNoCache([]string{"rmi", "alpine"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

// If the context directory is pointing at a file and not a directory,
// that's a no no, fail out.
It("podman build context directory a file", func() {
session := podmanTest.PodmanNoCache([]string{"build", "build/context_dir_a_file"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})

// Check that builds with different values for the squash options
// create the appropriate number of layers, then clean up after.
It("podman build basic alpine with squash", func() {
session := podmanTest.PodmanNoCache([]string{"build", "-f", "build/squash/Dockerfile.squash-a", "-t", "test-squash-a:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.PodmanNoCache([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-a"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
// Check for two layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2))

session = podmanTest.PodmanNoCache([]string{"build", "-f", "build/squash/Dockerfile.squash-b", "--squash", "-t", "test-squash-b:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.PodmanNoCache([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-b"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
// Check for three layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(3))

session = podmanTest.PodmanNoCache([]string{"build", "-f", "build/squash/Dockerfile.squash-c", "--squash", "-t", "test-squash-c:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.PodmanNoCache([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-c"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
// Check for two layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(2))

session = podmanTest.PodmanNoCache([]string{"build", "-f", "build/squash/Dockerfile.squash-c", "--squash-all", "-t", "test-squash-d:latest", "build/squash"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.PodmanNoCache([]string{"inspect", "--format", "{{.RootFS.Layers}}", "test-squash-d"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
// Check for one layers
Expect(len(strings.Fields(session.OutputToString()))).To(Equal(1))

session = podmanTest.PodmanNoCache([]string{"rm", "-a"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

session = podmanTest.PodmanNoCache([]string{"rmi", "-a", "-f"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of duplication here, can it be simplified at all (for example) by feeding a list of string-lists, to a local function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to shrink this down, but could be suffering with late evening brain. Maybe we can chat/point sometime over the next day or two on break?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't get a chance to chat in the F2F, If you've tips on condensing, happy to take them, but I'm not seeing it. If there are no other concerns, could we get this in and address in a follow up?

})
})