git-lfs/errors/errors_test.go

76 lines
1.4 KiB
Go
Raw Normal View History

2016-08-18 20:20:33 +00:00
package errors
2015-08-21 19:33:00 +00:00
import (
"errors"
"testing"
)
func TestChecksHandleGoErrors(t *testing.T) {
err := errors.New("go error")
2015-08-21 19:33:00 +00:00
if IsFatalError(err) {
t.Error("go error should not be a fatal error")
}
}
func TestCheckHandlesWrappedErrors(t *testing.T) {
err := errors.New("go error")
2015-08-21 19:33:00 +00:00
2016-05-17 13:40:05 +00:00
fatal := NewFatalError(err)
2015-08-21 19:33:00 +00:00
if !IsFatalError(fatal) {
t.Error("expected error to be fatal")
}
}
func TestBehaviorWraps(t *testing.T) {
err := errors.New("go error")
2015-08-21 19:33:00 +00:00
2016-05-17 13:40:05 +00:00
fatal := NewFatalError(err)
ni := NewNotImplementedError(fatal)
2015-08-21 19:33:00 +00:00
if !IsNotImplementedError(ni) {
t.Error("expected erro to be not implemeted")
}
if !IsFatalError(ni) {
t.Error("expected wrapped error to also be fatal")
}
if IsNotImplementedError(fatal) {
t.Error("expected fatal error to not be not implemented")
}
}
func TestContextOnGoErrors(t *testing.T) {
err := errors.New("go error")
2015-08-21 19:33:00 +00:00
2016-08-19 20:03:39 +00:00
SetContext(err, "foo", "bar")
2015-08-21 19:33:00 +00:00
2016-08-19 20:03:39 +00:00
v := GetContext(err, "foo")
2015-08-21 19:33:00 +00:00
if v == "bar" {
t.Error("expected empty context on go error")
}
}
func TestContextOnWrappedErrors(t *testing.T) {
err := NewFatalError(errors.New("go error"))
2015-08-21 19:33:00 +00:00
2016-08-19 20:03:39 +00:00
SetContext(err, "foo", "bar")
2015-08-21 19:33:00 +00:00
2016-08-19 20:03:39 +00:00
if v := GetContext(err, "foo"); v != "bar" {
2015-08-21 19:33:00 +00:00
t.Error("expected to be able to use context on wrapped errors")
}
2016-08-19 20:03:39 +00:00
ctxt := Context(err)
2015-08-21 19:33:00 +00:00
if ctxt["foo"] != "bar" {
t.Error("expected to get the context of an error")
}
2016-08-19 20:03:39 +00:00
DelContext(err, "foo")
2015-08-21 19:33:00 +00:00
2016-08-19 20:03:39 +00:00
if v := GetContext(err, "foo"); v == "bar" {
2015-08-21 19:33:00 +00:00
t.Errorf("expected to delete from error context")
}
}