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

refactor:build test case and local build steps #326

Merged
merged 1 commit into from
Jun 17, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions build/local_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,16 @@ func (l *LocalBuilder) mountAndExecLayer(layer *v1.Layer, tempTarget, tempUpper
if err != nil {
return fmt.Errorf("failed to mount target %s:%v", tempTarget, err)
}
defer func() {
if err = driver.Unmount(tempTarget); err != nil {
logger.Warn(fmt.Errorf("failed to umount %s:%v", tempTarget, err))
}
}()

err = l.execLayer(layer, tempTarget)
if err != nil {
return fmt.Errorf("failed to exec layer %v:%v", layer, err)
}
if err = driver.Unmount(tempTarget); err != nil {
return fmt.Errorf("failed to umount %s:%v", tempTarget, err)
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (p *Parser) Parse(kubeFile []byte, name string) *v1.Image {
layerType, layerValue, err := decodeLine(text)
if err != nil {
logger.Warn("decode kubeFile line failed, err: %v", err)
return nil
}
if layerType == "" {
continue
Expand Down
12 changes: 6 additions & 6 deletions test/sealer_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("sealer build", func() {
It("specific the base rootfs that do not exist", func() {
//base rootfs not exist
imageName := build.GetImageNameTemplate("no_rootfs")
err := testhelper.WriteFile(tempFile, []byte("from abc\ncopy . ."))
err := testhelper.WriteFile(tempFile, []byte("FROM abc\nCOPY . ."))
Expect(err).NotTo(HaveOccurred())
cmd := build.NewArgsOfBuild().
SetKubeFile(tempFile).
Expand All @@ -57,14 +57,14 @@ var _ = Describe("sealer build", func() {
Build()
sess, err := testhelper.Start(cmd)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(2))
Eventually(sess).Should(Exit(1))
Expect(build.CheckIsImageExist(imageName)).ShouldNot(BeTrue())
})

It("copy src that do not exist", func() {
//copy: copy src not exist;
imageName := build.GetImageNameTemplate("no_src_copy")
err := testhelper.WriteFile(tempFile, []byte("from sealer-io/kubernetes:v1.19.9\ncopy abc123 ."))
err := testhelper.WriteFile(tempFile, []byte("FROM sealer-io/kubernetes:v1.19.9\nCOPY abc123 ."))
Expect(err).NotTo(HaveOccurred())
cmd := build.NewArgsOfBuild().
SetKubeFile(tempFile).
Expand All @@ -74,14 +74,14 @@ var _ = Describe("sealer build", func() {
Build()
sess, err := testhelper.Start(cmd)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(2))
Eventually(sess).Should(Exit(1))
Expect(build.CheckIsImageExist(imageName)).ShouldNot(BeTrue())
})

It("exec cmd that do not exist in system", func() {
//run&cmd: exec cmd not exist
imageName := build.GetImageNameTemplate("no_cmd_run")
err := testhelper.WriteFile(tempFile, []byte("from sealer-io/kubernetes:v1.19.9\ncmd abc ."))
err := testhelper.WriteFile(tempFile, []byte("FROM sealer-io/kubernetes:v1.19.9\nCMD abc ."))
Expect(err).NotTo(HaveOccurred())
cmd := build.NewArgsOfBuild().
SetKubeFile(tempFile).
Expand All @@ -91,7 +91,7 @@ var _ = Describe("sealer build", func() {
Build()
sess, err := testhelper.Start(cmd)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(Exit(2))
Eventually(sess).Should(Exit(1))
Expect(build.CheckIsImageExist(imageName)).ShouldNot(BeTrue())
})
})
Expand Down