MCPcopy Index your code
hub / github.com/dearcode/candy / TestMessageDB

Function TestMessageDB

store/msg_test.go:32–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestMessageDB(t *testing.T) {
33 m := newMessageDB(testMessageDBPath)
34 if err := m.start(&testSender{}); err != nil {
35 t.Fatalf("start error:%s", errors.ErrorStack(err))
36 }
37
38 var msgs []meta.Message
39 for i := 0; i < 10; i++ {
40 id := time.Now().UnixNano()
41 msg := meta.Message{ID: int64(id), Body: fmt.Sprintf("this is msg:%d", id)}
42 msgs = append(msgs, msg)
43 if err := m.add(msg); err != nil {
44 t.Fatalf("add message error:%s", err.Error())
45 }
46 time.Sleep(time.Millisecond)
47 }
48
49 for _, msg := range msgs {
50 mss, err := m.get(msg.ID)
51 if err != nil {
52 t.Fatalf("get msg:(%d) error", msg.ID)
53 }
54
55 if !strings.EqualFold(msg.Body, mss[0].Body) {
56 t.Fatalf("expect:%s, find:%s", msg.Body, mss[0].Body)
57 }
58 }
59}

Callers

nothing calls this directly

Calls 5

newMessageDBFunction · 0.85
addMethod · 0.80
startMethod · 0.45
ErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected