I have a function with a sensitive operation:
function doSomeThingSensitive() {
customers = getAllCustomers()
for each customer in customers
if customer is from Europe
Give them a 1000 euro giveaway coupon
}
I want to dry run this function in order to calculate how many sensitive operations (aka the 1000-euro giveaways) will be performed. The dry run function will look something like:
function doSomeThingSensitiveDryRun() {
counter = 0
customers = getAllCustomers()
for each customer in customers
if customer is from Europe
counter++
print 'we will pay ' + counter * 1000
}
The problem with this approach is that the dry run function is not maintainable at all. Any slight change in the initial function will break the logic on the dry run function, which makes its maintenance very difficult. Is there a different way I can approach this?
An idea is to run the initial function as a unit test and stub the sensitive operations. A different idea can be to run the initial function with a Boolean parameter, dryRun
, and if it is set to true, the sensitive operation will not happen. Is there a better and maybe simpler way I can tackle this?
SELECT COUNT(*)
orSELECT *
and iterate over the records. I know not all databases are SQL, but there are ways to get the same results from all the database types I know of.