~egtann/srp

srp/api_test.go -rw-r--r-- 479 bytes
b28e623a — Evan Tann fix deadlock on peristent http requests 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package srp

import (
	"net"
	"testing"
)

func TestMaskIP(t *testing.T) {
	ip := "10.128.0.0/24"
	maskedIP, mask, err := maskIP(ip)
	if err != nil {
		t.Fatal(err)
	}

	ip = "10.128.0.10"
	if maskedIP != net.ParseIP(ip).Mask(mask).String() {
		t.Fatal("expected match")
	}

	ip = "1.1.1.1"
	if maskedIP == net.ParseIP(ip).Mask(mask).String() {
		t.Fatal("expected no match")
	}

	ip = ""
	if maskedIP == net.ParseIP(ip).Mask(mask).String() {
		t.Fatal("expected no match")
	}
}