blob: 4a1353e09093045302b15d65a1d29a0684110219 [file] [log] [blame]
gerardo.laurenzi63ab5d12019-11-07 11:05:27 +00001/*
Joey Armstrong7f8436c2023-07-09 20:23:27 -04002 * Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors
gerardo.laurenzi63ab5d12019-11-07 11:05:27 +00003
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package common
18
19import (
20 "fmt"
21 "github.com/stretchr/testify/assert"
22 "testing"
23)
24
25func pmNamesInit() []string {
26 pmNames := make([]string, 5)
27
28 for i := 0; i < len(pmNames); i++ {
29 pmNames[i] = fmt.Sprintf("pmName%d", i)
30 }
31 return pmNames
32}
33func TestNewPmMetrics(t *testing.T) {
34 //pm := &PmMetrics{deviceId: "deviceId"}
35 pm := NewPmMetrics("device1", Frequency(380000), Grouped(false))
36 //t.Logf(" freq --> %d" , pm.frequency)
37 assert.NotNil(t, pm)
38 assert.Equal(t, "device1", pm.deviceId, "device error")
39 assert.Equal(t, fmt.Sprint(380000), fmt.Sprint(pm.frequency), "frequency error")
40
41 pmNames := pmNamesInit()
42
43 pm2 := NewPmMetrics("device2", Frequency(380000), Grouped(false), FrequencyOverride(false), Metrics(pmNames))
44 assert.NotNil(t, pm2)
45}
46
47func TestPmConfig(t *testing.T) {
48 pm := NewPmMetrics("device3", Frequency(380000), Grouped(false), FrequencyOverride(false))
49 assert.NotNil(t, pm)
50 assert.Equal(t, "device3", pm.deviceId)
51 assert.EqualValues(t, 380000, pm.frequency)
52 assert.Equal(t, false, pm.frequencyOverride)
53}