mirror of
https://github.com/luscis/openlan.git
synced 2025-10-12 20:10:08 +08:00
clone from danieldin95
This commit is contained in:
63
pkg/models/network_test.go
Executable file
63
pkg/models/network_test.go
Executable file
@@ -0,0 +1,63 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNetworkEqual(t *testing.T) {
|
||||
assert.Equal(t, true, NetworkEqual(nil, nil), "be the same.")
|
||||
o := &Network{}
|
||||
assert.Equal(t, false, NetworkEqual(o, nil), "be the same.")
|
||||
n := &Network{}
|
||||
assert.Equal(t, false, NetworkEqual(nil, n), "be the same.")
|
||||
assert.Equal(t, true, NetworkEqual(n, n), "be the same.")
|
||||
o = &Network{
|
||||
IfAddr: "192.168.1.1",
|
||||
Netmask: "255.255.0.0",
|
||||
Routes: []*Route{
|
||||
{Prefix: "0.0.0.0/24", NextHop: "1.1.1.1."},
|
||||
},
|
||||
}
|
||||
n = &Network{
|
||||
IfAddr: "192.168.1.1",
|
||||
Netmask: "255.255.0.0",
|
||||
Routes: []*Route{
|
||||
{Prefix: "0.0.0.0/24", NextHop: "1.1.1.1."},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, true, NetworkEqual(o, n), "be the same.")
|
||||
o = &Network{
|
||||
IfAddr: "192.168.1.1",
|
||||
Netmask: "255.255.0.0",
|
||||
Routes: []*Route{},
|
||||
}
|
||||
assert.Equal(t, false, NetworkEqual(o, n), "be the same.")
|
||||
assert.Equal(t, false, NetworkEqual(n, o), "be the same.")
|
||||
o = &Network{
|
||||
IfAddr: "192.168.1.1",
|
||||
Netmask: "255.255.0.0",
|
||||
Routes: []*Route{
|
||||
{Prefix: "0.0.0.0/24", NextHop: "1.1.1.1."},
|
||||
{Prefix: "0.0.0.1/24", NextHop: "1.1.1.1."},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, false, NetworkEqual(o, n), "be the same.")
|
||||
assert.Equal(t, false, NetworkEqual(n, o), "be the same.")
|
||||
o = &Network{
|
||||
IfAddr: "192.168.1.1",
|
||||
Netmask: "255.255.0.0",
|
||||
Routes: []*Route{
|
||||
{Prefix: "0.0.0.0/24", NextHop: "1.1.1.1."},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, true, NetworkEqual(o, n), "be the same.")
|
||||
assert.Equal(t, true, NetworkEqual(n, o), "be the same.")
|
||||
o.IfAddr = "182.168.1.1"
|
||||
assert.Equal(t, false, NetworkEqual(o, n), "be the same.")
|
||||
assert.Equal(t, false, NetworkEqual(n, o), "be the same.")
|
||||
o.IfAddr = "192.168.1.1"
|
||||
assert.Equal(t, true, NetworkEqual(o, n), "be the same.")
|
||||
o.IfAddr = "255.255.255.0"
|
||||
assert.Equal(t, false, NetworkEqual(n, o), "be the same.")
|
||||
}
|
Reference in New Issue
Block a user