go.ligato.io/vpp-agent/v3@v3.5.0/pkg/metrics/registry_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 metrics 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 22 "go.ligato.io/vpp-agent/v3/pkg/models" 23 ) 24 25 type TestMetrics struct { 26 TestValue int 27 } 28 29 var n = 0 30 31 func GetTestMetrics() *TestMetrics { 32 return &TestMetrics{ 33 TestValue: n, 34 } 35 } 36 37 func TestRetrieve(t *testing.T) { 38 RegisterTestingT(t) 39 40 models.DefaultRegistry = models.NewRegistry() 41 42 _, err := models.DefaultRegistry.Register(&TestMetrics{}, models.Spec{ 43 Module: "testmodule", 44 Type: "testtype", 45 Class: "metrics", 46 }) 47 Expect(err).ToNot(HaveOccurred()) 48 49 Register(&TestMetrics{}, func() interface{} { 50 return GetTestMetrics() 51 }) 52 53 n = 1 54 55 var metricData TestMetrics 56 err = Retrieve(&metricData) 57 Expect(err).ToNot(HaveOccurred()) 58 Expect(metricData.TestValue).To(Equal(1)) 59 }