2 * Copyright (c) 2020 AT&T Intellectual Property.
3 * Copyright (c) 2020 Nokia.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 * platform project (RICP).
24 "github.com/stretchr/testify/assert"
28 "gerrit.o-ran-sc.org/r/ric-plt/alarm-go.git/alarm"
31 var alarmer *alarm.RICAlarm
34 func TestAlarmInitSuccess(t *testing.T) {
35 a, err := alarm.InitAlarm("my-pod", "my-app")
36 assert.Nil(t, err, "init failed")
37 assert.Equal(t, false, a == nil)
42 func TestAlarmRaiseSuccess(t *testing.T) {
43 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
45 err := alarmer.Raise(a)
46 assert.Nil(t, err, "raise failed")
49 func TestAlarmClearSuccess(t *testing.T) {
50 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
52 err := alarmer.Clear(a)
53 assert.Nil(t, err, "clear failed")
56 func TestAlarmReraiseSuccess(t *testing.T) {
57 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
59 err := alarmer.Reraise(a)
60 assert.Nil(t, err, "re-raise failed")
63 func TestAlarmClearAllSuccess(t *testing.T) {
64 err := alarmer.ClearAll()
65 assert.Nil(t, err, "clearAll failed")
68 func TestAlarmSendSuccess(t *testing.T) {
69 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
71 consumer := func(m alarm.AlarmMessage) {
72 assert.Equal(t, m.ManagedObjectId, a.ManagedObjectId)
73 assert.Equal(t, m.ApplicationId, a.ApplicationId)
74 assert.Equal(t, m.SpecificProblem, a.SpecificProblem)
75 assert.Equal(t, m.PerceivedSeverity, a.PerceivedSeverity)
76 assert.Equal(t, m.AdditionalInfo, a.AdditionalInfo)
77 assert.Equal(t, m.IdentifyingInfo, a.IdentifyingInfo)
78 assert.Equal(t, m.AlarmAction, alarm.AlarmActionRaise)
81 go alarmer.ReceiveMessage(consumer)
82 time.Sleep(time.Duration(1 * time.Second))
84 err := alarmer.Raise(a)
85 assert.Nil(t, err, "send failed")
88 func TestSetManagedObjectIdSuccess(t *testing.T) {
89 alarmer.SetManagedObjectId("new-pod")
91 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
92 assert.Equal(t, a.ManagedObjectId, "new-pod")
95 func TestSetApplicationIdSuccess(t *testing.T) {
96 alarmer.SetApplicationId("new-app")
98 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
99 assert.Equal(t, a.ApplicationId, "new-app")