mirror of
https://github.com/mudler/luet.git
synced 2025-09-13 22:01:39 +00:00
Define context for scoped operation across core types
It holds necessary state plus additional information relative to the context which we are being run to (e.g. if we are in a terminal or not). Besides in the future we can use it also as a contextual logger to provide more smart logging capabilities. This also replace the general global configuration instance that previously was share between the core components.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
||||
// Copyright © 2019-2021 Ettore Di Giacinto <mudler@gentoo.org>
|
||||
//
|
||||
// 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
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mudler/luet/pkg/api/core/types"
|
||||
"github.com/mudler/luet/pkg/api/core/types/artifact"
|
||||
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
||||
. "github.com/mudler/luet/pkg/installer/client"
|
||||
@@ -29,6 +30,8 @@ import (
|
||||
|
||||
var _ = Describe("Local client", func() {
|
||||
Context("With repository", func() {
|
||||
ctx := types.NewContext()
|
||||
|
||||
It("Downloads single files", func() {
|
||||
tmpdir, err := ioutil.TempDir("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
@@ -38,7 +41,7 @@ var _ = Describe("Local client", func() {
|
||||
err = ioutil.WriteFile(filepath.Join(tmpdir, "test.txt"), []byte(`test`), os.ModePerm)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
c := NewLocalClient(RepoData{Urls: []string{tmpdir}})
|
||||
c := NewLocalClient(RepoData{Urls: []string{tmpdir}}, ctx)
|
||||
path, err := c.DownloadFile("test.txt")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(fileHelper.Read(path)).To(Equal("test"))
|
||||
@@ -54,7 +57,7 @@ var _ = Describe("Local client", func() {
|
||||
err = ioutil.WriteFile(filepath.Join(tmpdir, "test.txt"), []byte(`test`), os.ModePerm)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
c := NewLocalClient(RepoData{Urls: []string{tmpdir}})
|
||||
c := NewLocalClient(RepoData{Urls: []string{tmpdir}}, ctx)
|
||||
path, err := c.DownloadArtifact(&artifact.PackageArtifact{Path: "test.txt"})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(fileHelper.Read(path.Path)).To(Equal("test"))
|
||||
|
Reference in New Issue
Block a user