Debian Codegraph @

lmdb/error_test.go

raw symbols SCIP
1 package lmdb
2
3 import (
4 "fmt"
5 "syscall"
6 "testing"
7 )
8
9 func TestErrno_Error(t *testing.T) {
10 operr := &OpError{"testop", fmt.Errorf("testmsg")}
11 msg := operr.Error()
12 if msg != "testop: testmsg" {
13 t.Errorf("message: %q", msg)
14 }
15 }
16
17 func BenchmarkErrno_Error(b *testing.B) {
18 for i := 0; i < b.N; i++ {
19 for _, errno := range []error{
20 syscall.EINVAL,
21 NotFound,
22 MapResized,
23 MapFull,
24 } {
25 operr := &OpError{"mdb_testop", errno}
26 msg := operr.Error()
27 if msg == "" {
28 b.Fatal("empty message")
29 }
30 }
31
32 }
33 }
34 func TestErrno(t *testing.T) {
35 zeroerr := operrno("testop", 0)
36 if zeroerr != nil {
37 t.Errorf("errno(0) != nil: %#v", zeroerr)
38 }
39 syserr := _operrno("testop", int(syscall.EINVAL))
40 if syserr.(*OpError).Errno != syscall.EINVAL { // fails if error is Errno(syscall.EINVAL)
41 t.Errorf("errno(syscall.EINVAL) != syscall.EINVAL: %#v", syserr)
42 }
43 mdberr := _operrno("testop", int(KeyExist))
44 if mdberr.(*OpError).Errno != KeyExist {
45 t.Errorf("errno(ErrKeyExist) != ErrKeyExist: %#v", syserr)
46 }
47 }
48
49 func TestIsErrno(t *testing.T) {
50 err := NotFound
51 if !IsErrno(err, err) {
52 t.Errorf("expected match: %v", err)
53 }
54
55 operr := &OpError{
56 Op: "testop",
57 Errno: err,
58 }
59 if !IsErrno(operr, err) {
60 t.Errorf("expected match: %v", operr)
61 }
62 }