blob: 037174e14cdd7a8fe5342260b7c18e8c6bc3daad [file] [log] [blame]
Elia Battistonac63b112022-01-12 18:40:49 +01001/*
Joey Armstrong2c039362024-02-04 18:51:52 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Elia Battistonac63b112022-01-12 18:40:49 +01003
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 devices
18
19import (
20 "testing"
21
22 bbsimTypes "github.com/opencord/bbsim/internal/bbsim/types"
23 "github.com/stretchr/testify/assert"
24)
25
26func createTestPots() (*PotsPort, error) {
27 onu := &Onu{
28 ID: 0,
29 SerialNumber: NewSN(1, 1, 1),
30 PonPortID: 0,
31 Channel: make(chan bbsimTypes.Message),
32 }
33
34 pots, err := NewPotsPort(1, onu)
35
36 return pots, err
37}
38
39func Test_Pots_Create(t *testing.T) {
40 pots, err := createTestPots()
41
42 assert.Nil(t, err)
43 assert.NotNil(t, pots)
44
45 // check initial operational state
46 assert.Equal(t, pots.OperState.Current(), PotsStateDown)
47}
48
49func Test_Pots_OperationalState(t *testing.T) {
50 pots, _ := createTestPots()
51
52 assert.Equal(t, pots.OperState.Current(), PotsStateDown)
53
54 go func() {
55 //When it will be enabled
56 msg, ok := <-pots.Onu.Channel
57 assert.True(t, ok)
58 assert.Equal(t, uint8(0), msg.Data.(bbsimTypes.UniStatusAlarmMessage).AdminState)
59
60 //When it will be disabled
61 msg, ok = <-pots.Onu.Channel
62 assert.True(t, ok)
63 assert.Equal(t, uint8(1), msg.Data.(bbsimTypes.UniStatusAlarmMessage).AdminState)
64 }()
65
66 err := pots.Enable()
67 assert.Nil(t, err)
68 assert.Equal(t, PotsStateUp, pots.OperState.Current())
69
70 err = pots.Disable()
71 assert.Nil(t, err)
72 assert.Equal(t, PotsStateDown, pots.OperState.Current())
73}