// Copyright © 2019 Ettore Di Giacinto // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, see . package installer_test import ( "io/ioutil" "os" // . "github.com/mudler/luet/pkg/installer" "github.com/mudler/luet/pkg/helpers" pkg "github.com/mudler/luet/pkg/package" "github.com/mudler/luet/pkg/tree" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Repository", func() { Context("Writes a repository definition", func() { It("Writes a repo", func() { //repo:=NewLuetRepository() tmpdir, err := ioutil.TempDir("", "tree") Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpdir) // clean up generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false)) err := generalRecipe.Load("../../tests/fixtures/buildable") Expect(err).ToNot(HaveOccurred()) Expect(generalRecipe.Tree()).ToNot(BeNil()) // It should be populated back at this point Expect(len(generalRecipe.Tree().GetPackageSet().GetPackages())).To(Equal(3)) compiler := NewLuetCompiler(sd.NewSimpleDockerBackend(), generalRecipe.Tree(), generalRecipe.Tree().GetPackageSet()) err = compiler.Prepare(1) Expect(err).ToNot(HaveOccurred()) spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"}) Expect(err).ToNot(HaveOccurred()) Expect(spec.GetPackage().GetPath()).ToNot(Equal("")) tmpdir, err := ioutil.TempDir("", "tree") Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpdir) // clean up Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"})) Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"})) spec.SetOutputPath(tmpdir) artifact, err := compiler.Compile(2, false, spec) Expect(err).ToNot(HaveOccurred()) 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("test6"))).To(BeTrue()) content1, err := helpers.Read(spec.Rel("test5")) Expect(err).ToNot(HaveOccurred()) content2, err := helpers.Read(spec.Rel("test6")) Expect(err).ToNot(HaveOccurred()) Expect(content1).To(Equal("artifact5\n")) Expect(content2).To(Equal("artifact6\n")) }) }) })