Simulating no internet connection

Hi all,

catch e 
   if e isa (Sockets.DNSError)
      # print message 
   elseif e isa (HTTP.StatusError) 
      # print message 
# ... 

I know that the Sockets.DNSError can either be triggered by an invalid URL or having no internet connection when running the program, but the former isn’t an option within my program anyway so I need to go for the latter by simulating no internet connection.

Does anybody know of a way to programmatically simulate having no internet connection for testing purposes? I’m mainly looking to improve my code coverage test results and also just generally check that in my runtests.jl file that I am accounting for behavior arising from no internet connection.


I can think of ways to get the OS to prevent you from having internet. On Linux you can shove your program into a network namespace with no internet connection. But it requires certain permissions and I don’t think you can do it easily from within julia. You could run a shell script that started up a Julia session within a NetNS though.