go-pattern-examples/resiliency/04_retrier/classifier_test.go

60 lines
1.2 KiB
Go
Raw Permalink Normal View History

2020-05-03 05:52:05 +03:00
package retrier
import (
"testing"
)
func TestDefaultClassifier(t *testing.T) {
c := DefaultClassifier{}
if c.Classify(nil) != Succeed {
t.Error("default misclassified nil")
}
if c.Classify(errFoo) != Retry {
t.Error("default misclassified foo")
}
if c.Classify(errBar) != Retry {
t.Error("default misclassified bar")
}
if c.Classify(errBaz) != Retry {
t.Error("default misclassified baz")
}
}
func TestWhitelistClassifier(t *testing.T) {
c := WhitelistClassifier{errFoo, errBar}
if c.Classify(nil) != Succeed {
t.Error("whitelist misclassified nil")
}
if c.Classify(errFoo) != Retry {
t.Error("whitelist misclassified foo")
}
if c.Classify(errBar) != Retry {
t.Error("whitelist misclassified bar")
}
if c.Classify(errBaz) != Fail {
t.Error("whitelist misclassified baz")
}
}
func TestBlacklistClassifier(t *testing.T) {
c := BlacklistClassifier{errBar}
if c.Classify(nil) != Succeed {
t.Error("blacklist misclassified nil")
}
if c.Classify(errFoo) != Retry {
t.Error("blacklist misclassified foo")
}
if c.Classify(errBar) != Fail {
t.Error("blacklist misclassified bar")
}
if c.Classify(errBaz) != Retry {
t.Error("blacklist misclassified baz")
}
}