For general anesthesia, a lot of doctors will drug test nowadays, especially with the opioid epidemic and how many people are actually addicted to them now.
I actually woke up in the middle of my TTE because the anesthesiologist didn't compensate for my addiction and known drug use, and I woke up in the middle of it with the camera down my throat.
It was actually an anesthesiologist tech, and the anesthesiologist was trying to multitask two patients - he was fired, although I have no clue if it was specifically because of what happened with me or a culmination of errors or what the case was.
Anyways, if you're going to be put under anesthesia, it really is in your best interest to be honest. If the surgery requires pain management after, the doctor won't make you suffer in agonizing pain because you used heroin.
You may get opioids for a shorter period of time, but it will be used in conjunction with other pain medications, which honestly work better than opioids alone depending on the pain.