Skip to content

Commit

Permalink
Merge pull request #2 from rakelkar/rakelkar/netroute
Browse files Browse the repository at this point in the history
make structs and member public so that can be consumed, also add Exit…
  • Loading branch information
rakelkar authored Sep 30, 2017
2 parents 7426d58 + 59aa2f5 commit 58f4435
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 13 additions & 9 deletions netroute/netroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ type Interface interface {

// Remove an existing route
RemoveNetRoute(linkIndex int, destinationSubnet *net.IPNet, gatewayAddress net.IP) error

// exit the shell
Exit()
}

type Route struct {
linkIndex int
destinationSubnet *net.IPNet
gatewayAddress net.IP
routeMetric int
ifMetric int
LinkIndex int
DestinationSubnet *net.IPNet
GatewayAddress net.IP
RouteMetric int
IfMetric int
}

type shell struct {
Expand All @@ -53,6 +56,7 @@ func New() Interface {

func (shell *shell) Exit() {
shell.shellInstance.Exit()
shell.shellInstance = nil
}

func (shell *shell) GetNetRoutesAll() ([]Route, error) {
Expand Down Expand Up @@ -116,9 +120,9 @@ func parseRoutesList(stdout string) []Route {
continue
}
route := Route{
destinationSubnet: destinationSubnet,
gatewayAddress: gatewayAddress,
linkIndex: linkIndex,
DestinationSubnet: destinationSubnet,
GatewayAddress: gatewayAddress,
LinkIndex: linkIndex,
}

routes = append(routes, route)
Expand All @@ -128,7 +132,7 @@ func parseRoutesList(stdout string) []Route {
}

func (r *Route) Equal(route Route) bool {
if r.destinationSubnet.IP.Equal(route.destinationSubnet.IP) && r.gatewayAddress.Equal(route.gatewayAddress) && bytes.Equal(r.destinationSubnet.Mask, route.destinationSubnet.Mask) {
if r.DestinationSubnet.IP.Equal(route.DestinationSubnet.IP) && r.GatewayAddress.Equal(route.GatewayAddress) && bytes.Equal(r.DestinationSubnet.Mask, route.DestinationSubnet.Mask) {
return true
}

Expand Down
6 changes: 3 additions & 3 deletions netroute/netroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func GetAllRoutesTest(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t,3, len(routes))
assert.Equal(t, "192.168.10.0/24", routes[2].destinationSubnet.String())
assert.Equal(t, 12, routes[2].linkIndex)
assert.Equal(t, "10.244.0.1", routes[2].gatewayAddress)
assert.Equal(t, "192.168.10.0/24", routes[2].DestinationSubnet.String())
assert.Equal(t, 12, routes[2].LinkIndex)
assert.Equal(t, "10.244.0.1", routes[2].GatewayAddress)
assert.True(t, routes[0].Equal(routes[0]))
assert.False(t, routes[0].Equal(routes[1]))
}
Expand Down

0 comments on commit 58f4435

Please sign in to comment.