blob: f0ac1b6750e52e326e1b7e1e9e397794a31e1ee5 [file] [log] [blame]
gioc76baed2024-08-19 22:04:57 +04001package soft
2
3import (
4 "sync"
5 "testing"
6)
7
8type mockRepoIO struct {
9 RepoFS
10 addr string
11 t *testing.T
12 l sync.Locker
13}
14
15func NewMockRepoIO(fs RepoFS, addr string, t *testing.T) RepoIO {
16 return &mockRepoIO{
17 RepoFS: fs,
18 addr: addr,
19 t: t,
20 l: &sync.Mutex{},
21 }
22}
23
24func (r mockRepoIO) FullAddress() string {
25 return r.addr
26}
27
28func (r mockRepoIO) Pull() error {
29 r.t.Logf("Pull: %s", r.addr)
30 return nil
31}
32
33func (r mockRepoIO) CommitAndPush(message string, opts ...PushOption) (string, error) {
34 r.t.Logf("Commit and push: %s", message)
35 return "", nil
36}
37
38func (r mockRepoIO) Do(op DoFn, _ ...DoOption) (string, error) {
39 r.l.Lock()
40 defer r.l.Unlock()
41 msg, err := op(r)
42 if err != nil {
43 return "", err
44 }
45 return r.CommitAndPush(msg)
46}