blob: a022c7c259e5f7b76ad49c89c8e6e64baa234818 [file] [log] [blame]
Matteo Scandolo10f965c2019-09-24 10:40:46 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
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 "gotest.tools/assert"
21 "testing"
22)
23
24func createMockOlt(numPon int, numOnu int) OltDevice {
25 olt := OltDevice{
26 ID: 0,
27 }
28
29 for i := 0; i < numPon; i++ {
30 pon := PonPort{
31 ID: uint32(i),
32 }
33
34 for j := 0; j < numOnu; j++ {
35 onu := Onu{
36 ID: uint32(i + j),
37 PonPort: pon,
38 PonPortID: uint32(i),
39 }
40 onu.SerialNumber = onu.NewSN(olt.ID, pon.ID, onu.ID)
41 pon.Onus = append(pon.Onus, onu)
42 }
43 olt.Pons = append(olt.Pons, pon)
44 }
45 return olt
46}
47
48func Test_Olt_FindOnu_Success(t *testing.T) {
49
50 numPon := 4
51 numOnu := 4
52
53 olt := createMockOlt(numPon, numOnu)
54
55 onu, err := olt.FindOnu("BBSM00000303")
56
57 assert.Equal(t, err, nil)
58 assert.Equal(t, onu.Sn(), "BBSM00000303")
59 assert.Equal(t, onu.ID, uint32(3))
60 assert.Equal(t, onu.PonPortID, uint32(3))
61}
62
63func Test_Olt_FindOnu_Error(t *testing.T) {
64
65 numPon := 1
66 numOnu := 4
67
68 olt := createMockOlt(numPon, numOnu)
69
70 _, err := olt.FindOnu("BBSM00000303")
71
72 assert.Equal(t, err.Error(), "cannot-find-onu-BBSM00000303")
73}