-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
69 lines (60 loc) · 1.45 KB
/
service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package rig
import (
"bytes"
"fmt"
"io"
"testing"
)
type testService struct {
version uint64
}
func (s *testService) Version() (uint64, error) {
return s.version, nil
}
func (s *testService) Validate(Operation) error {
return nil
}
func (s *testService) Apply(version uint64, op Operation) error {
s.version = version
return nil
}
func (s *testService) Snapshot() (io.ReadSeeker, int64, error) {
snapshot := []byte(fmt.Sprint(s.version))
r := bytes.NewReader(snapshot)
return r, int64(len(snapshot)), nil
}
func (s *testService) Restore(version uint64, r io.Reader) error {
s.version = version
return nil
}
type testObjectStore struct{ t *testing.T }
func (o *testObjectStore) GetObject(name string) (io.ReadCloser, error) {
o.t.Log("getting object", name)
return nil, nil
}
func (o *testObjectStore) DeleteObject(name string) error {
o.t.Log("deleting object", name)
return nil
}
func (o *testObjectStore) PutObject(name string, data io.ReadSeeker, size int64) error {
o.t.Log("putting object", name, "size", size)
return nil
}
func TestSimple(t *testing.T) {
rs, err := NewRiggedService(&testService{}, NewFileObjectStore("/tmp/bucket"), "my_service")
if err != nil {
t.Fatal(err)
}
rs.testSleep = true
t.Log(rs.Recover())
t.Log(rs.service)
rs.Apply(Operation{}, false)
rs.Flush()
rs.Apply(Operation{}, false)
rs.Apply(Operation{}, false)
rs.Apply(Operation{}, false)
rs.Flush()
rs.Apply(Operation{}, false)
rs.Flush()
rs.Snapshot()
}