test: add test for mock server and bind option

This commit is contained in:
Nick Peng
2023-03-16 20:03:01 +08:00
parent 47f2f45c37
commit 455dca9ae4
7 changed files with 137 additions and 19 deletions

View File

@@ -65,7 +65,13 @@ struct ServerRequestContext {
int response_data_len;
};
using ServerRequest = std::function<bool(struct ServerRequestContext *request)>;
typedef enum {
SERVER_REQUEST_OK = 0,
SERVER_REQUEST_ERROR,
SERVER_REQUEST_SOA,
} ServerRequestResult;
using ServerRequest = std::function<ServerRequestResult(struct ServerRequestContext *request)>;
class MockServer
{
@@ -77,10 +83,12 @@ class MockServer
void Stop();
bool IsRunning();
static bool AddIP(struct ServerRequestContext *request, const std::string &domain, const std::string &ip, int ttl = 60);
private:
void Run();
bool GetAddr(const std::string &host, const std::string port, int type, int protocol, struct sockaddr_storage *addr,
static bool GetAddr(const std::string &host, const std::string port, int type, int protocol, struct sockaddr_storage *addr,
socklen_t *addrlen);
int fd_;
std::thread thread_;