cloudflare-dns-cli/main_test.go

47 lines
875 B
Go
Raw Permalink Normal View History

2023-03-23 18:57:30 -04:00
package main
import (
"fmt"
2023-04-10 14:16:23 -04:00
"net"
2023-03-23 18:57:30 -04:00
"testing"
)
func TestParseRange(t *testing.T) {
expected := []int{0, 1, 2, 6}
actual := parseRange("0-2,-5,6,-7-7,1, 11", 10)
if fmt.Sprint(expected) != fmt.Sprint(actual) {
2023-04-10 14:16:23 -04:00
t.Errorf("unexpected %#v\n", actual)
}
}
2024-01-18 16:18:27 -05:00
func TestParseRangeEmpty(t *testing.T) {
expectedLen := 0
actual := parseRange("", 10)
if expectedLen != len(actual) {
t.Errorf("unexpected %#v\n", actual)
}
}
2023-04-10 14:16:23 -04:00
func TestParseIP(t *testing.T) {
var ip net.IP
if err := ip.UnmarshalText([]byte("127.0.0.1")); err != nil {
t.Error(err)
}
if ip.To4() == nil {
t.Error("Failed to parse ipv4")
}
if ip.To16() == nil {
t.Error("Failed to parse as ipv6")
}
if err := ip.UnmarshalText([]byte("::1")); err != nil {
t.Error(err)
}
if ip.To16() == nil {
t.Error("Failed to parse ipv6")
}
if ip.To4() != nil {
t.Error("ipv6 parsed as ipv4")
2023-03-23 18:57:30 -04:00
}
}