mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: doc and parameter order
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
3
samples/readfile/data/file1.json
Normal file
3
samples/readfile/data/file1.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"data": "file1"
|
||||
}
|
3
samples/readfile/data/file2.json
Normal file
3
samples/readfile/data/file2.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"data": "file2"
|
||||
}
|
3
samples/readfile/data/file3.json
Normal file
3
samples/readfile/data/file3.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"data": "file3"
|
||||
}
|
@@ -2,8 +2,10 @@ package readfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
A "github.com/IBM/fp-go/array"
|
||||
R "github.com/IBM/fp-go/context/readerioeither"
|
||||
"github.com/IBM/fp-go/context/readerioeither/file"
|
||||
E "github.com/IBM/fp-go/either"
|
||||
@@ -22,7 +24,7 @@ type RecordType struct {
|
||||
func TestReadSingleFile(t *testing.T) {
|
||||
|
||||
data := F.Pipe2(
|
||||
file.ReadFile("./file.json"),
|
||||
file.ReadFile("./data/file.json"),
|
||||
R.ChainEitherK(J.Unmarshal[RecordType]),
|
||||
R.ChainFirstIOK(IO.Logf[RecordType]("Log: %v")),
|
||||
)
|
||||
@@ -31,3 +33,26 @@ func TestReadSingleFile(t *testing.T) {
|
||||
|
||||
assert.Equal(t, E.Of[error](RecordType{"Carsten"}), result())
|
||||
}
|
||||
|
||||
func idxToFilename(idx int) string {
|
||||
return fmt.Sprintf("./data/file%d.json", idx+1)
|
||||
}
|
||||
|
||||
// TestReadMultipleFiles reads the content of a multiple from disk and parses them into
|
||||
// structs
|
||||
func TestReadMultipleFiles(t *testing.T) {
|
||||
|
||||
data := F.Pipe2(
|
||||
A.MakeBy(3, idxToFilename),
|
||||
R.TraverseArray(F.Flow3(
|
||||
file.ReadFile,
|
||||
R.ChainEitherK(J.Unmarshal[RecordType]),
|
||||
R.ChainFirstIOK(IO.Logf[RecordType]("Log Single: %v")),
|
||||
)),
|
||||
R.ChainFirstIOK(IO.Logf[[]RecordType]("Log Result: %v")),
|
||||
)
|
||||
|
||||
result := data(context.Background())
|
||||
|
||||
assert.Equal(t, E.Of[error](A.From(RecordType{"file1"}, RecordType{"file2"}, RecordType{"file3"})), result())
|
||||
}
|
||||
|
Reference in New Issue
Block a user