mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 03:11:02 +01:00
7ebe58f20a
* Add DNS list argument for mobile client * Write testable code Many places are checked the wgInterface != nil condition. It is doing it just because to avoid the real wgInterface creation for tests. Instead of this involve a wgInterface interface what is moc-able. * Refactor the DNS server internal code structure With the fake resolver has been involved several if-else statement and generated some unused variables to distinguish the listener and fake resolver solutions at running time. With this commit the fake resolver and listener based solution has been moved into two separated structure. Name of this layer is the 'service'. With this modification the unit test looks simpler and open the option to add new logic for the permanent DNS service usage for mobile systems. * Remove is running check in test We can not ensure the state well so remove this check. The test will fail if the server is not running well.
32 lines
615 B
Go
32 lines
615 B
Go
package dns
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetLastIPFromNetwork(t *testing.T) {
|
|
tests := []struct {
|
|
addr string
|
|
ip string
|
|
}{
|
|
{"2001:db8::/32", "2001:db8:ffff:ffff:ffff:ffff:ffff:fffe"},
|
|
{"192.168.0.0/30", "192.168.0.2"},
|
|
{"192.168.0.0/16", "192.168.255.254"},
|
|
{"192.168.0.0/24", "192.168.0.254"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
_, ipnet, err := net.ParseCIDR(tt.addr)
|
|
if err != nil {
|
|
t.Errorf("Error parsing CIDR: %v", err)
|
|
return
|
|
}
|
|
|
|
lastIP := getLastIPFromNetwork(ipnet, 1)
|
|
if lastIP != tt.ip {
|
|
t.Errorf("wrong IP address, expected %s: got %s", tt.ip, lastIP)
|
|
}
|
|
}
|
|
}
|