X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=manager%2Fcmd%2Fmanager_test.go;h=5f1cecc46c9a949c0f7c804c3ee7ae02e9f89148;hb=bbfd41502beb6f03a6b3ff2bf3d6507b4d9291e2;hp=00df224a33d24cd41140110d83e934297e9a7be4;hpb=3649fae7a06ad3ad099d0aa4e68f7ca3a2ae5a87;p=ric-plt%2Falarm-go.git diff --git a/manager/cmd/manager_test.go b/manager/cmd/manager_test.go index 00df224..5f1cecc 100755 --- a/manager/cmd/manager_test.go +++ b/manager/cmd/manager_test.go @@ -221,6 +221,34 @@ func TestNewAlarmStoredAndPostedSucess(t *testing.T) { assert.Nil(t, alarmer.Raise(a), "raise failed") VerifyAlarm(t, a, 1) + + var activeAlarms []AlarmNotification + activeAlarms = make([]AlarmNotification, 1) + req, _ := http.NewRequest("GET", "/ric/v1/alarms/active", nil) + req = mux.SetURLVars(req, nil) + handleFunc := http.HandlerFunc(alarmManager.GetActiveAlarms) + response := executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + + // Decode the json output from handler + json.NewDecoder(response.Body).Decode(activeAlarms) + if len(activeAlarms) != 1 { + t.Errorf("Incorrect alarm alarm count") + } + + var alarmHistory []AlarmNotification + alarmHistory = make([]AlarmNotification, 1) + req, _ = http.NewRequest("GET", "/ric/v1/alarms/history", nil) + req = mux.SetURLVars(req, nil) + handleFunc = http.HandlerFunc(alarmManager.GetAlarmHistory) + response = executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + + // Decode the json output from handler + json.NewDecoder(response.Body).Decode(alarmHistory) + if len(alarmHistory) != 1 { + t.Errorf("Incorrect alarm history count") + } } func TestAlarmClearedSucess(t *testing.T) { @@ -353,7 +381,7 @@ func TestGetPrometheusAlerts(t *testing.T) { commandReady := make(chan bool, 1) command := "cli/alarm-cli" - args := []string{"gapam", "--active", "true", "--inhibited", "true", "--silenced", "--unprocessed", "true", "true", "--host", "localhost", "--port", "9093", "flushall"} + args := []string{"alerts", "--active", "true", "--inhibited", "true", "--silenced", "--unprocessed", "true", "true", "--host", "localhost", "--port", "9093", "flushall"} ExecCLICommand(commandReady, command, args...) <-commandReady @@ -523,6 +551,60 @@ func TestClearExpiredAlarms(t *testing.T) { assert.Equal(t, len(alarmManager.activeAlarms), 0) } +func TestSetAlarmConfig(t *testing.T) { + xapp.Logger.Info("TestSetAlarmConfig") + + var setAlarmConfig alarm.AlarmConfigParams + setAlarmConfig.MaxActiveAlarms = 500 + setAlarmConfig.MaxAlarmHistory = 2000 + + pbodyEn, _ := json.Marshal(setAlarmConfig) + req, _ := http.NewRequest("POST", "/ric/v1/alarms/config", bytes.NewBuffer(pbodyEn)) + handleFunc := http.HandlerFunc(alarmManager.SetAlarmConfig) + response := executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + + var getAlarmConfig alarm.AlarmConfigParams + req, _ = http.NewRequest("GET", "/ric/v1/alarms/config", nil) + req = mux.SetURLVars(req, nil) + handleFunc = http.HandlerFunc(alarmManager.GetAlarmConfig) + response = executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + + // Decode the json output from handler + json.NewDecoder(response.Body).Decode(&getAlarmConfig) + if getAlarmConfig.MaxActiveAlarms != 500 || getAlarmConfig.MaxAlarmHistory != 2000 { + t.Errorf("Incorrect alarm thresholds") + } + + // Revert ot default + setAlarmConfig.MaxActiveAlarms = 5000 + setAlarmConfig.MaxAlarmHistory = 20000 + + pbodyEn, _ = json.Marshal(setAlarmConfig) + req, _ = http.NewRequest("POST", "/ric/v1/alarms/config", bytes.NewBuffer(pbodyEn)) + handleFunc = http.HandlerFunc(alarmManager.SetAlarmConfig) + response = executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + + req, _ = http.NewRequest("GET", "/ric/v1/alarms/config", nil) + req = mux.SetURLVars(req, nil) + handleFunc = http.HandlerFunc(alarmManager.GetAlarmConfig) + response = executeRequest(req, handleFunc) + checkResponseCode(t, http.StatusOK, response.Code) + + // Decode the json output from handler + json.NewDecoder(response.Body).Decode(&getAlarmConfig) + if getAlarmConfig.MaxActiveAlarms != 5000 || getAlarmConfig.MaxAlarmHistory != 20000 { + t.Errorf("Incorrect alarm thresholds") + } +} + +func TestConfigChangeCB(t *testing.T) { + xapp.Logger.Info("TestConfigChangeCB") + alarmManager.ConfigChangeCB("AlarmManager") +} + func VerifyAlarm(t *testing.T, a alarm.Alarm, expectedCount int) string { receivedAlert := waitForEvent()