go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/001_telemetry_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 16 17 import ( 18 "testing" 19 20 "go.ligato.io/vpp-agent/v3/plugins/telemetry/vppcalls" 21 22 _ "go.ligato.io/vpp-agent/v3/plugins/telemetry" 23 ) 24 25 func TestTelemetryNodeCounters(t *testing.T) { 26 test := setupVPP(t) 27 defer test.teardownVPP() 28 29 h := vppcalls.CompatibleTelemetryHandler(test.vppClient) 30 if h == nil { 31 t.Fatalf("telemetry handler not available") 32 } 33 34 nodeCounters, err := h.GetNodeCounters(test.Ctx) 35 if err != nil { 36 t.Fatalf("getting node counters failed: %v", err) 37 } 38 t.Logf("retrieved %d node counters", len(nodeCounters.Counters)) 39 if nodeCounters.Counters == nil { 40 t.Fatal("expected node counters, got nil") 41 } 42 if len(nodeCounters.Counters) == 0 { 43 t.Fatalf("expected node counters length > 0, got %v", len(nodeCounters.Counters)) 44 } 45 } 46 47 func TestTelemetryInterfaceStats(t *testing.T) { 48 test := setupVPP(t) 49 defer test.teardownVPP() 50 51 h := vppcalls.CompatibleTelemetryHandler(test.vppClient) 52 if h == nil { 53 t.Fatalf("telemetry handler not available") 54 } 55 56 ifStats, err := h.GetInterfaceStats(test.Ctx) 57 if err != nil { 58 t.Fatalf("getting interface stats failed: %v", err) 59 } else { 60 t.Logf("retrieved interface stats: %+v", ifStats) 61 } 62 if ifStats == nil || ifStats.Interfaces == nil { 63 t.Fatal("expected interface stats, got nil") 64 } 65 if len(ifStats.Interfaces) == 0 { 66 t.Fatalf("expected memory stats length > 0, got %v", len(ifStats.Interfaces)) 67 } 68 }