MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestCreateAccount_QueryError

Function TestCreateAccount_QueryError

database/account_test.go:180–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestCreateAccount_QueryError(t *testing.T) {
181 db, mock, err := sqlmock.New()
182 assert.NoError(t, err)
183 defer func() { _ = db.Close() }()
184
185 ds := Datasource{Conn: db}
186
187 account := model.Account{
188 Name: "Test Account",
189 Number: "1234567890",
190 BankName: "Test Bank",
191 Currency: "USD",
192 LedgerID: "ldg1",
193 IdentityID: "idt1",
194 BalanceID: "bal1",
195 MetaData: map[string]interface{}{},
196 }
197
198 metaDataJSON, err := json.Marshal(account.MetaData)
199 assert.NoError(t, err)
200
201 mock.ExpectExec("INSERT INTO ledgerforge.accounts").
202 WithArgs(sqlmock.AnyArg(), account.Name, account.Number, account.BankName, account.Currency, account.LedgerID, account.IdentityID, account.BalanceID, sqlmock.AnyArg(), metaDataJSON).
203 WillReturnError(fmt.Errorf("database connection error"))
204
205 _, err = ds.CreateAccount(account)
206 assert.Error(t, err)
207}
208
209func TestGetAccountByID_NotFound(t *testing.T) {
210 db, mock, err := sqlmock.New()

Callers

nothing calls this directly

Calls 3

CreateAccountMethod · 0.95
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected