From 2c87e7708621c29fe840d32595df12cc11f223b1 Mon Sep 17 00:00:00 2001 From: ascandone Date: Tue, 15 Oct 2024 19:11:44 +0200 Subject: [PATCH] feat: renamed Machine into NumscriptRuntime --- .../controller/ledger/controller_default.go | 2 +- .../ledger/controller_default_test.go | 8 ++--- internal/controller/ledger/machine.go | 18 +++++------ internal/controller/ledger/machine_factory.go | 6 ++-- .../ledger/machine_factory_generated_test.go | 4 +-- .../ledger/machine_generated_test.go | 30 +++++++++---------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/internal/controller/ledger/controller_default.go b/internal/controller/ledger/controller_default.go index a4a92b89b..d5d8bdf56 100644 --- a/internal/controller/ledger/controller_default.go +++ b/internal/controller/ledger/controller_default.go @@ -261,7 +261,7 @@ func (ctrl *DefaultController) createTransaction(ctx context.Context, sqlTX TX, "ExecuteMachine", ctrl.tracer, ctrl.executeMachineHistogram, - func(ctx context.Context) (*MachineResult, error) { + func(ctx context.Context) (*NumscriptExecutionResult, error) { return m.Execute(ctx, sqlTX, parameters.Input.Vars) }, ) diff --git a/internal/controller/ledger/controller_default_test.go b/internal/controller/ledger/controller_default_test.go index 627ab6fa2..e6165068f 100644 --- a/internal/controller/ledger/controller_default_test.go +++ b/internal/controller/ledger/controller_default_test.go @@ -24,7 +24,7 @@ func TestCreateTransaction(t *testing.T) { ctrl := gomock.NewController(t) store := NewMockStore(ctrl) - machine := NewMockMachine(ctrl) + numscriptRuntime := NewMockNumscriptRuntime(ctrl) parser := NewMockNumscriptParser(ctrl) sqlTX := NewMockTX(ctrl) @@ -34,7 +34,7 @@ func TestCreateTransaction(t *testing.T) { parser.EXPECT(). Parse(runScript.Plain). - Return(machine, nil) + Return(numscriptRuntime, nil) store.EXPECT(). WithTX(gomock.Any(), nil, gomock.Any()). @@ -44,9 +44,9 @@ func TestCreateTransaction(t *testing.T) { }) posting := ledger.NewPosting("world", "bank", "USD", big.NewInt(100)) - machine.EXPECT(). + numscriptRuntime.EXPECT(). Execute(gomock.Any(), sqlTX, runScript.Vars). - Return(&MachineResult{ + Return(&NumscriptExecutionResult{ Postings: ledger.Postings{posting}, }, nil) diff --git a/internal/controller/ledger/machine.go b/internal/controller/ledger/machine.go index 98f1cc216..13ba97c1e 100644 --- a/internal/controller/ledger/machine.go +++ b/internal/controller/ledger/machine.go @@ -15,23 +15,23 @@ import ( "github.com/formancehq/ledger/internal/machine/vm/program" ) -type MachineResult struct { +type NumscriptExecutionResult struct { Postings ledger.Postings `json:"postings"` Metadata metadata.Metadata `json:"metadata"` AccountMetadata map[string]metadata.Metadata } //go:generate mockgen -write_source_comment=false -write_package_comment=false -source machine.go -destination machine_generated_test.go -package ledger . Machine -type Machine interface { - Execute(context.Context, TX, map[string]string) (*MachineResult, error) +type NumscriptRuntime interface { + Execute(context.Context, TX, map[string]string) (*NumscriptExecutionResult, error) } -type DefaultMachineAdapter struct { +type MachineNumscriptRuntimeAdapter struct { program program.Program machine *vm.Machine } -func (d *DefaultMachineAdapter) Execute(ctx context.Context, tx TX, vars map[string]string) (*MachineResult, error) { +func (d *MachineNumscriptRuntimeAdapter) Execute(ctx context.Context, tx TX, vars map[string]string) (*NumscriptExecutionResult, error) { store := newVmStoreAdapter(tx) d.machine = vm.NewMachine(d.program) @@ -65,7 +65,7 @@ func (d *DefaultMachineAdapter) Execute(ctx context.Context, tx TX, vars map[str } } - return &MachineResult{ + return &NumscriptExecutionResult{ Postings: collectionutils.Map(d.machine.Postings, func(from vm.Posting) ledger.Posting { return ledger.Posting{ Source: from.Source, @@ -79,10 +79,10 @@ func (d *DefaultMachineAdapter) Execute(ctx context.Context, tx TX, vars map[str }, nil } -func NewDefaultMachine(p program.Program) *DefaultMachineAdapter { - return &DefaultMachineAdapter{ +func NewMachineNumscriptRuntimeAdapter(p program.Program) *MachineNumscriptRuntimeAdapter { + return &MachineNumscriptRuntimeAdapter{ program: p, } } -var _ Machine = (*DefaultMachineAdapter)(nil) +var _ NumscriptRuntime = (*MachineNumscriptRuntimeAdapter)(nil) diff --git a/internal/controller/ledger/machine_factory.go b/internal/controller/ledger/machine_factory.go index ef96a10b1..4902134f2 100644 --- a/internal/controller/ledger/machine_factory.go +++ b/internal/controller/ledger/machine_factory.go @@ -5,19 +5,19 @@ package ledger type NumscriptParser interface { // Parse can return following errors: // * ErrCompilationFailed - Parse(script string) (Machine, error) + Parse(script string) (NumscriptRuntime, error) } type DefaultNumscriptParser struct { compiler Compiler } -func (d *DefaultNumscriptParser) Parse(script string) (Machine, error) { +func (d *DefaultNumscriptParser) Parse(script string) (NumscriptRuntime, error) { ret, err := d.compiler.Compile(script) if err != nil { return nil, err } - return NewDefaultMachine(*ret), nil + return NewMachineNumscriptRuntimeAdapter(*ret), nil } func NewDefaultMachineFactory(compiler Compiler) *DefaultNumscriptParser { diff --git a/internal/controller/ledger/machine_factory_generated_test.go b/internal/controller/ledger/machine_factory_generated_test.go index af26e407f..d9c4c863e 100644 --- a/internal/controller/ledger/machine_factory_generated_test.go +++ b/internal/controller/ledger/machine_factory_generated_test.go @@ -35,10 +35,10 @@ func (m *MockNumscriptParser) EXPECT() *MockNumscriptParserMockRecorder { } // Parse mocks base method. -func (m *MockNumscriptParser) Parse(script string) (Machine, error) { +func (m *MockNumscriptParser) Parse(script string) (NumscriptRuntime, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Parse", script) - ret0, _ := ret[0].(Machine) + ret0, _ := ret[0].(NumscriptRuntime) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/controller/ledger/machine_generated_test.go b/internal/controller/ledger/machine_generated_test.go index 049b6690d..81f17bda4 100644 --- a/internal/controller/ledger/machine_generated_test.go +++ b/internal/controller/ledger/machine_generated_test.go @@ -12,40 +12,40 @@ import ( gomock "go.uber.org/mock/gomock" ) -// MockMachine is a mock of Machine interface. -type MockMachine struct { +// MockNumscriptRuntime is a mock of NumscriptRuntime interface. +type MockNumscriptRuntime struct { ctrl *gomock.Controller - recorder *MockMachineMockRecorder + recorder *MockNumscriptRuntimeMockRecorder } -// MockMachineMockRecorder is the mock recorder for MockMachine. -type MockMachineMockRecorder struct { - mock *MockMachine +// MockNumscriptRuntimeMockRecorder is the mock recorder for MockNumscriptRuntime. +type MockNumscriptRuntimeMockRecorder struct { + mock *MockNumscriptRuntime } -// NewMockMachine creates a new mock instance. -func NewMockMachine(ctrl *gomock.Controller) *MockMachine { - mock := &MockMachine{ctrl: ctrl} - mock.recorder = &MockMachineMockRecorder{mock} +// NewMockNumscriptRuntime creates a new mock instance. +func NewMockNumscriptRuntime(ctrl *gomock.Controller) *MockNumscriptRuntime { + mock := &MockNumscriptRuntime{ctrl: ctrl} + mock.recorder = &MockNumscriptRuntimeMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockMachine) EXPECT() *MockMachineMockRecorder { +func (m *MockNumscriptRuntime) EXPECT() *MockNumscriptRuntimeMockRecorder { return m.recorder } // Execute mocks base method. -func (m *MockMachine) Execute(arg0 context.Context, arg1 TX, arg2 map[string]string) (*MachineResult, error) { +func (m *MockNumscriptRuntime) Execute(arg0 context.Context, arg1 TX, arg2 map[string]string) (*NumscriptExecutionResult, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Execute", arg0, arg1, arg2) - ret0, _ := ret[0].(*MachineResult) + ret0, _ := ret[0].(*NumscriptExecutionResult) ret1, _ := ret[1].(error) return ret0, ret1 } // Execute indicates an expected call of Execute. -func (mr *MockMachineMockRecorder) Execute(arg0, arg1, arg2 any) *gomock.Call { +func (mr *MockNumscriptRuntimeMockRecorder) Execute(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockMachine)(nil).Execute), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockNumscriptRuntime)(nil).Execute), arg0, arg1, arg2) }