2021-10-20 22:13:02 +00:00
|
|
|
// Copyright © 2019-2021 Ettore Di Giacinto <mudler@gentoo.org>
|
2019-11-26 17:06:23 +00:00
|
|
|
//
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package client_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2021-10-20 22:13:02 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
2021-10-19 15:06:48 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types/artifact"
|
2021-06-01 14:43:31 +00:00
|
|
|
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
2019-11-26 17:06:23 +00:00
|
|
|
. "github.com/mudler/luet/pkg/installer/client"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Local client", func() {
|
|
|
|
Context("With repository", func() {
|
2021-10-20 22:13:02 +00:00
|
|
|
ctx := types.NewContext()
|
|
|
|
|
2019-11-26 17:06:23 +00:00
|
|
|
It("Downloads single files", func() {
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
// write the whole body at once
|
|
|
|
err = ioutil.WriteFile(filepath.Join(tmpdir, "test.txt"), []byte(`test`), os.ModePerm)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-10-20 22:13:02 +00:00
|
|
|
c := NewLocalClient(RepoData{Urls: []string{tmpdir}}, ctx)
|
2019-11-26 17:06:23 +00:00
|
|
|
path, err := c.DownloadFile("test.txt")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Read(path)).To(Equal("test"))
|
2019-11-26 17:06:23 +00:00
|
|
|
os.RemoveAll(path)
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Downloads artifacts", func() {
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
// write the whole body at once
|
|
|
|
err = ioutil.WriteFile(filepath.Join(tmpdir, "test.txt"), []byte(`test`), os.ModePerm)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-10-20 22:13:02 +00:00
|
|
|
c := NewLocalClient(RepoData{Urls: []string{tmpdir}}, ctx)
|
2021-04-12 17:00:36 +00:00
|
|
|
path, err := c.DownloadArtifact(&artifact.PackageArtifact{Path: "test.txt"})
|
2019-11-26 17:06:23 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Read(path.Path)).To(Equal("test"))
|
2021-04-12 17:00:36 +00:00
|
|
|
os.RemoveAll(path.Path)
|
2019-11-26 17:06:23 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|