go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/import_test.go (about) 1 // Copyright (c) 2019 Cisco and/or its affiliates. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package vpp_test 16 17 import ( 18 "bytes" 19 "fmt" 20 "log" 21 "os" 22 "reflect" 23 "sort" 24 "testing" 25 "text/tabwriter" 26 27 "go.fd.io/govpp/api" 28 29 "go.ligato.io/vpp-agent/v3/plugins/vpp" 30 31 // force import of all vpp plugins 32 _ "go.ligato.io/vpp-agent/v3/cmd/vpp-agent/app" 33 ) 34 35 func TestVppHandlers(t *testing.T) { 36 handlers := vpp.GetHandlers() 37 log.Printf("%d handlers:", len(handlers)) 38 39 for h, handler := range handlers { 40 log.Printf("- handler: %-10s (%v)", h, handler.Versions()) 41 } 42 } 43 44 func TestBinapiMessage(t *testing.T) { 45 msgTypes := api.GetRegisteredMessageTypes() 46 log.Printf("%d binapi messages:", len(msgTypes)) 47 48 type item struct { 49 message string 50 crc string 51 pkgPath string 52 } 53 items := []item{} 54 for _, path := range msgTypes { 55 for msgType := range path { 56 typ := msgType.Elem() 57 msg := reflect.New(typ).Interface().(api.Message) 58 t := item{msg.GetMessageName(), msg.GetCrcString(), typ.PkgPath()} 59 items = append(items, t) 60 } 61 } 62 63 sort.Slice(items, func(i, j int) bool { 64 if items[i].pkgPath == items[j].pkgPath { 65 return items[i].message < items[j].message 66 } 67 return items[i].pkgPath < items[j].pkgPath 68 }) 69 70 b := new(bytes.Buffer) 71 w := tabwriter.NewWriter(b, 0, 0, 1, ' ', 0) 72 fmt.Fprintf(w, "MESSAGE\tCRC\tPKG PATH\t\n") 73 for _, item := range items { 74 // typ := msgType.Elem() 75 // msg := reflect.New(typ).Interface().(api.Message) 76 // id := fmt.Sprintf("%s_%s", msg.GetMessageName(), msg.GetCrcString()) 77 // log.Printf("- msg: %s - %s (%v)", typ.String(), typ.PkgPath(), id) 78 // fmt.Fprintf(w, "%s\t%s\t%s\t\n", msg.GetMessageName(), msg.GetCrcString(), typ.PkgPath()) 79 fmt.Fprintf(w, "%s\t%s\t%s\t\n", item.message, item.crc, item.pkgPath) 80 } 81 if err := w.Flush(); err != nil { 82 return 83 } 84 fmt.Fprintf(os.Stdout, "%s", b) 85 }