Debian Codegraph @

exception_test.go

raw
1 package raven
2
3 import (
4 "encoding/json"
5 "errors"
6 "testing"
7 )
8
9 var newExceptionTests = []struct {
10 err error
11 Exception
12 }{
13 {errors.New("foobar"), Exception{Value: "foobar", Type: "*errors.errorString"}},
14 {errors.New("bar: foobar"), Exception{Value: "foobar", Type: "*errors.errorString", Module: "bar"}},
15 }
16
17 func TestNewException(t *testing.T) {
18 for _, test := range newExceptionTests {
19 actual := NewException(test.err, nil)
20 if actual.Value != test.Value {
21 t.Errorf("incorrect Value: got %s, want %s", actual.Value, test.Value)
22 }
23 if actual.Type != test.Type {
24 t.Errorf("incorrect Type: got %s, want %s", actual.Type, test.Type)
25 }
26 if actual.Module != test.Module {
27 t.Errorf("incorrect Module: got %s, want %s", actual.Module, test.Module)
28 }
29 }
30 }
31
32 func TestNewException_JSON(t *testing.T) {
33 expected := `{"value":"foobar","type":"*errors.errorString"}`
34 e := NewException(errors.New("foobar"), nil)
35 b, _ := json.Marshal(e)
36 if string(b) != expected {
37 t.Errorf("incorrect JSON: got %s, want %s", string(b), expected)
38 }
39 }