diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-17 02:06:22 -0500 |
---|---|---|
committer | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-11-17 21:52:20 -0500 |
commit | 24e397b0f65b1c5294ea711a953501fda944411d (patch) | |
tree | 6a08d7863516465fc1c421cfd20805f2c209f833 | |
parent | a3e262f3a83fedeeabc5c7820a6d42b54e0325c1 (diff) |
add go vet test
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | client/client.go | 20 | ||||
-rw-r--r-- | gobgp/cmd/global.go | 4 | ||||
-rw-r--r-- | gobgp/cmd/mrt.go | 2 | ||||
-rw-r--r-- | gobgp/cmd/neighbor.go | 4 | ||||
-rw-r--r-- | gobgp/cmd/policy.go | 4 | ||||
-rw-r--r-- | packet/bgp/bgp_test.go | 10 | ||||
-rw-r--r-- | server/fsm_test.go | 2 | ||||
-rw-r--r-- | server/server.go | 2 | ||||
-rw-r--r-- | server/sockopt_linux_test.go | 6 | ||||
-rw-r--r-- | table/adj.go | 2 | ||||
-rw-r--r-- | table/policy.go | 12 | ||||
-rw-r--r-- | table/policy_test.go | 22 |
13 files changed, 55 insertions, 39 deletions
diff --git a/.travis.yml b/.travis.yml index 40ef667c..bd3c9dae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,10 @@ matrix: script: test -z "$(go fmt ./...)" - go: 1.7 before_install: true + install: true + script: test -z "$(go vet ./...)" + - go: 1.7 + before_install: true install: go get ./... script: python test/scenario_test/ci-scripts/build_embeded_go.py docs/sources/lib.md - env: diff --git a/client/client.go b/client/client.go index a2107637..abc22161 100644 --- a/client/client.go +++ b/client/client.go @@ -151,13 +151,13 @@ func (cli *GoBGPClient) GetNeighbor(name string) (*config.Neighbor, error) { func (cli *GoBGPClient) AddNeighbor(c *config.Neighbor) error { peer := api.NewPeerFromConfigStruct(c) - _, err := cli.cli.AddNeighbor(context.Background(), &api.AddNeighborRequest{peer}) + _, err := cli.cli.AddNeighbor(context.Background(), &api.AddNeighborRequest{Peer: peer}) return err } func (cli *GoBGPClient) DeleteNeighbor(c *config.Neighbor) error { peer := api.NewPeerFromConfigStruct(c) - _, err := cli.cli.DeleteNeighbor(context.Background(), &api.DeleteNeighborRequest{peer}) + _, err := cli.cli.DeleteNeighbor(context.Background(), &api.DeleteNeighborRequest{Peer: peer}) return err } @@ -165,22 +165,22 @@ func (cli *GoBGPClient) DeleteNeighbor(c *config.Neighbor) error { //} func (cli *GoBGPClient) ShutdownNeighbor(addr string) error { - _, err := cli.cli.ShutdownNeighbor(context.Background(), &api.ShutdownNeighborRequest{addr}) + _, err := cli.cli.ShutdownNeighbor(context.Background(), &api.ShutdownNeighborRequest{Address: addr}) return err } func (cli *GoBGPClient) ResetNeighbor(addr string) error { - _, err := cli.cli.ResetNeighbor(context.Background(), &api.ResetNeighborRequest{addr}) + _, err := cli.cli.ResetNeighbor(context.Background(), &api.ResetNeighborRequest{Address: addr}) return err } func (cli *GoBGPClient) EnableNeighbor(addr string) error { - _, err := cli.cli.EnableNeighbor(context.Background(), &api.EnableNeighborRequest{addr}) + _, err := cli.cli.EnableNeighbor(context.Background(), &api.EnableNeighborRequest{Address: addr}) return err } func (cli *GoBGPClient) DisableNeighbor(addr string) error { - _, err := cli.cli.DisableNeighbor(context.Background(), &api.DisableNeighborRequest{addr}) + _, err := cli.cli.DisableNeighbor(context.Background(), &api.DisableNeighborRequest{Address: addr}) return err } @@ -705,20 +705,22 @@ func (cli *GoBGPClient) GetRouteServerExportPolicy(name string) (*table.PolicyAs func (cli *GoBGPClient) AddPolicyAssignment(assignment *table.PolicyAssignment) error { _, err := cli.cli.AddPolicyAssignment(context.Background(), &api.AddPolicyAssignmentRequest{ - api.NewAPIPolicyAssignmentFromTableStruct(assignment), + Assignment: api.NewAPIPolicyAssignmentFromTableStruct(assignment), }) return err } func (cli *GoBGPClient) DeletePolicyAssignment(assignment *table.PolicyAssignment, all bool) error { a := api.NewAPIPolicyAssignmentFromTableStruct(assignment) - _, err := cli.cli.DeletePolicyAssignment(context.Background(), &api.DeletePolicyAssignmentRequest{a, all}) + _, err := cli.cli.DeletePolicyAssignment(context.Background(), &api.DeletePolicyAssignmentRequest{ + Assignment: a, + All: all}) return err } func (cli *GoBGPClient) ReplacePolicyAssignment(assignment *table.PolicyAssignment) error { _, err := cli.cli.ReplacePolicyAssignment(context.Background(), &api.ReplacePolicyAssignmentRequest{ - api.NewAPIPolicyAssignmentFromTableStruct(assignment), + Assignment: api.NewAPIPolicyAssignmentFromTableStruct(assignment), }) return err } diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index 651d6866..097847e8 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -197,7 +197,7 @@ func encapParser(args []string) ([]bgp.ExtendedCommunityInterface, error) { isTransitive := true o := bgp.NewOpaqueExtended(isTransitive) o.SubType = bgp.EC_SUBTYPE_ENCAPSULATION - o.Value = &bgp.EncapExtended{typ} + o.Value = &bgp.EncapExtended{TunnelType: typ} return []bgp.ExtendedCommunityInterface{o}, nil } @@ -219,7 +219,7 @@ func validationParser(args []string) ([]bgp.ExtendedCommunityInterface, error) { isTransitive := false o := bgp.NewOpaqueExtended(isTransitive) o.SubType = bgp.EC_SUBTYPE_ORIGIN_VALIDATION - o.Value = &bgp.ValidationExtended{typ} + o.Value = &bgp.ValidationExtended{Value: typ} return []bgp.ExtendedCommunityInterface{o}, nil } diff --git a/gobgp/cmd/mrt.go b/gobgp/cmd/mrt.go index c548a677..67703682 100644 --- a/gobgp/cmd/mrt.go +++ b/gobgp/cmd/mrt.go @@ -80,7 +80,7 @@ func injectMrt(filename string, count int, skip int, onlyBest bool) error { peers = msg.Body.(*mrt.PeerIndexTable).Peers continue default: - exitWithError(fmt.Errorf("unsupported subType: %s", subType)) + exitWithError(fmt.Errorf("unsupported subType: %v", subType)) } if peers == nil { diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go index 318fc05b..324e21f0 100644 --- a/gobgp/cmd/neighbor.go +++ b/gobgp/cmd/neighbor.go @@ -655,7 +655,7 @@ func showNeighborPolicy(remoteIP, policyType string, indent int) error { case "export": assignment, err = client.GetRouteServerExportPolicy(remoteIP) default: - fmt.Errorf("invalid policy type: choose from (in|import|export)") + return fmt.Errorf("invalid policy type: choose from (in|import|export)") } if err != nil { @@ -669,7 +669,7 @@ func showNeighborPolicy(remoteIP, policyType string, indent int) error { } fmt.Printf("%s policy:\n", strings.Title(policyType)) - fmt.Printf("%sDefault: %s\n", strings.Repeat(" ", indent), assignment.Default) + fmt.Printf("%sDefault: %s\n", strings.Repeat(" ", indent), assignment.Default.String()) for _, p := range assignment.Policies { fmt.Printf("%sName %s:\n", strings.Repeat(" ", indent), p.Name) printPolicy(indent+4, p) diff --git a/gobgp/cmd/policy.go b/gobgp/cmd/policy.go index 4b475b51..aa614d50 100644 --- a/gobgp/cmd/policy.go +++ b/gobgp/cmd/policy.go @@ -719,7 +719,7 @@ func modAction(name, op string, args []string) error { } case "med": if len(args) < 2 { - return fmt.Errorf("%s med { add | sub | set } <value>") + return fmt.Errorf("%s med { add | sub | set } <value>", usage) } med, err := strconv.Atoi(args[1]) if err != nil { @@ -733,7 +733,7 @@ func modAction(name, op string, args []string) error { case "set": stmt.Actions.BgpActions.SetMed = config.BgpSetMedType(fmt.Sprintf("%d", med)) default: - return fmt.Errorf("%s med { add | sub | set } <value>") + return fmt.Errorf("%s med { add | sub | set } <value>", usage) } case "local-pref": if len(args) < 1 { diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index c46144cc..34cdaff2 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -450,11 +450,11 @@ func Test_FlowSpecNlriL2(t *testing.T) { func Test_NotificationErrorCode(t *testing.T) { // boundary check - NewNotificationErrorCode(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_TYPE).String() - NewNotificationErrorCode(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_TYPE+1).String() - NewNotificationErrorCode(BGP_ERROR_MESSAGE_HEADER_ERROR, 0).String() - NewNotificationErrorCode(0, BGP_ERROR_SUB_BAD_MESSAGE_TYPE).String() - NewNotificationErrorCode(BGP_ERROR_ROUTE_REFRESH_MESSAGE_ERROR+1, 0).String() + t.Log(NewNotificationErrorCode(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_TYPE).String()) + t.Log(NewNotificationErrorCode(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_TYPE+1).String()) + t.Log(NewNotificationErrorCode(BGP_ERROR_MESSAGE_HEADER_ERROR, 0).String()) + t.Log(NewNotificationErrorCode(0, BGP_ERROR_SUB_BAD_MESSAGE_TYPE).String()) + t.Log(NewNotificationErrorCode(BGP_ERROR_ROUTE_REFRESH_MESSAGE_ERROR+1, 0).String()) } func Test_FlowSpecNlriVPN(t *testing.T) { diff --git a/server/fsm_test.go b/server/fsm_test.go index 5e31c67a..0fb67f98 100644 --- a/server/fsm_test.go +++ b/server/fsm_test.go @@ -309,7 +309,7 @@ func open() *bgp.BGPMessage { []bgp.ParameterCapabilityInterface{bgp.NewCapRouteRefresh()}) p2 := bgp.NewOptionParameterCapability( []bgp.ParameterCapabilityInterface{bgp.NewCapMultiProtocol(bgp.RF_IPv4_UC)}) - g := &bgp.CapGracefulRestartTuple{4, 2, 3} + g := &bgp.CapGracefulRestartTuple{AFI: 4, SAFI: 2, Flags: 3} p3 := bgp.NewOptionParameterCapability( []bgp.ParameterCapabilityInterface{bgp.NewCapGracefulRestart(true, true, 100, []*bgp.CapGracefulRestartTuple{g})}) diff --git a/server/server.go b/server/server.go index d71e45b2..aaa69e7d 100644 --- a/server/server.go +++ b/server/server.go @@ -2515,7 +2515,7 @@ func (w *Watcher) Generate(t WatchEventType) (err error) { } w.notify(&WatchEventTable{PathList: pathList, Neighbor: l}) default: - err = fmt.Errorf("unsupported type ", t) + err = fmt.Errorf("unsupported type %v", t) return } } diff --git a/server/sockopt_linux_test.go b/server/sockopt_linux_test.go index e3ef65d9..f78431af 100644 --- a/server/sockopt_linux_test.go +++ b/server/sockopt_linux_test.go @@ -32,9 +32,8 @@ func Test_buildTcpMD5Sig(t *testing.T) { buf1 := make([]uint8, 216) p := unsafe.Pointer(&s) - src := uintptr(p) for i := uintptr(0); i < 216; i++ { - buf1[i] = *(*byte)(unsafe.Pointer(src + i)) + buf1[i] = *(*byte)(unsafe.Pointer(uintptr(p) + i)) } buf2 := []uint8{2, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -51,9 +50,8 @@ func Test_buildTcpMD5Sigv6(t *testing.T) { buf1 := make([]uint8, 216) p := unsafe.Pointer(&s) - src := uintptr(p) for i := uintptr(0); i < 216; i++ { - buf1[i] = *(*byte)(unsafe.Pointer(src + i)) + buf1[i] = *(*byte)(unsafe.Pointer(uintptr(p) + i)) } buf2 := []uint8{10, 0, 0, 0, 0, 0, 0, 0, 254, 128, 0, 0, 0, 0, 0, 0, 72, 80, 49, 255, 254, 1, 252, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 119, 111, 114, 108, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} diff --git a/table/adj.go b/table/adj.go index ea7b4151..f1843859 100644 --- a/table/adj.go +++ b/table/adj.go @@ -192,7 +192,7 @@ func (adj *AdjRib) Select(family bgp.RouteFamily, accepted bool, option ...Table func (adj *AdjRib) TableInfo(family bgp.RouteFamily) (*TableInfo, error) { if _, ok := adj.table[family]; !ok { - return nil, fmt.Errorf("%s unsupported") + return nil, fmt.Errorf("%s unsupported", family) } c := adj.Count([]bgp.RouteFamily{family}) a := adj.Accepted([]bgp.RouteFamily{family}) diff --git a/table/policy.go b/table/policy.go index 7ac8a6c3..1d055b57 100644 --- a/table/policy.go +++ b/table/policy.go @@ -56,6 +56,18 @@ const ( ROUTE_TYPE_REJECT ) +func (t RouteType) String() string { + switch t { + case ROUTE_TYPE_NONE: + return "continue" + case ROUTE_TYPE_ACCEPT: + return "accept" + case ROUTE_TYPE_REJECT: + return "reject" + } + return fmt.Sprintf("unknown(%d)", t) +} + type PolicyDirection int const ( diff --git a/table/policy_test.go b/table/policy_test.go index 58b944e2..c3a04433 100644 --- a/table/policy_test.go +++ b/table/policy_test.go @@ -2862,8 +2862,8 @@ func TestPrefixSetMatch(t *testing.T) { func TestLargeCommunityMatchAction(t *testing.T) { coms := []*bgp.LargeCommunity{ - &bgp.LargeCommunity{100, 100, 100}, - &bgp.LargeCommunity{100, 200, 200}, + &bgp.LargeCommunity{ASN: 100, LocalData1: 100, LocalData2: 100}, + &bgp.LargeCommunity{ASN: 100, LocalData1: 200, LocalData2: 200}, } p := NewPath(nil, nil, false, []bgp.PathAttributeInterface{bgp.NewPathAttributeLargeCommunities(coms)}, time.Time{}, false) @@ -2887,10 +2887,10 @@ func TestLargeCommunityMatchAction(t *testing.T) { assert.Equal(t, m.Evaluate(p, nil), true) a, err := NewLargeCommunityAction(config.SetLargeCommunity{ - config.SetLargeCommunityMethod{ - []string{"100:100:100"}, + SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + CommunitiesList: []string{"100:100:100"}, }, - config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, }) assert.Equal(t, err, nil) p = a.Apply(p, nil) @@ -2898,13 +2898,13 @@ func TestLargeCommunityMatchAction(t *testing.T) { assert.Equal(t, m.Evaluate(p, nil), false) a, err = NewLargeCommunityAction(config.SetLargeCommunity{ - config.SetLargeCommunityMethod{ - []string{ + SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + CommunitiesList: []string{ "100:300:100", "200:100:100", }, }, - config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD, + Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_ADD, }) assert.Equal(t, err, nil) p = a.Apply(p, nil) @@ -2912,10 +2912,10 @@ func TestLargeCommunityMatchAction(t *testing.T) { assert.Equal(t, m.Evaluate(p, nil), true) a, err = NewLargeCommunityAction(config.SetLargeCommunity{ - config.SetLargeCommunityMethod{ - []string{"^100:"}, + SetLargeCommunityMethod: config.SetLargeCommunityMethod{ + CommunitiesList: []string{"^100:"}, }, - config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, + Options: config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE, }) assert.Equal(t, err, nil) p = a.Apply(p, nil) |