server: add unit tests

Make test coverage >= 90%

#1019 
check the error before you check resp.