diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-06-05 14:03:13 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-06-05 20:05:52 +0900 |
commit | c78328019756dca6912b69d7ecfcb850f727513f (patch) | |
tree | be974cd413df20ecd7568007fefc6d24f6fd0e38 | |
parent | 5d15b3f290a4305e0c8b7d651834c997d2b09910 (diff) |
cmd/rpki_test: Unit test for showRPKITable
Adds an unit test for ed3f7b711c92c69bf231bc9e6a06312b23270db0
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | gobgp/cmd/rpki_test.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/gobgp/cmd/rpki_test.go b/gobgp/cmd/rpki_test.go new file mode 100644 index 00000000..985681e6 --- /dev/null +++ b/gobgp/cmd/rpki_test.go @@ -0,0 +1,78 @@ +// Copyright (C) 2018 Nippon Telegraph and Telephone Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + + api "github.com/osrg/gobgp/api" + "github.com/osrg/gobgp/config" + "github.com/osrg/gobgp/server" +) + +func TestShowRPKITable(test *testing.T) { + assert := assert.New(test) + + s := server.NewBgpServer() + go s.Serve() + + g := api.NewGrpcServer(s, ":50051") + go g.Serve() + + err := s.Start(&config.Global{ + Config: config.GlobalConfig{ + As: 1, + RouterId: "1.1.1.1", + Port: -1, + }, + }) + assert.Nil(err) + defer s.Stop() + + // MF RPKI Project + // http://www.mfeed.ad.jp/rpki/en/roa_cache/technical_info.html + rpki := &config.RpkiServerConfig{ + Address: "210.173.170.254", + Port: 323, + } + err = s.AddRpki(rpki) + assert.Nil(err) + + globalOpts.Host = "127.0.0.1" + globalOpts.Port = 50051 + client = newClient() + defer client.Close() + + // Wait for downloading ROA info + for i := 0; ; i++ { + if servers, err := s.GetRpki(); err == nil && len(servers) > 0 { + if servers[0].State.RecordsV4 > 0 { + break + } + } + if i > 10 { + test.Error("timeout to download ROA info") + break + } + time.Sleep(1 * time.Second) + } + + err = showRPKITable(nil) + assert.Nil(err) +} |