58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package utility
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func chaosMonkeyA(t *testing.T) error {
|
|
t.Logf("chaosMonkeyA")
|
|
return errors.New("chaosMonkeyA")
|
|
}
|
|
|
|
func chaosMonkeyB(t *testing.T) (string, error) {
|
|
t.Logf("chaosMonkeyB")
|
|
return "chaosMonkeyB", errors.New("chaosMonkeyB")
|
|
}
|
|
|
|
func iAmWalkingInLine(t *testing.T) (float64, error) {
|
|
t.Logf("iAmWalkingInLine")
|
|
return 88888888.88888888, nil
|
|
}
|
|
|
|
func TestMust(t *testing.T) {
|
|
func() {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
t.Logf("caseA: should panic, %s", err)
|
|
} else {
|
|
t.Fatalf("caseA: should panic, but didn't")
|
|
}
|
|
}()
|
|
Must(chaosMonkeyA(t))
|
|
}()
|
|
func() {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
t.Logf("caseB: should panic, %s", err)
|
|
} else {
|
|
t.Fatalf("caseB: should panic, but didn't")
|
|
}
|
|
}()
|
|
var value string
|
|
MustGet(chaosMonkeyB(t)).Value(&value)
|
|
}()
|
|
func() {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
t.Fatalf("caseC: should not panic, but paniced %s", err)
|
|
} else {
|
|
t.Logf("caseC: everything went fine")
|
|
}
|
|
}()
|
|
var value float64
|
|
MustGet(iAmWalkingInLine(t)).Value(&value)
|
|
t.Logf("caseC: value, %f", value)
|
|
}()
|
|
}
|