1 // Copyright (c) 2019 Cisco and/or its affiliates.
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:
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // Package mock is an alternative VPP stats adapter aimed for unit/integration testing where the
16 // actual communication with VPP is not demanded.
21 "git.fd.io/govpp.git/adapter"
24 // StatsAdapter simulates VPP stats socket from which stats can be read
25 type StatsAdapter struct {
26 entries []*adapter.StatEntry
29 // NewStatsAdapter returns a new mock stats adapter.
30 func NewStatsAdapter() *StatsAdapter {
31 return &StatsAdapter{}
34 // Connect mocks client connection to the stats API.
35 func (a *StatsAdapter) Connect() error {
39 // Disconnect mocks client connection termination.
40 func (a *StatsAdapter) Disconnect() error {
44 // ListStats mocks name listing for all stats.
45 func (a *StatsAdapter) ListStats(patterns ...string) ([]string, error) {
46 var statNames []string
47 for _, stat := range a.entries {
48 statNames = append(statNames, stat.Name)
53 // DumpStats mocks all stat entries dump.
54 func (a *StatsAdapter) DumpStats(patterns ...string) ([]*adapter.StatEntry, error) {
58 // MockStats replaces current values of all supported stats by provided value
59 func (a *StatsAdapter) MockStats(stats []*adapter.StatEntry) {