-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult_test.go
50 lines (41 loc) · 1.07 KB
/
result_test.go
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
41
42
43
44
45
46
47
48
49
50
package async_test
import (
"errors"
"testing"
"github.com/41north/async.go"
"github.com/stretchr/testify/assert"
)
func ExampleNewResult() {
result := async.NewResultValue[string]("success")
v, _ := result.Unwrap()
println(v)
}
func ExampleNewResultErr() {
result := async.NewResultErr[string](errors.New("failure"))
_, err := result.Unwrap()
panic(err)
}
func TestNewResult(t *testing.T) {
r := async.NewResult[string]("hello", nil)
value, err := r.Unwrap()
assert.Equal(t, "hello", value)
assert.Nil(t, err)
expected := errors.New("something bad happened")
r = async.NewResult[string]("", expected)
value, err = r.Unwrap()
assert.Equal(t, "", value)
assert.Equal(t, expected, err)
}
func TestNewResultValue(t *testing.T) {
r := async.NewResultValue[string]("hello")
value, err := r.Unwrap()
assert.Equal(t, "hello", value)
assert.Nil(t, err)
}
func TestNewResultErr(t *testing.T) {
expected := errors.New("something bad happened")
r := async.NewResultErr[string](expected)
value, err := r.Unwrap()
assert.Equal(t, "", value)
assert.Equal(t, expected, err)
}