2019-12-10 23:02:56 +01:00
|
|
|
package ip_manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAll(t *testing.T) {
|
|
|
|
pool, err := GetIPPool()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-13 18:20:41 +01:00
|
|
|
ip, err := pool.GetIP()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Log(ip)
|
|
|
|
pool.ReleaseIP(ip)
|
|
|
|
ip2, err := pool.GetIP()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if ip == ip2 && len(pool.ips) > 1 {
|
|
|
|
t.Fatalf("the same IP was returned twice! %s, %s", ip, ip2)
|
|
|
|
}
|
|
|
|
t.Log(ip2)
|
|
|
|
pool.ReleaseIP(ip2)
|
|
|
|
|
2019-12-10 23:02:56 +01:00
|
|
|
for range pool.ips {
|
2019-12-13 18:20:41 +01:00
|
|
|
_, err = pool.GetIP()
|
2019-12-10 23:02:56 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next, err := pool.nextIP()
|
|
|
|
if err != nil {
|
|
|
|
t.Logf("%s", err.Error())
|
|
|
|
} else {
|
|
|
|
t.Fatal(next)
|
|
|
|
}
|
|
|
|
}
|