Shit ton of tests
This commit is contained in:
parent
99b00887a8
commit
ccf98c2f6e
13 changed files with 1157 additions and 1 deletions
55
other/other_test.go
Normal file
55
other/other_test.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
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)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package other
|
||||
|
||||
// Can't really test zerolog setup functions as they rely on
|
||||
// CLI flags
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io"
|
||||
|
@ -72,5 +75,4 @@ func configOutputs(logWriter io.Writer) {
|
|||
append([]io.Writer{log.Logger}, extraLogWriters...)...,
|
||||
)).With().Timestamp().Logger()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue