From bf07e75bae33feb6382a2a645fccfc61ab218ded Mon Sep 17 00:00:00 2001 From: Lz Date: Fri, 8 Mar 2024 17:12:07 +0800 Subject: [PATCH] fix(tests): updated tests --- .gitignore | 1 + CHANGELOG.md | 9 +++++++++ README.md | 3 ++- awaiter_test.go | 25 ++++++++++++++++++++++++- coverage.txt | 40 ++++++++++++++++++++++------------------ 5 files changed, 58 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 3b735ec..9b82006 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29..2b24c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index ffae43b..4abf8c2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -46,7 +47,7 @@ if err == nil { } ``` -see more [examples](./awaiter_test.go?L13) + ### WaitAny wait any task to completed diff --git a/awaiter_test.go b/awaiter_test.go index 3dd10d4..1a70893 100644 --- a/awaiter_test.go +++ b/awaiter_test.go @@ -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 @@ -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 { diff --git a/coverage.txt b/coverage.txt index 3e656eb..b481701 100644 --- a/coverage.txt +++ b/coverage.txt @@ -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