The two statements "the connection can be made" and "I am able to proceed with what I intend to do" are far from equivalent, and a simple TCP connection test like Test-NetConnection
does not at all test the same thing as an actual git clone
.
Being able to open a TCP connection to a port does not imply access to the service listening on that port. There are many stages after the initial connect that may fail, such as TLS negotiations, authentication, authorization or application level protocol exchanges.
Also, firewall restrictions are not the only possible reason for a TCP connection to fail, and failures of the TCP connection are not the only possible effect of a firewall restriction. So your statements:
If I cannot access the site on a particular port, then that means I would need to modify the firewall before proceeding.
and
Otherwise, if I can reach the site, then I would be able to proceed with what I intend to do.
are both wrong.
This means that, instead of wondering why your Test-NetConnection
test did not detect the problem that later caused your GitHub access to fail, you should analyze what that problem actually was, and then evaluate whether detecting that particular problem in advance would provide any benefit. If the answer is yes, you can then devise a test to do just that.
In practice, frequently the most efficient course of action is to just try the intended operation without any preceding tests, and handle any errors as they occur. Checking for problems in advance mostly only makes sense if they can be fixed automatically or if trying and failing the actual operation carries a substantial cost or risk.
Specifically, GitHub operations fail rather gracefully and with reasonably clear indication of the cause of failure, so I see no direct benefit in testing the connection first instead of just trying the intended operation directly.