implement reporter

also introduce gomock and tests
This commit is contained in:
2025-11-11 16:35:05 +00:00
parent 38113f21af
commit 7a38ae1696
10 changed files with 493 additions and 78 deletions

42
internal/reporter_test.go Normal file
View File

@@ -0,0 +1,42 @@
package internal_test
import (
"io"
"math/big"
"testing"
"git.naterciomoniz.net/applications/broker2anexoj/internal"
"git.naterciomoniz.net/applications/broker2anexoj/internal/mocks"
"go.uber.org/mock/gomock"
)
func TestReporter_Run(t *testing.T) {
ctrl := gomock.NewController(t)
rec := mocks.NewMockRecord(ctrl)
rec.EXPECT().Price().Return(big.NewFloat(1.25)).AnyTimes()
rec.EXPECT().Quantity().Return(big.NewFloat(10)).AnyTimes()
rec.EXPECT().Side().Return(internal.SideBuy).AnyTimes()
rec.EXPECT().Symbol().Return("TEST").AnyTimes()
reader := mocks.NewMockRecordReader(ctrl)
records := []internal.Record{
rec,
rec,
}
reader.EXPECT().ReadRecord().DoAndReturn(func() (internal.Record, error) {
if len(records) > 0 {
r := records[0]
records = records[1:]
return r, nil
} else {
return nil, io.EOF
}
}).AnyTimes()
reporter := internal.NewReporter(reader)
gotErr := reporter.Run()
if gotErr != nil {
t.Fatalf("got unexpected err: %v", gotErr)
}
}