Skip to content

Commit

Permalink
fix(tests): updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi committed Mar 8, 2024
1 parent 794a72b commit bf07e75
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.txt

# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2024-03-08
- 1st release
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Async is an asynchronous task package for Go.
- Works with generic instead of `interface{}`

## Tutorials
see more [examples](./awaiter_test.go)

### Install async
- install latest commit from `main` branch
Expand Down Expand Up @@ -46,7 +47,7 @@ if err == nil {
}
```
see more [examples](./awaiter_test.go?L13)


### WaitAny
wait any task to completed
Expand Down
25 changes: 24 additions & 1 deletion awaiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func TestWait(t *testing.T) {
func TestWaitAny(t *testing.T) {

wantedErr := errors.New("wanted")
//var wantedErrs error = Errors([]error{wantedErr, wantedErr})

tests := []struct {
name string
Expand Down Expand Up @@ -229,6 +228,30 @@ func TestWaitAny(t *testing.T) {
},
wantedResult: 1,
},
{
name: "errors_should_work",
ctx: func() context.Context { return context.Background() },
setup: func() Awaiter[int] {
return New[int](func(ctx context.Context) (int, error) {
return 0, wantedErr
}, func(ctx context.Context) (int, error) {
return 0, wantedErr
}, func(ctx context.Context) (int, error) {
return 0, wantedErr
})
},
wantedError: Errors([]error{wantedErr, wantedErr, wantedErr}),
},
{
name: "error_should_work",
ctx: func() context.Context { return context.Background() },
setup: func() Awaiter[int] {
return New[int](func(ctx context.Context) (int, error) {
return 0, wantedErr
})
},
wantedError: Errors([]error{wantedErr}),
},
{
name: "context_should_work",
ctx: func() context.Context {
Expand Down
40 changes: 22 additions & 18 deletions coverage.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
mode: atomic
github.com/yaitoo/async/async.go:5.75,9.2 1 3
github.com/yaitoo/async/awaiter.go:17.69,19.2 1 0
github.com/yaitoo/async/awaiter.go:21.61,25.31 3 3
github.com/yaitoo/async/awaiter.go:25.31,26.50 1 9
github.com/yaitoo/async/awaiter.go:26.50,32.4 2 9
github.com/yaitoo/async/awaiter.go:35.2,39.25 4 3
github.com/yaitoo/async/awaiter.go:39.25,40.10 1 8
github.com/yaitoo/async/awaiter.go:41.19,42.22 1 7
github.com/yaitoo/async/async.go:5.75,9.2 1 12
github.com/yaitoo/async/awaiter.go:17.69,19.2 1 2
github.com/yaitoo/async/awaiter.go:21.61,25.31 3 4
github.com/yaitoo/async/awaiter.go:25.31,26.50 1 12
github.com/yaitoo/async/awaiter.go:26.50,32.4 2 12
github.com/yaitoo/async/awaiter.go:35.2,39.25 4 4
github.com/yaitoo/async/awaiter.go:39.25,40.10 1 10
github.com/yaitoo/async/awaiter.go:41.19,42.22 1 8
github.com/yaitoo/async/awaiter.go:42.22,44.5 1 1
github.com/yaitoo/async/awaiter.go:44.10,46.5 1 6
github.com/yaitoo/async/awaiter.go:47.21,48.27 1 1
github.com/yaitoo/async/awaiter.go:44.10,46.5 1 7
github.com/yaitoo/async/awaiter.go:47.21,48.27 1 2
github.com/yaitoo/async/awaiter.go:53.2,53.17 1 2
github.com/yaitoo/async/awaiter.go:53.17,55.3 1 1
github.com/yaitoo/async/awaiter.go:57.2,57.19 1 1
github.com/yaitoo/async/awaiter.go:60.62,68.31 5 0
github.com/yaitoo/async/awaiter.go:68.31,69.50 1 0
github.com/yaitoo/async/awaiter.go:69.50,75.4 2 0
github.com/yaitoo/async/awaiter.go:78.2,81.25 3 0
github.com/yaitoo/async/awaiter.go:81.25,83.21 2 0
github.com/yaitoo/async/awaiter.go:83.21,85.4 1 0
github.com/yaitoo/async/awaiter.go:87.3,87.27 1 0
github.com/yaitoo/async/awaiter.go:90.2,91.14 2 0
github.com/yaitoo/async/awaiter.go:60.62,68.31 5 8
github.com/yaitoo/async/awaiter.go:68.31,69.50 1 24
github.com/yaitoo/async/awaiter.go:69.50,75.4 2 24
github.com/yaitoo/async/awaiter.go:78.2,83.25 4 8
github.com/yaitoo/async/awaiter.go:83.25,84.10 1 12
github.com/yaitoo/async/awaiter.go:85.19,86.22 1 10
github.com/yaitoo/async/awaiter.go:86.22,88.5 1 5
github.com/yaitoo/async/awaiter.go:90.4,90.28 1 5
github.com/yaitoo/async/awaiter.go:91.21,92.23 1 2
github.com/yaitoo/async/awaiter.go:96.2,96.17 1 1
github.com/yaitoo/async/awaiter.go:96.17,98.3 1 1
github.com/yaitoo/async/awaiter.go:100.2,100.15 1 0
github.com/yaitoo/async/errors.go:7.33,9.2 1 0

0 comments on commit bf07e75

Please sign in to comment.