-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep_by_step_test.go
More file actions
49 lines (40 loc) · 1.08 KB
/
step_by_step_test.go
File metadata and controls
49 lines (40 loc) · 1.08 KB
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
/*
* Copyright (c) 2024-2025 Mikhail Knyazhev <markus621@yandex.com>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/
package do_test
import (
"fmt"
"testing"
"go.osspkg.com/casecheck"
"go.osspkg.com/do"
)
func TestUnit_StepByStep(t *testing.T) {
sbs := do.NewStepByStep[string]()
sbs.Add(func(s string) (string, error) {
return s + "a", nil
})
sbs.Add(func(s string) (string, error) {
return s + "b", nil
})
v, err := sbs.Exec("123")
casecheck.NoError(t, err)
casecheck.Equal(t, "123ab", v)
sbs.Add(func(s string) (string, error) {
switch s {
case "000ab":
return s, fmt.Errorf("1")
case "111ab":
panic("0")
default:
return s, nil
}
})
_, err = sbs.Exec("000")
casecheck.Error(t, err)
casecheck.Equal(t, "fail on step #3: 1", err.Error())
_, err = sbs.Exec("111")
casecheck.Error(t, err)
casecheck.Contains(t, err.Error(), "panic on step #3: panic=0 trace=./step_by_step_test.go")
casecheck.Contains(t, err.Error(), "go.osspkg.com/do_test.TestUnit_StepByStep.func3")
}