Skip to content

Commit

Permalink
test: fix test issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Dec 20, 2023
1 parent ba2cad4 commit 33ee73c
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 369 deletions.
40 changes: 8 additions & 32 deletions test/cases/test-address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ TEST_F(Address, soa)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/#4
address /b.com/#6
address /c.com/#
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -135,13 +132,10 @@ TEST_F(Address, ip)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/10.10.10.10
address /a.com/64:ff9b::1010:1010
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -180,13 +174,10 @@ TEST_F(Address, multiaddress)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/10.10.10.10,11.11.11.11,22.22.22.22
address /a.com/64:ff9b::1010:1010,64:ff9b::1111:1111,64:ff9b::2222:2222
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -271,13 +262,10 @@ TEST_F(Address, soa_sub_ip)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/192.168.1.1
address /com/#
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -317,12 +305,9 @@ TEST_F(Address, set_ipv4_query_ipv6)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/192.168.1.1
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -357,12 +342,9 @@ TEST_F(Address, set_ipv6_query_ipv4)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/64:ff9b::1010:1010
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -397,14 +379,11 @@ TEST_F(Address, set_ipv4_allow_ipv6)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/192.168.1.1
address /b.a.com/-6
address /com/#
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -458,14 +437,11 @@ TEST_F(Address, set_both_ipv4_ipv6)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
speed-check-mode none
address /a.com/192.168.1.1
address /b.a.com/64:ff9b::1010:1010
address /com/#
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down
50 changes: 10 additions & 40 deletions test/cases/test-bind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ TEST(Bind, tls)

server.Start(R"""(bind [::]:61053
server-tls 127.0.0.1:60053 -no-check-certificate
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
server_wrap.Start(R"""(bind-tls [::]:60053
address /example.com/1.2.3.4
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("example.com", 61053));
ASSERT_EQ(client.GetAnswerNum(), 1);
Expand All @@ -69,16 +63,10 @@ TEST(Bind, https)

server.Start(R"""(bind [::]:61053
server https://127.0.0.1:60053 -no-check-certificate
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
server_wrap.Start(R"""(bind-https [::]:60053
address /example.com/1.2.3.4
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("example.com", 61053));
ASSERT_EQ(client.GetAnswerNum(), 1);
Expand All @@ -103,10 +91,7 @@ TEST(Bind, udp_tcp)
bind [::]:60053
bind-tcp [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com +tcp", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -141,10 +126,7 @@ bind [::]:60053 -group self
server 127.0.0.1:61053 -group self
bind [::]:61053 -group upstream
server 127.0.0.1:62053 -group upstream
log-num 0
log-console yes
log-level info
cache-persist no)""");
)""");
smartdns::Client client;

ASSERT_TRUE(client.Query("a.com", 60053));
Expand Down Expand Up @@ -174,10 +156,7 @@ TEST(Bind, nocache)
bind [::]:60053 --no-cache
bind-tcp [::]:60053
server 127.0.0.1:61053
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -213,10 +192,7 @@ TEST(Bind, device)
server.Start(R"""(
bind [::]:60053@lo
server 127.0.0.1:62053
log-num 0
log-console yes
log-level info
cache-persist no)""");
)""");
smartdns::Client client;

ASSERT_TRUE(client.Query("a.com", 60053));
Expand Down Expand Up @@ -244,10 +220,8 @@ TEST(Bind, malformed_packet)
server.Start(R"""(
bind [::]:60053@lo
server 127.0.0.1:62053
log-num 0
log-console yes
log-level info
cache-persist no)""");
)""");

int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
ASSERT_NE(sockfd, -1);
Expand Down Expand Up @@ -283,7 +257,6 @@ cache-persist no)""");
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
}


TEST(Bind, group)
{
smartdns::MockServer server_upstream;
Expand Down Expand Up @@ -324,10 +297,7 @@ bind [::]:60253 -group g2
server 127.0.0.1:61053
server 127.0.0.1:62053 -group g1 -exclude-default-group
server 127.0.0.1:63053 -group g2 -exclude-default-group
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down
5 changes: 1 addition & 4 deletions test/cases/test-bootstrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ TEST_F(BootStrap, bootstrap)
server.Start(R"""(bind [::]:60053
server udp://127.0.0.1:62053 -bootstrap-dns
server udp://example.com:61053
log-num 0
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
usleep(2500000);
ASSERT_TRUE(client.Query("a.com", 60053));
Expand Down
39 changes: 7 additions & 32 deletions test/cases/test-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ TEST_F(Cache, min)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
cache-size 1
rr-ttl-min 1
speed-check-mode none
response-mode fastest-response
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -110,15 +107,12 @@ TEST_F(Cache, max_reply_ttl)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
cache-size 1
rr-ttl-min 600
rr-ttl-reply-max 5
speed-check-mode none
response-mode fastest-response
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -166,13 +160,10 @@ TEST_F(Cache, max_reply_ttl_expired)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
cache-size 1
rr-ttl-min 600
rr-ttl-reply-max 6
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -234,14 +225,10 @@ bind [::]:60153 -group g1
server 127.0.0.1:61053
server 127.0.0.1:62053 -group g1 -exclude-default-group
server 127.0.0.1:63053 -group g2
log-num 0
prefetch-domain yes
rr-ttl-max 2
serve-expired no
log-console yes
log-level debug
srv-record-selection no
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand Down Expand Up @@ -303,14 +290,11 @@ TEST_F(Cache, nocache)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
cache-size 100
rr-ttl-min 600
rr-ttl-reply-max 5
log-console yes
log-level debug
domain-rules /a.com/ --no-cache
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com", 60053));
std::cout << client.GetResult() << std::endl;
Expand All @@ -337,9 +321,6 @@ TEST_F(Cache, save_file)
std::string conf = R"""(
bind [::]:60053@lo
server 127.0.0.1:62053
log-num 0
log-console yes
log-level debug
cache-persist yes
dualstack-ip-selection no
)""";
Expand Down Expand Up @@ -390,9 +371,6 @@ TEST_F(Cache, corrupt_file)
std::string conf = R"""(
bind [::]:60053@lo
server 127.0.0.1:62053
log-num 0
log-console yes
log-level debug
dualstack-ip-selection no
cache-persist yes
)""";
Expand Down Expand Up @@ -479,11 +457,8 @@ TEST_F(Cache, cname)

server.Start(R"""(bind [::]:60053
server 127.0.0.1:61053
log-num 0
cache-size 100
log-console yes
log-level debug
cache-persist no)""");
)""");
smartdns::Client client;
ASSERT_TRUE(client.Query("a.com A", 60053));
std::cout << client.GetResult() << std::endl;
Expand All @@ -501,6 +476,6 @@ cache-persist no)""");
ASSERT_EQ(client.GetAnswerNum(), 1);
EXPECT_EQ(client.GetStatus(), "NOERROR");
EXPECT_EQ(client.GetAnswer()[0].GetName(), "cname.a.com");
EXPECT_GE(client.GetAnswer()[0].GetTTL(), 3);
EXPECT_GE(client.GetAnswer()[0].GetTTL(), 590);
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
}
Loading

0 comments on commit 33ee73c

Please sign in to comment.