From b1316b50b496db5ea838d69dc34f37a1d0f59407 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 8 Nov 2020 15:48:26 +0100 Subject: [PATCH] Add excludes tests --- pkg/compiler/compiler_test.go | 140 ++++++++++++++++++ tests/fixtures/excludeimage/build.yaml | 14 ++ tests/fixtures/excludeimage/definition.yaml | 3 + tests/fixtures/excludeimage/seed/build.yaml | 2 + .../excludeimage/seed/definition.yaml | 3 + tests/fixtures/excludeincludeimage/build.yaml | 17 +++ .../excludeincludeimage/definition.yaml | 3 + .../excludeincludeimage/seed/build.yaml | 2 + .../excludeincludeimage/seed/definition.yaml | 3 + tests/fixtures/excludes/build.yaml | 11 ++ tests/fixtures/excludes/definition.yaml | 3 + tests/fixtures/excludesincludes/build.yaml | 14 ++ .../fixtures/excludesincludes/definition.yaml | 3 + 13 files changed, 218 insertions(+) create mode 100644 tests/fixtures/excludeimage/build.yaml create mode 100644 tests/fixtures/excludeimage/definition.yaml create mode 100644 tests/fixtures/excludeimage/seed/build.yaml create mode 100644 tests/fixtures/excludeimage/seed/definition.yaml create mode 100644 tests/fixtures/excludeincludeimage/build.yaml create mode 100644 tests/fixtures/excludeincludeimage/definition.yaml create mode 100644 tests/fixtures/excludeincludeimage/seed/build.yaml create mode 100644 tests/fixtures/excludeincludeimage/seed/definition.yaml create mode 100644 tests/fixtures/excludes/build.yaml create mode 100644 tests/fixtures/excludes/definition.yaml create mode 100644 tests/fixtures/excludesincludes/build.yaml create mode 100644 tests/fixtures/excludesincludes/definition.yaml diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 054bfb08..a205be6f 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -265,6 +265,146 @@ var _ = Describe("Compiler", func() { Expect(helpers.Exists(spec.Rel("test6"))).ToNot(BeTrue()) }) + It("Compiles and excludes files", func() { + generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false)) + tmpdir, err := ioutil.TempDir("", "package") + Expect(err).ToNot(HaveOccurred()) + defer os.RemoveAll(tmpdir) // clean up + + err = generalRecipe.Load("../../tests/fixtures/excludes") + Expect(err).ToNot(HaveOccurred()) + + Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(1)) + + compiler := NewLuetCompiler(sd.NewSimpleDockerBackend(), generalRecipe.GetDatabase(), NewDefaultCompilerOptions(), solver.Options{Type: solver.SingleCoreSimple}) + + spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"}) + Expect(err).ToNot(HaveOccurred()) + + // err = generalRecipe.Tree().ResolveDeps(3) + // Expect(err).ToNot(HaveOccurred()) + + spec.SetOutputPath(tmpdir) + compiler.SetConcurrency(1) + + artifacts, errs := compiler.CompileParallel(false, NewLuetCompilationspecs(spec)) + Expect(errs).To(BeNil()) + Expect(len(artifacts)).To(Equal(1)) + + for _, artifact := range artifacts { + Expect(helpers.Exists(artifact.GetPath())).To(BeTrue()) + Expect(helpers.Untar(artifact.GetPath(), tmpdir, false)).ToNot(HaveOccurred()) + } + Expect(helpers.Exists(spec.Rel("test5"))).To(BeTrue()) + Expect(helpers.Exists(spec.Rel("marvin"))).To(BeTrue()) + Expect(helpers.Exists(spec.Rel("marvot"))).ToNot(BeTrue()) + Expect(helpers.Exists(spec.Rel("test6"))).To(BeTrue()) + }) + + It("Compiles includes and excludes files", func() { + generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false)) + tmpdir, err := ioutil.TempDir("", "package") + Expect(err).ToNot(HaveOccurred()) + defer os.RemoveAll(tmpdir) // clean up + + err = generalRecipe.Load("../../tests/fixtures/excludesincludes") + Expect(err).ToNot(HaveOccurred()) + + Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(1)) + + compiler := NewLuetCompiler(sd.NewSimpleDockerBackend(), generalRecipe.GetDatabase(), NewDefaultCompilerOptions(), solver.Options{Type: solver.SingleCoreSimple}) + + spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"}) + Expect(err).ToNot(HaveOccurred()) + + // err = generalRecipe.Tree().ResolveDeps(3) + // Expect(err).ToNot(HaveOccurred()) + + spec.SetOutputPath(tmpdir) + compiler.SetConcurrency(1) + + artifacts, errs := compiler.CompileParallel(false, NewLuetCompilationspecs(spec)) + Expect(errs).To(BeNil()) + Expect(len(artifacts)).To(Equal(1)) + + for _, artifact := range artifacts { + Expect(helpers.Exists(artifact.GetPath())).To(BeTrue()) + Expect(helpers.Untar(artifact.GetPath(), tmpdir, false)).ToNot(HaveOccurred()) + } + Expect(helpers.Exists(spec.Rel("test5"))).To(BeTrue()) + Expect(helpers.Exists(spec.Rel("marvin"))).To(BeTrue()) + Expect(helpers.Exists(spec.Rel("marvot"))).ToNot(BeTrue()) + Expect(helpers.Exists(spec.Rel("test6"))).ToNot(BeTrue()) + }) + + It("Compiles and excludes ony wanted files also from unpacked packages", func() { + generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false)) + tmpdir, err := ioutil.TempDir("", "package") + Expect(err).ToNot(HaveOccurred()) + defer os.RemoveAll(tmpdir) // clean up + + err = generalRecipe.Load("../../tests/fixtures/excludeimage") + Expect(err).ToNot(HaveOccurred()) + + Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(2)) + + compiler := NewLuetCompiler(sd.NewSimpleDockerBackend(), generalRecipe.GetDatabase(), NewDefaultCompilerOptions(), solver.Options{Type: solver.SingleCoreSimple}) + + spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"}) + Expect(err).ToNot(HaveOccurred()) + + // err = generalRecipe.Tree().ResolveDeps(3) + // Expect(err).ToNot(HaveOccurred()) + + spec.SetOutputPath(tmpdir) + compiler.SetConcurrency(1) + artifacts, errs := compiler.CompileParallel(false, NewLuetCompilationspecs(spec)) + Expect(errs).To(BeNil()) + Expect(len(artifacts)).To(Equal(1)) + + for _, artifact := range artifacts { + Expect(helpers.Exists(artifact.GetPath())).To(BeTrue()) + Expect(helpers.Untar(artifact.GetPath(), tmpdir, false)).ToNot(HaveOccurred()) + } + Expect(helpers.Exists(spec.Rel("marvin"))).ToNot(BeTrue()) + Expect(helpers.Exists(spec.Rel("test5"))).To(BeTrue()) + Expect(helpers.Exists(spec.Rel("test6"))).To(BeTrue()) + }) + + It("Compiles includes and excludes ony wanted files also from unpacked packages", func() { + generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false)) + tmpdir, err := ioutil.TempDir("", "package") + Expect(err).ToNot(HaveOccurred()) + defer os.RemoveAll(tmpdir) // clean up + + err = generalRecipe.Load("../../tests/fixtures/excludeincludeimage") + Expect(err).ToNot(HaveOccurred()) + + Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(2)) + + compiler := NewLuetCompiler(sd.NewSimpleDockerBackend(), generalRecipe.GetDatabase(), NewDefaultCompilerOptions(), solver.Options{Type: solver.SingleCoreSimple}) + + spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"}) + Expect(err).ToNot(HaveOccurred()) + + // err = generalRecipe.Tree().ResolveDeps(3) + // Expect(err).ToNot(HaveOccurred()) + + spec.SetOutputPath(tmpdir) + compiler.SetConcurrency(1) + artifacts, errs := compiler.CompileParallel(false, NewLuetCompilationspecs(spec)) + Expect(errs).To(BeNil()) + Expect(len(artifacts)).To(Equal(1)) + + for _, artifact := range artifacts { + Expect(helpers.Exists(artifact.GetPath())).To(BeTrue()) + Expect(helpers.Untar(artifact.GetPath(), tmpdir, false)).ToNot(HaveOccurred()) + } + Expect(helpers.Exists(spec.Rel("marvin"))).ToNot(BeTrue()) + Expect(helpers.Exists(spec.Rel("test5"))).To(BeTrue()) + Expect(helpers.Exists(spec.Rel("test6"))).To(BeTrue()) + }) + It("Compiles and includes ony wanted files also from unpacked packages", func() { generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false)) tmpdir, err := ioutil.TempDir("", "package") diff --git a/tests/fixtures/excludeimage/build.yaml b/tests/fixtures/excludeimage/build.yaml new file mode 100644 index 00000000..a9234ab7 --- /dev/null +++ b/tests/fixtures/excludeimage/build.yaml @@ -0,0 +1,14 @@ +requires: +- category: "layer" + name: "seed" + version: "1.0" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact5 > /test5 + - echo artifact6 > /test6 + - echo artifact43 > /marvin +unpack: true +excludes: +- marvin diff --git a/tests/fixtures/excludeimage/definition.yaml b/tests/fixtures/excludeimage/definition.yaml new file mode 100644 index 00000000..b02a44e8 --- /dev/null +++ b/tests/fixtures/excludeimage/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "b" +version: "1.0" diff --git a/tests/fixtures/excludeimage/seed/build.yaml b/tests/fixtures/excludeimage/seed/build.yaml new file mode 100644 index 00000000..7d9077ab --- /dev/null +++ b/tests/fixtures/excludeimage/seed/build.yaml @@ -0,0 +1,2 @@ +image: alpine +unpack: true \ No newline at end of file diff --git a/tests/fixtures/excludeimage/seed/definition.yaml b/tests/fixtures/excludeimage/seed/definition.yaml new file mode 100644 index 00000000..bc0499d9 --- /dev/null +++ b/tests/fixtures/excludeimage/seed/definition.yaml @@ -0,0 +1,3 @@ +category: "layer" +name: "seed" +version: "1.0" diff --git a/tests/fixtures/excludeincludeimage/build.yaml b/tests/fixtures/excludeincludeimage/build.yaml new file mode 100644 index 00000000..2aced72c --- /dev/null +++ b/tests/fixtures/excludeincludeimage/build.yaml @@ -0,0 +1,17 @@ +requires: +- category: "layer" + name: "seed" + version: "1.0" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact5 > /test5 + - echo artifact6 > /test6 + - echo artifact43 > /marvin +unpack: true +excludes: +- marvin +includes: +- test.* +- mar.* \ No newline at end of file diff --git a/tests/fixtures/excludeincludeimage/definition.yaml b/tests/fixtures/excludeincludeimage/definition.yaml new file mode 100644 index 00000000..b02a44e8 --- /dev/null +++ b/tests/fixtures/excludeincludeimage/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "b" +version: "1.0" diff --git a/tests/fixtures/excludeincludeimage/seed/build.yaml b/tests/fixtures/excludeincludeimage/seed/build.yaml new file mode 100644 index 00000000..7d9077ab --- /dev/null +++ b/tests/fixtures/excludeincludeimage/seed/build.yaml @@ -0,0 +1,2 @@ +image: alpine +unpack: true \ No newline at end of file diff --git a/tests/fixtures/excludeincludeimage/seed/definition.yaml b/tests/fixtures/excludeincludeimage/seed/definition.yaml new file mode 100644 index 00000000..bc0499d9 --- /dev/null +++ b/tests/fixtures/excludeincludeimage/seed/definition.yaml @@ -0,0 +1,3 @@ +category: "layer" +name: "seed" +version: "1.0" diff --git a/tests/fixtures/excludes/build.yaml b/tests/fixtures/excludes/build.yaml new file mode 100644 index 00000000..a49efe76 --- /dev/null +++ b/tests/fixtures/excludes/build.yaml @@ -0,0 +1,11 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact5 > /test5 + - echo artifact6 > /test6 + - echo artifact43 > /marvin + - echo "foo" > /marvot +excludes: +- marvot \ No newline at end of file diff --git a/tests/fixtures/excludes/definition.yaml b/tests/fixtures/excludes/definition.yaml new file mode 100644 index 00000000..b02a44e8 --- /dev/null +++ b/tests/fixtures/excludes/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "b" +version: "1.0" diff --git a/tests/fixtures/excludesincludes/build.yaml b/tests/fixtures/excludesincludes/build.yaml new file mode 100644 index 00000000..65f2eb3c --- /dev/null +++ b/tests/fixtures/excludesincludes/build.yaml @@ -0,0 +1,14 @@ +image: "alpine" +prelude: + - echo foo > /test + - echo bar > /test2 +steps: + - echo artifact5 > /test5 + - echo artifact6 > /test6 + - echo artifact43 > /marvin + - echo "foo" > /marvot +excludes: +- marvot +includes: +- /test5 +- mar.* diff --git a/tests/fixtures/excludesincludes/definition.yaml b/tests/fixtures/excludesincludes/definition.yaml new file mode 100644 index 00000000..b02a44e8 --- /dev/null +++ b/tests/fixtures/excludesincludes/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "b" +version: "1.0"