File: exception_test.go

package info (click to toggle)
golang-raven-go 0.2.0%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 228 kB
  • sloc: makefile: 3; sh: 3
file content (39 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download
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
package raven

import (
	"encoding/json"
	"errors"
	"testing"
)

var newExceptionTests = []struct {
	err error
	Exception
}{
	{errors.New("foobar"), Exception{Value: "foobar", Type: "*errors.errorString"}},
	{errors.New("bar: foobar"), Exception{Value: "foobar", Type: "*errors.errorString", Module: "bar"}},
}

func TestNewException(t *testing.T) {
	for _, test := range newExceptionTests {
		actual := NewException(test.err, nil)
		if actual.Value != test.Value {
			t.Errorf("incorrect Value: got %s, want %s", actual.Value, test.Value)
		}
		if actual.Type != test.Type {
			t.Errorf("incorrect Type: got %s, want %s", actual.Type, test.Type)
		}
		if actual.Module != test.Module {
			t.Errorf("incorrect Module: got %s, want %s", actual.Module, test.Module)
		}
	}
}

func TestNewException_JSON(t *testing.T) {
	expected := `{"value":"foobar","type":"*errors.errorString"}`
	e := NewException(errors.New("foobar"), nil)
	b, _ := json.Marshal(e)
	if string(b) != expected {
		t.Errorf("incorrect JSON: got %s, want %s", string(b), expected)
	}
}