Skip to content

Commit d6245dd

Browse files
committed
ref: replace extendio storage with traverse.fs (#216)
1 parent ad76826 commit d6245dd

21 files changed

+1318
-74
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"faydeaudeau",
3737
"fieldalignment",
3838
"flif",
39+
"fsys",
3940
"GOARCH",
4041
"goconst",
4142
"gocritic",
@@ -66,6 +67,7 @@
6667
"mockgen",
6768
"modcache",
6869
"mohae",
70+
"Musico",
6971
"nakedret",
7072
"natefinch",
7173
"navi",
@@ -92,6 +94,7 @@
9294
"thelper",
9395
"toplevel",
9496
"tparallel",
97+
"tsys",
9598
"typecheck",
9699
"unconvert",
97100
"unparam",

go.mod

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ require (
66
github.com/charmbracelet/bubbletea v1.1.1
77
github.com/charmbracelet/lipgloss v0.13.0
88
github.com/muesli/go-app-paths v0.2.2
9+
github.com/onsi/ginkgo v1.16.5
910
github.com/onsi/ginkgo/v2 v2.20.2
1011
github.com/onsi/gomega v1.34.2
1112
github.com/pkg/errors v0.9.1
1213
github.com/samber/lo v1.47.0
1314
github.com/snivilised/extendio v0.7.0
1415
github.com/snivilised/li18ngo v0.1.4
1516
github.com/snivilised/lorax v0.5.2
17+
github.com/snivilised/pants v0.1.2
18+
github.com/snivilised/traverse v0.1.2
1619
github.com/spf13/cobra v1.8.1
1720
github.com/spf13/viper v1.18.2
1821
go.uber.org/mock v0.4.0
1922
go.uber.org/zap v1.27.0
2023
go.uber.org/zap/exp v0.2.0
21-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
24+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
2225
)
2326

2427
require (
@@ -41,7 +44,7 @@ require (
4144
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
4245
github.com/muesli/cancelreader v0.2.2 // indirect
4346
github.com/muesli/termenv v0.15.2 // indirect
44-
github.com/onsi/ginkgo v1.16.5 // indirect
47+
github.com/nxadm/tail v1.4.8 // indirect
4548
github.com/rivo/uniseg v0.4.7 // indirect
4649
github.com/sagikazarmark/locafero v0.4.0 // indirect
4750
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
@@ -50,6 +53,7 @@ require (
5053
golang.org/x/sync v0.8.0 // indirect
5154
golang.org/x/tools v0.24.0 // indirect
5255
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
56+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
5357
)
5458

5559
require (

go.sum

+8-4
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH
112112
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
113113
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
114114
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
115-
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
116-
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
115+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
116+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
117117
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
118118
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
119119
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
@@ -129,6 +129,10 @@ github.com/snivilised/li18ngo v0.1.4 h1:y6EECoVFpmkud2yDEeBnMnebPmSvdrEZ/LAq1PoP
129129
github.com/snivilised/li18ngo v0.1.4/go.mod h1:Or3qUhpR6AM1X51i82RtyCvORWy2/hrxY9lg1i1gFTE=
130130
github.com/snivilised/lorax v0.5.2 h1:iReIJl63tydiPSSD0YzsNQFX1CctmvMkYx0aSxoZJKo=
131131
github.com/snivilised/lorax v0.5.2/go.mod h1:7H1JPgSn4h4p8NSqfl64raacYefdm/FiFkfcZ51PVHY=
132+
github.com/snivilised/pants v0.1.2 h1:6Abj02gV5rFYyKfCsmeEiOi1pLdRyITKUY5oDoRgYuU=
133+
github.com/snivilised/pants v0.1.2/go.mod h1:BOZa24yLxVjjnTCFWQeCzUWL8eK4TLtXtkz3pMdEFQM=
134+
github.com/snivilised/traverse v0.1.2 h1:cg0AtPAu40Us+sKhVtIi+q9e0SpovfM2dXz2fM0FHe8=
135+
github.com/snivilised/traverse v0.1.2/go.mod h1:yDe4oJLGLPvC0BGob1UlXRjPZ0bsPVl0HDl9PhGEjVw=
132136
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
133137
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
134138
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
@@ -165,8 +169,8 @@ go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ
165169
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
166170
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
167171
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
168-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
169-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
172+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
173+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
170174
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
171175
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
172176
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

src/app/cfg/cfg-suite_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ func TestCfg(t *testing.T) {
1111
gomega.RegisterFailHandler(ginkgo.Fail)
1212
ginkgo.RunSpecs(t, "Cfg Suite")
1313
}
14+
15+
const (
16+
NoOverwrite = false
17+
home = "/home"
18+
)

src/app/cfg/config-runner.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/snivilised/extendio/xfs/storage"
1515
"github.com/snivilised/li18ngo"
1616
"github.com/snivilised/pixa/src/app/proxy/common"
17+
"github.com/snivilised/traverse/lfs"
1718
"github.com/spf13/viper"
1819
"golang.org/x/text/language"
1920
)
@@ -35,7 +36,8 @@ func New(
3536
ci *common.ConfigInfo,
3637
sourceID string,
3738
applicationName string,
38-
vfs storage.VirtualFS,
39+
tfs lfs.TraverseFS,
40+
vfsL storage.VirtualFS,
3941
) (common.ConfigRunner, error) {
4042
home, err := os.UserHomeDir()
4143

@@ -45,7 +47,8 @@ func New(
4547
sourceID: sourceID,
4648
applicationName: applicationName,
4749
home: home,
48-
vfs: vfs,
50+
tfs: tfs,
51+
vfsL: vfsL,
4952
useXDG: common.IsUsingXDG(ci.Viper),
5053
}, err
5154
}
@@ -56,7 +59,8 @@ type configRunner struct {
5659
sourceID string
5760
applicationName string
5861
home string
59-
vfs storage.VirtualFS
62+
tfs lfs.TraverseFS
63+
vfsL storage.VirtualFS
6064
useXDG bool
6165
}
6266

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

194-
if !c.vfs.FileExists(file) {
195-
if err := c.vfs.MkdirAll(path, common.Permissions.Write); err != nil {
198+
if !c.vfsL.FileExists(file) {
199+
if err := c.vfsL.MkdirAll(path, common.Permissions.Write); err != nil {
196200
return err
197201
}
198202

199-
return c.vfs.WriteFile(file, content, common.Permissions.Write)
203+
return c.vfsL.WriteFile(file, content, common.Permissions.Write)
200204
}
201205

202206
return nil

src/app/cfg/config-runner_test.go

+24-11
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ package cfg_test
33
import (
44
"errors"
55
"fmt"
6+
"os"
67
"path/filepath"
8+
"testing/fstest"
79

810
. "github.com/onsi/ginkgo/v2" //nolint:revive // foo
911
. "github.com/onsi/gomega" //nolint:revive // foo
10-
"github.com/spf13/viper"
11-
"go.uber.org/mock/gomock"
12-
1312
"github.com/snivilised/cobrass/src/assistant/mocks"
1413
"github.com/snivilised/extendio/xfs/storage"
15-
"github.com/snivilised/li18ngo"
14+
_ "github.com/snivilised/pants"
1615
"github.com/snivilised/pixa/src/app/cfg"
1716
"github.com/snivilised/pixa/src/app/proxy/common"
1817
"github.com/snivilised/pixa/src/internal/helpers"
18+
lab "github.com/snivilised/pixa/src/internal/laboratory"
19+
"github.com/snivilised/traverse/lfs"
20+
"github.com/spf13/viper"
21+
"go.uber.org/mock/gomock"
1922
)
2023

2124
var (
@@ -63,22 +66,32 @@ var _ = Describe("ConfigRunner", Ordered, func() {
6366
var (
6467
repo string
6568
configPath string
66-
vfs storage.VirtualFS
69+
vfsL storage.VirtualFS
70+
FS lfs.TraverseFS
6771
ctrl *gomock.Controller
6872
mock *mocks.MockViperConfig
6973
)
7074

7175
BeforeAll(func() {
72-
Expect(li18ngo.Use()).To(Succeed())
76+
repo = helpers.Repo("")
77+
Expect(lab.UseI18n(lab.Path(repo, "test/data/l10n"))).To(Succeed())
78+
_ = FS
7379
})
7480

7581
BeforeEach(func() {
7682
viper.Reset()
77-
vfs = storage.UseMemFS()
83+
vfsL = storage.UseMemFS()
84+
FS = &lab.TestTraverseFS{
85+
MapFS: fstest.MapFS{
86+
home: &fstest.MapFile{
87+
Mode: os.ModeDir,
88+
},
89+
},
90+
}
7891
ctrl = gomock.NewController(GinkgoT())
7992
mock = mocks.NewMockViperConfig(ctrl)
80-
repo = helpers.Repo("")
81-
configPath = helpers.Path(repo, "test/data/configuration")
93+
94+
configPath = lab.Path(repo, "test/data/configuration")
8295
})
8396

8497
AfterEach(func() {
@@ -107,7 +120,7 @@ var _ = Describe("ConfigRunner", Ordered, func() {
107120
mock.EXPECT().InConfig(gomock.Any()).AnyTimes()
108121
mock.EXPECT().GetString(gomock.Any()).AnyTimes()
109122

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

195-
_ = vfs.WriteFile(path, content, common.Permissions.Write)
208+
_ = vfsL.WriteFile(path, content, common.Permissions.Write)
196209
},
197210
assert: func(_ *runnerTE, runner common.ConfigRunner, err error) {
198211
Expect(err).Error().To(BeNil())

src/app/command/bootstrap.go

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/snivilised/pixa/src/app/proxy"
2525
"github.com/snivilised/pixa/src/app/proxy/common"
2626
"github.com/snivilised/pixa/src/locale"
27+
"github.com/snivilised/traverse/lfs"
2728
)
2829

2930
type LocaleDetector interface {
@@ -65,6 +66,7 @@ type Bootstrap struct {
6566
OptionsInfo ConfigureOptionsInfo
6667
Configs *common.Configs
6768
Vfs storage.VirtualFS
69+
FS lfs.TraverseFS
6870
Logger *slog.Logger
6971
Presentation common.PresentationOptions
7072
Observers common.Observers
@@ -105,6 +107,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
105107
ci,
106108
common.Definitions.Pixa.SourceID,
107109
common.Definitions.Pixa.AppName,
110+
b.FS,
108111
b.Vfs,
109112
)
110113

src/app/command/bootstrap_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/snivilised/pixa/src/app/command"
99
"github.com/snivilised/pixa/src/app/proxy/common"
1010
"github.com/snivilised/pixa/src/internal/helpers"
11+
lab "github.com/snivilised/pixa/src/internal/laboratory"
12+
"github.com/snivilised/traverse/lfs"
1113
"golang.org/x/text/language"
1214
)
1315

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

3739
var _ = Describe("Bootstrap", Ordered, func() {
38-
3940
var (
4041
repo string
4142
l10nPath string
4243
configPath string
43-
vfs storage.VirtualFS
44+
FS lfs.TraverseFS
45+
vfsL storage.VirtualFS
4446
)
4547

4648
BeforeAll(func() {
4749
repo = helpers.Repo("")
48-
l10nPath = helpers.Path(repo, "test/data/l10n")
49-
configPath = helpers.Path(repo, "test/data/configuration")
50+
l10nPath = lab.Path(repo, "test/data/l10n")
51+
configPath = lab.Path(repo, "test/data/configuration")
5052
})
5153

5254
BeforeEach(func() {
53-
vfs, _ = helpers.SetupTest(
54-
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
55-
)
55+
FS, _ = lab.SetupTest("nasa-scientist-index.xml", configPath, l10nPath, lab.Silent)
5656
})
5757

5858
Context("given: root defined with magick sub-command", func() {
5959
It("🧪 should: setup command without error", func() {
6060
bootstrap := command.Bootstrap{
61-
Vfs: vfs,
61+
Vfs: vfsL,
62+
FS: FS,
6263
}
6364
rootCmd := bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
6465
co.Detector = &DetectorStub{}

src/app/command/magick-cmd_test.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,33 @@ import (
66

77
"github.com/snivilised/cobrass/src/assistant/configuration"
88
"github.com/snivilised/extendio/xfs/storage"
9-
"github.com/snivilised/li18ngo"
109
"github.com/snivilised/pixa/src/app/command"
1110
"github.com/snivilised/pixa/src/app/proxy/common"
1211
"github.com/snivilised/pixa/src/internal/helpers"
12+
lab "github.com/snivilised/pixa/src/internal/laboratory"
13+
"github.com/snivilised/traverse/lfs"
1314
)
1415

1516
var _ = Describe("MagickCmd", Ordered, func() {
1617
var (
1718
repo string
1819
l10nPath string
1920
configPath string
21+
FS lfs.TraverseFS
2022
vfs storage.VirtualFS
2123
)
2224

2325
BeforeAll(func() {
2426
vfs = storage.UseNativeFS()
2527
repo = helpers.Repo("")
26-
l10nPath = helpers.Path(repo, "test/data/l10n")
27-
configPath = helpers.Path(repo, "test/data/configuration")
28+
l10nPath = lab.Path(repo, "test/data/l10n")
29+
configPath = lab.Path(repo, "test/data/configuration")
2830
})
2931

3032
BeforeEach(func() {
31-
Expect(li18ngo.Use()).To(Succeed())
32-
vfs, _ = helpers.SetupTest(
33+
Expect(lab.UseI18n(l10nPath)).To(Succeed())
34+
35+
FS, _ = lab.SetupTest(
3336
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
3437
)
3538
})
@@ -38,6 +41,7 @@ var _ = Describe("MagickCmd", Ordered, func() {
3841
It("🧪 should: execute without error", func() {
3942
bootstrap := command.Bootstrap{
4043
Vfs: vfs,
44+
FS: FS,
4145
}
4246
tester := helpers.CommandTester{
4347
Args: []string{"mag", "--no-tui"},

0 commit comments

Comments
 (0)