test: add coverage for ParallelMap and ParallelFilter workers

Add tests to verify default worker behavior in ParallelMap and
ParallelFilter.
Add internal test to cover unexported Result marker methods for
coverage.
This commit is contained in:
Ruidy 2025-09-01 22:54:03 -04:00
parent 9cf61ec6c5
commit 39be9420c4
No known key found for this signature in database
GPG key ID: 705C24D202990805
4 changed files with 31 additions and 1 deletions

View file

@ -6,7 +6,7 @@ build:
docker build -t $(IMAGE):latest .
test: build
docker run --name $(IMAGE) --rm -i -t $(IMAGE) sh -c "$(TEST) $(COVER)"
docker run --name $(IMAGE) --rm -i $(IMAGE) sh -c "$(TEST) $(COVER)"
scan:
trivy --cache-dir .trivycache/ image --exit-code 0 --no-progress --severity CRITICAL $(IMAGE)

View file

@ -31,3 +31,12 @@ func TestParallelFilter_Error(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, out)
}
func TestParallelFilter_DefaultWorkers(t *testing.T) {
values := []int{1, 2, 3, 4}
out, err := u.ParallelFilter(context.Background(), values, 0, func(_ context.Context, n int) (bool, error) {
return n%2 == 1, nil
})
assert.NoError(t, err)
assert.Equal(t, []int{1, 3}, out)
}

View file

@ -31,3 +31,12 @@ func TestParallelMap_Error(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, out)
}
func TestParallelMap_DefaultWorkers(t *testing.T) {
values := []int{1, 2, 3}
out, err := u.ParallelMap(context.Background(), values, 0, func(_ context.Context, n int) (int, error) {
return n + 1, nil
})
assert.NoError(t, err)
assert.Equal(t, []int{2, 3, 4}, out)
}

12
result_internal_test.go Normal file
View file

@ -0,0 +1,12 @@
package underscore
import "testing"
// Ensure the unexported marker methods are executed for coverage.
func TestResultIsResultMarker(t *testing.T) {
var ok Ok[int]
ok.isResult()
var er Err[int]
er.isResult()
}