Skip to content

Commit d243eed

Browse files
misc: add mock cache, fix remotefs test and run log (#341)
1 parent f20ed70 commit d243eed

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

internal/cli/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (a *appServer) Run(ctx context.Context) error {
254254
return err
255255
}
256256
a.prompter.SuccessReload()
257-
a.log.Debug("restarted the process in %d", time.Since(now))
257+
a.log.Debug("restarted the process in %s", time.Since(now))
258258
process = p
259259
return nil
260260
}))

package/remotefs/remotefs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestCommand(t *testing.T) {
143143
Stderr: os.Stderr,
144144
Stdout: os.Stdout,
145145
}
146-
processfs, err := command.Start(ctx, cmd.Path, cmd.Args...)
146+
processfs, err := command.Start(ctx, cmd.Path, cmd.Args[1:]...)
147147
is.NoErr(err)
148148
defer processfs.Close()
149149
code, err := fs.ReadFile(processfs, "a.txt")

package/virtual/vcache/mock.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package vcache
2+
3+
import "github.com/livebud/bud/package/virtual"
4+
5+
func Mock(fallback Cache) *MockCache {
6+
return &MockCache{Cache: fallback}
7+
}
8+
9+
type MockCache struct {
10+
Cache
11+
MockHas func(path string) (ok bool)
12+
MockGet func(path string) (entry virtual.Entry, ok bool)
13+
MockSet func(path string, entry virtual.Entry)
14+
MockDelete func(path string)
15+
MockRange func(fn func(path string, entry virtual.Entry) bool)
16+
MockClear func()
17+
}
18+
19+
func (m *MockCache) Has(path string) (ok bool) {
20+
if m.MockHas != nil {
21+
return m.MockHas(path)
22+
}
23+
return m.Cache.Has(path)
24+
}
25+
26+
func (m *MockCache) Get(path string) (entry virtual.Entry, ok bool) {
27+
if m.MockGet != nil {
28+
return m.MockGet(path)
29+
}
30+
return m.Cache.Get(path)
31+
}
32+
33+
func (m *MockCache) Set(path string, entry virtual.Entry) {
34+
if m.MockSet != nil {
35+
m.MockSet(path, entry)
36+
return
37+
}
38+
m.Cache.Set(path, entry)
39+
}
40+
41+
func (m *MockCache) Delete(path string) {
42+
if m.MockDelete != nil {
43+
m.MockDelete(path)
44+
return
45+
}
46+
m.Cache.Delete(path)
47+
}
48+
49+
func (m *MockCache) Range(fn func(path string, entry virtual.Entry) bool) {
50+
if m.MockRange != nil {
51+
m.MockRange(fn)
52+
return
53+
}
54+
m.Cache.Range(fn)
55+
}
56+
57+
func (m *MockCache) Clear() {
58+
if m.MockClear != nil {
59+
m.MockClear()
60+
}
61+
m.Cache.Clear()
62+
}

0 commit comments

Comments
 (0)