Skip to content

Commit

Permalink
ref: replace extendio storage with traverse.fs (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 9, 2024
1 parent ad76826 commit d6245dd
Show file tree
Hide file tree
Showing 21 changed files with 1,318 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"faydeaudeau",
"fieldalignment",
"flif",
"fsys",
"GOARCH",
"goconst",
"gocritic",
Expand Down Expand Up @@ -66,6 +67,7 @@
"mockgen",
"modcache",
"mohae",
"Musico",
"nakedret",
"natefinch",
"navi",
Expand All @@ -92,6 +94,7 @@
"thelper",
"toplevel",
"tparallel",
"tsys",
"typecheck",
"unconvert",
"unparam",
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ require (
github.com/charmbracelet/bubbletea v1.1.1
github.com/charmbracelet/lipgloss v0.13.0
github.com/muesli/go-app-paths v0.2.2
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.47.0
github.com/snivilised/extendio v0.7.0
github.com/snivilised/li18ngo v0.1.4
github.com/snivilised/lorax v0.5.2
github.com/snivilised/pants v0.1.2
github.com/snivilised/traverse v0.1.2
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.18.2
go.uber.org/mock v0.4.0
go.uber.org/zap v1.27.0
go.uber.org/zap/exp v0.2.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
)

require (
Expand All @@ -41,7 +44,7 @@ require (
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -50,6 +53,7 @@ require (
golang.org/x/sync v0.8.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

require (
Expand Down
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
Expand All @@ -129,6 +129,10 @@ github.com/snivilised/li18ngo v0.1.4 h1:y6EECoVFpmkud2yDEeBnMnebPmSvdrEZ/LAq1PoP
github.com/snivilised/li18ngo v0.1.4/go.mod h1:Or3qUhpR6AM1X51i82RtyCvORWy2/hrxY9lg1i1gFTE=
github.com/snivilised/lorax v0.5.2 h1:iReIJl63tydiPSSD0YzsNQFX1CctmvMkYx0aSxoZJKo=
github.com/snivilised/lorax v0.5.2/go.mod h1:7H1JPgSn4h4p8NSqfl64raacYefdm/FiFkfcZ51PVHY=
github.com/snivilised/pants v0.1.2 h1:6Abj02gV5rFYyKfCsmeEiOi1pLdRyITKUY5oDoRgYuU=
github.com/snivilised/pants v0.1.2/go.mod h1:BOZa24yLxVjjnTCFWQeCzUWL8eK4TLtXtkz3pMdEFQM=
github.com/snivilised/traverse v0.1.2 h1:cg0AtPAu40Us+sKhVtIi+q9e0SpovfM2dXz2fM0FHe8=
github.com/snivilised/traverse v0.1.2/go.mod h1:yDe4oJLGLPvC0BGob1UlXRjPZ0bsPVl0HDl9PhGEjVw=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
Expand Down Expand Up @@ -165,8 +169,8 @@ go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
5 changes: 5 additions & 0 deletions src/app/cfg/cfg-suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ func TestCfg(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Cfg Suite")
}

const (
NoOverwrite = false
home = "/home"
)
16 changes: 10 additions & 6 deletions src/app/cfg/config-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/traverse/lfs"
"github.com/spf13/viper"
"golang.org/x/text/language"
)
Expand All @@ -35,7 +36,8 @@ func New(
ci *common.ConfigInfo,
sourceID string,
applicationName string,
vfs storage.VirtualFS,
tfs lfs.TraverseFS,
vfsL storage.VirtualFS,
) (common.ConfigRunner, error) {
home, err := os.UserHomeDir()

Expand All @@ -45,7 +47,8 @@ func New(
sourceID: sourceID,
applicationName: applicationName,
home: home,
vfs: vfs,
tfs: tfs,
vfsL: vfsL,
useXDG: common.IsUsingXDG(ci.Viper),
}, err
}
Expand All @@ -56,7 +59,8 @@ type configRunner struct {
sourceID string
applicationName string
home string
vfs storage.VirtualFS
tfs lfs.TraverseFS
vfsL storage.VirtualFS
useXDG bool
}

Expand Down Expand Up @@ -191,12 +195,12 @@ func (c *configRunner) export() error {
file := filepath.Join(path, common.Definitions.Pixa.ConfigType)
content := []byte(defaultConfig)

if !c.vfs.FileExists(file) {
if err := c.vfs.MkdirAll(path, common.Permissions.Write); err != nil {
if !c.vfsL.FileExists(file) {
if err := c.vfsL.MkdirAll(path, common.Permissions.Write); err != nil {
return err
}

return c.vfs.WriteFile(file, content, common.Permissions.Write)
return c.vfsL.WriteFile(file, content, common.Permissions.Write)
}

return nil
Expand Down
35 changes: 24 additions & 11 deletions src/app/cfg/config-runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package cfg_test
import (
"errors"
"fmt"
"os"
"path/filepath"
"testing/fstest"

. "github.com/onsi/ginkgo/v2" //nolint:revive // foo
. "github.com/onsi/gomega" //nolint:revive // foo
"github.com/spf13/viper"
"go.uber.org/mock/gomock"

"github.com/snivilised/cobrass/src/assistant/mocks"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
_ "github.com/snivilised/pants"
"github.com/snivilised/pixa/src/app/cfg"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/helpers"
lab "github.com/snivilised/pixa/src/internal/laboratory"
"github.com/snivilised/traverse/lfs"
"github.com/spf13/viper"
"go.uber.org/mock/gomock"
)

var (
Expand Down Expand Up @@ -63,22 +66,32 @@ var _ = Describe("ConfigRunner", Ordered, func() {
var (
repo string
configPath string
vfs storage.VirtualFS
vfsL storage.VirtualFS
FS lfs.TraverseFS
ctrl *gomock.Controller
mock *mocks.MockViperConfig
)

BeforeAll(func() {
Expect(li18ngo.Use()).To(Succeed())
repo = helpers.Repo("")
Expect(lab.UseI18n(lab.Path(repo, "test/data/l10n"))).To(Succeed())
_ = FS
})

BeforeEach(func() {
viper.Reset()
vfs = storage.UseMemFS()
vfsL = storage.UseMemFS()
FS = &lab.TestTraverseFS{
MapFS: fstest.MapFS{
home: &fstest.MapFile{
Mode: os.ModeDir,
},
},
}
ctrl = gomock.NewController(GinkgoT())
mock = mocks.NewMockViperConfig(ctrl)
repo = helpers.Repo("")
configPath = helpers.Path(repo, "test/data/configuration")

configPath = lab.Path(repo, "test/data/configuration")
})

AfterEach(func() {
Expand Down Expand Up @@ -107,7 +120,7 @@ var _ = Describe("ConfigRunner", Ordered, func() {
mock.EXPECT().InConfig(gomock.Any()).AnyTimes()
mock.EXPECT().GetString(gomock.Any()).AnyTimes()

runner, err := cfg.New(&ci, sourceID, common.Definitions.Pixa.AppName, vfs)
runner, err := cfg.New(&ci, sourceID, common.Definitions.Pixa.AppName, FS, vfsL)
if entry.created != nil {
entry.created(entry, runner)
}
Expand Down Expand Up @@ -192,7 +205,7 @@ var _ = Describe("ConfigRunner", Ordered, func() {
path := filepath.Join(runner.DefaultPath(), name)
content := []byte(cfg.GetDefaultConfigContent())

_ = vfs.WriteFile(path, content, common.Permissions.Write)
_ = vfsL.WriteFile(path, content, common.Permissions.Write)
},
assert: func(_ *runnerTE, runner common.ConfigRunner, err error) {
Expect(err).Error().To(BeNil())
Expand Down
3 changes: 3 additions & 0 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/snivilised/pixa/src/app/proxy"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/locale"
"github.com/snivilised/traverse/lfs"
)

type LocaleDetector interface {
Expand Down Expand Up @@ -65,6 +66,7 @@ type Bootstrap struct {
OptionsInfo ConfigureOptionsInfo
Configs *common.Configs
Vfs storage.VirtualFS
FS lfs.TraverseFS
Logger *slog.Logger
Presentation common.PresentationOptions
Observers common.Observers
Expand Down Expand Up @@ -105,6 +107,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
ci,
common.Definitions.Pixa.SourceID,
common.Definitions.Pixa.AppName,
b.FS,
b.Vfs,
)

Expand Down
17 changes: 9 additions & 8 deletions src/app/command/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/helpers"
lab "github.com/snivilised/pixa/src/internal/laboratory"
"github.com/snivilised/traverse/lfs"
"golang.org/x/text/language"
)

Expand Down Expand Up @@ -35,30 +37,29 @@ func (j *DetectorStub) Scan() language.Tag {
}

var _ = Describe("Bootstrap", Ordered, func() {

var (
repo string
l10nPath string
configPath string
vfs storage.VirtualFS
FS lfs.TraverseFS
vfsL storage.VirtualFS
)

BeforeAll(func() {
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
l10nPath = lab.Path(repo, "test/data/l10n")
configPath = lab.Path(repo, "test/data/configuration")
})

BeforeEach(func() {
vfs, _ = helpers.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)
FS, _ = lab.SetupTest("nasa-scientist-index.xml", configPath, l10nPath, lab.Silent)
})

Context("given: root defined with magick sub-command", func() {
It("🧪 should: setup command without error", func() {
bootstrap := command.Bootstrap{
Vfs: vfs,
Vfs: vfsL,
FS: FS,
}
rootCmd := bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
Expand Down
14 changes: 9 additions & 5 deletions src/app/command/magick-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ import (

"github.com/snivilised/cobrass/src/assistant/configuration"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/li18ngo"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/proxy/common"
"github.com/snivilised/pixa/src/internal/helpers"
lab "github.com/snivilised/pixa/src/internal/laboratory"
"github.com/snivilised/traverse/lfs"
)

var _ = Describe("MagickCmd", Ordered, func() {
var (
repo string
l10nPath string
configPath string
FS lfs.TraverseFS
vfs storage.VirtualFS
)

BeforeAll(func() {
vfs = storage.UseNativeFS()
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
l10nPath = lab.Path(repo, "test/data/l10n")
configPath = lab.Path(repo, "test/data/configuration")
})

BeforeEach(func() {
Expect(li18ngo.Use()).To(Succeed())
vfs, _ = helpers.SetupTest(
Expect(lab.UseI18n(l10nPath)).To(Succeed())

FS, _ = lab.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)
})
Expand All @@ -38,6 +41,7 @@ var _ = Describe("MagickCmd", Ordered, func() {
It("🧪 should: execute without error", func() {
bootstrap := command.Bootstrap{
Vfs: vfs,
FS: FS,
}
tester := helpers.CommandTester{
Args: []string{"mag", "--no-tui"},
Expand Down
Loading

0 comments on commit d6245dd

Please sign in to comment.