update test assertions and cover state time boundaries
Generate check / check-changes (pull_request) Successful in 3s
Generate check / verify-generate (pull_request) Skipped
Quality / check-changes (pull_request) Successful in 2s
Quality / static-checks (pull_request) Successful in 20s
Quality / run-tests (pull_request) Successful in 54s
Generate check / check-changes (pull_request) Successful in 3s
Generate check / verify-generate (pull_request) Skipped
Quality / check-changes (pull_request) Successful in 2s
Quality / static-checks (pull_request) Successful in 20s
Quality / run-tests (pull_request) Successful in 54s
This commit is contained in:
1 parent
79151422b0
commit
b142ce49b3
1 file changed
+25
-5
@@ -9,6 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nmoniz/any2anexoj/internal"
|
"github.com/nmoniz/any2anexoj/internal"
|
||||||
"github.com/nmoniz/any2anexoj/internal/mocks"
|
"github.com/nmoniz/any2anexoj/internal/mocks"
|
||||||
@@ -84,13 +85,25 @@ func TestJSONStore_RoundTrip(t *testing.T) {
|
|||||||
// confirming the inline form is parseable guards against accidentally
|
// confirming the inline form is parseable guards against accidentally
|
||||||
// double-encoding it again in the future).
|
// double-encoding it again in the future).
|
||||||
var parsed struct {
|
var parsed struct {
|
||||||
Queues map[string][]struct {
|
Latest time.Time `json:"latest"`
|
||||||
|
Earliest time.Time `json:"earliest"`
|
||||||
|
Queues map[string][]struct {
|
||||||
RecordData json.RawMessage `json:"record_data"`
|
RecordData json.RawMessage `json:"record_data"`
|
||||||
} `json:"queues"`
|
} `json:"queues"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &parsed); err != nil {
|
if err := json.Unmarshal(data, &parsed); err != nil {
|
||||||
t.Fatalf("saved state file is not valid JSON: %v", err)
|
t.Fatalf("saved state file is not valid JSON: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The latest/earliest bounds must be persisted alongside the queues.
|
||||||
|
// Every record in this test returns testRecordTime, so both bounds must
|
||||||
|
// equal it exactly.
|
||||||
|
if !parsed.Latest.Equal(testRecordTime) {
|
||||||
|
t.Errorf("state latest = %v; want %v", parsed.Latest, testRecordTime)
|
||||||
|
}
|
||||||
|
if !parsed.Earliest.Equal(testRecordTime) {
|
||||||
|
t.Errorf("state earliest = %v; want %v", parsed.Earliest, testRecordTime)
|
||||||
|
}
|
||||||
for symbol, lots := range parsed.Queues {
|
for symbol, lots := range parsed.Queues {
|
||||||
for i, lot := range lots {
|
for i, lot := range lots {
|
||||||
if len(lot.RecordData) == 0 {
|
if len(lot.RecordData) == 0 {
|
||||||
@@ -341,13 +354,20 @@ func TestNewJSONStore_ValidatesArguments(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRecord builds a MockRecord whose Symbol() returns the given symbol.
|
// testRecordTime is the deterministic timestamp returned by every record
|
||||||
// The JSONStore only reads Symbol() off the loaded Record during tests
|
// built in this file. Using a fixed value keeps the latest/earliest bounds
|
||||||
// (quantity/price/filled come from the persisted struct fields), so all
|
// written by JSONStore.Save predictable and assertable.
|
||||||
// other Record methods can be left as default-mocked values.
|
var testRecordTime = time.Date(2024, 6, 15, 12, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
|
// newRecord builds a MockRecord whose Symbol() returns the given symbol and
|
||||||
|
// whose Timestamp() returns testRecordTime. The JSONStore only reads Symbol()
|
||||||
|
// and Timestamp() off the Record during tests (quantity/price/filled come
|
||||||
|
// from the persisted struct fields), so all other Record methods can be left
|
||||||
|
// as default-mocked values.
|
||||||
func newRecord(ctrl *gomock.Controller, symbol string) *mocks.MockRecord {
|
func newRecord(ctrl *gomock.Controller, symbol string) *mocks.MockRecord {
|
||||||
r := mocks.NewMockRecord(ctrl)
|
r := mocks.NewMockRecord(ctrl)
|
||||||
r.EXPECT().Symbol().Return(symbol).AnyTimes()
|
r.EXPECT().Symbol().Return(symbol).AnyTimes()
|
||||||
|
r.EXPECT().Timestamp().Return(testRecordTime).AnyTimes()
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user