package other_test import ( "errors" "testing" "git.mstar.dev/mstar/goutils/other" ) func TestOutputIntoChannel(t *testing.T) { c := make(chan int) go func() { other.OutputIntoChannel(10, c) }() x := <-c if x != 10 { t.Fatalf("sent %v, expected 10", x) } } func TestMust_mustPanic(t *testing.T) { defer func() { if r := recover(); r == nil { t.Fatal("Must didn't panic on error") } }() _ = other.Must(10, errors.New("some error")) } func TestMust_noPanic(t *testing.T) { defer func() { if r := recover(); r != nil { t.Fatalf("Must panicked: %v", r) } }() x := other.Must(10, nil) if x != 10 { t.Fatalf("got %v, expected 10", x) } } func TestIntoPointer(t *testing.T) { p := other.IntoPointer(10) if *p != 10 { t.Fatalf("other.IntoPointer(10) = %v, want &10", p) } } func TestError(t *testing.T) { e := errors.New("some error") we := other.Error("source", "message", e) if we.Error() != "source: message: some error" { t.Fatalf("Got %v, expected \"source: message: some error\"", we) } }