-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmust_test.go
More file actions
40 lines (31 loc) · 727 Bytes
/
Copy pathmust_test.go
File metadata and controls
40 lines (31 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package coda_test
import (
"errors"
"testing"
"github.com/marnixbouhuis/coda"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMust(t *testing.T) {
t.Parallel()
t.Run("should panic on error", func(t *testing.T) {
t.Parallel()
expectedErr := errors.New("look at me, I'm an error")
fn := func() (string, error) {
return "", expectedErr
}
require.PanicsWithError(t, expectedErr.Error(), func() {
coda.Must(fn())
})
})
t.Run("should not panic on success", func(t *testing.T) {
t.Parallel()
fn := func() (string, error) {
return "success", nil
}
require.NotPanics(t, func() {
res := coda.Must(fn())
assert.Equal(t, "success", res)
})
})
}