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-lib", "my-app")
36 assert.Nil(t, err, "init failed")
37 assert.Equal(t, false, a == nil)
40 time.Sleep(time.Duration(5 * time.Second))
43 func TestAlarmRaiseSuccess(t *testing.T) {
44 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
46 err := alarmer.Raise(a)
47 assert.Nil(t, err, "raise failed")
50 func TestAlarmClearSuccess(t *testing.T) {
51 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
53 err := alarmer.Clear(a)
54 assert.Nil(t, err, "clear failed")
57 func TestAlarmReraiseSuccess(t *testing.T) {
58 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
60 err := alarmer.Reraise(a)
61 assert.Nil(t, err, "re-raise failed")
64 func TestAlarmClearAllSuccess(t *testing.T) {
65 err := alarmer.ClearAll()
66 assert.Nil(t, err, "clearAll failed")
69 func TestAlarmSendSuccess(t *testing.T) {
70 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
72 consumer := func(m alarm.AlarmMessage) {
73 assert.Equal(t, m.ManagedObjectId, a.ManagedObjectId)
74 assert.Equal(t, m.ApplicationId, a.ApplicationId)
75 assert.Equal(t, m.SpecificProblem, a.SpecificProblem)
76 assert.Equal(t, m.PerceivedSeverity, a.PerceivedSeverity)
77 assert.Equal(t, m.AdditionalInfo, a.AdditionalInfo)
78 assert.Equal(t, m.IdentifyingInfo, a.IdentifyingInfo)
79 assert.Equal(t, m.AlarmAction, alarm.AlarmActionRaise)
82 go alarmer.ReceiveMessage(consumer)
83 time.Sleep(time.Duration(1 * time.Second))
85 err := alarmer.Raise(a)
86 assert.Nil(t, err, "send failed")
89 func TestSetManagedObjectIdSuccess(t *testing.T) {
90 alarmer.SetManagedObjectId("new-pod")
92 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
93 assert.Equal(t, a.ManagedObjectId, "new-pod")
96 func TestSetApplicationIdSuccess(t *testing.T) {
97 alarmer.SetApplicationId("new-app")
99 a := alarmer.NewAlarm(1234, alarm.SeverityMajor, "Some App data", "eth 0 1")
100 assert.Equal(t, a.ApplicationId, "new-app")