MCPcopy
hub / github.com/op/go-logging / TestMemoryBackend

Function TestMemoryBackend

memory_test.go:42–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestMemoryBackend(t *testing.T) {
43 backend := NewMemoryBackend(8)
44 SetBackend(backend)
45
46 log := MustGetLogger("test")
47
48 if nil != MemoryRecordN(backend, 0) || 0 != backend.size {
49 t.Errorf("memory level: %d", backend.size)
50 }
51
52 // Run 13 times, the resulting vector should be [5..12]
53 for i := 0; i < 13; i++ {
54 log.Infof("%d", i)
55 }
56
57 if 8 != backend.size {
58 t.Errorf("record length: %d", backend.size)
59 }
60 record := MemoryRecordN(backend, 0)
61 if "5" != record.Formatted(0) {
62 t.Errorf("unexpected start: %s", record.Formatted(0))
63 }
64 for i := 0; i < 8; i++ {
65 record = MemoryRecordN(backend, i)
66 if strconv.Itoa(i+5) != record.Formatted(0) {
67 t.Errorf("unexpected record: %v", record.Formatted(0))
68 }
69 }
70 record = MemoryRecordN(backend, 7)
71 if "12" != record.Formatted(0) {
72 t.Errorf("unexpected end: %s", record.Formatted(0))
73 }
74 record = MemoryRecordN(backend, 8)
75 if nil != record {
76 t.Errorf("unexpected eof: %s", record.Formatted(0))
77 }
78}
79
80func TestChannelMemoryBackend(t *testing.T) {
81 backend := NewChannelMemoryBackend(8)

Callers

nothing calls this directly

Calls 7

NewMemoryBackendFunction · 0.85
SetBackendFunction · 0.85
MustGetLoggerFunction · 0.85
MemoryRecordNFunction · 0.85
ErrorfMethod · 0.80
InfofMethod · 0.80
FormattedMethod · 0.80

Tested by

no test coverage detected