(t *testing.T)
| 1253 | } |
| 1254 | |
| 1255 | func TestGetMonitorByID_NotFound(t *testing.T) { |
| 1256 | db, mock, err := sqlmock.New() |
| 1257 | assert.NoError(t, err) |
| 1258 | defer func() { _ = db.Close() }() |
| 1259 | |
| 1260 | ds := Datasource{Conn: db} |
| 1261 | |
| 1262 | query := ` |
| 1263 | SELECT monitor_id, balance_id, field, operator, value, precision, precise_value, description, call_back_url, created_at |
| 1264 | FROM ledgerforge.balance_monitors WHERE monitor_id = $1 |
| 1265 | ` |
| 1266 | |
| 1267 | mock.ExpectQuery(regexp.QuoteMeta(query)). |
| 1268 | WithArgs("mon_nonexistent"). |
| 1269 | WillReturnError(sql.ErrNoRows) |
| 1270 | |
| 1271 | monitor, err := ds.GetMonitorByID("mon_nonexistent") |
| 1272 | assert.Error(t, err) |
| 1273 | assert.Nil(t, monitor) |
| 1274 | apiErr, ok := err.(apierror.APIError) |
| 1275 | assert.True(t, ok) |
| 1276 | assert.Equal(t, apierror.ErrNotFound, apiErr.Code) |
| 1277 | |
| 1278 | err = mock.ExpectationsWereMet() |
| 1279 | assert.NoError(t, err) |
| 1280 | } |
| 1281 | |
| 1282 | func TestGetAllMonitors_Success(t *testing.T) { |
| 1283 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected