|
|
|
@ -2,12 +2,17 @@ package notify
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/analogj/scrutiny/webapp/backend/pkg"
|
|
|
|
|
mock_database "github.com/analogj/scrutiny/webapp/backend/pkg/database/mock"
|
|
|
|
|
"github.com/analogj/scrutiny/webapp/backend/pkg/models"
|
|
|
|
|
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MustSkipPassingDevices(t *testing.T) {
|
|
|
|
@ -20,22 +25,27 @@ func TestShouldNotify_MustSkipPassingDevices(t *testing.T) {
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdBoth
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesAll
|
|
|
|
|
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
//assert
|
|
|
|
|
require.False(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.False(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusThresholdBoth_FailingSmartDevice(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
//setup
|
|
|
|
|
//setupD
|
|
|
|
|
device := models.Device{
|
|
|
|
|
DeviceStatus: pkg.DeviceStatusFailedSmart,
|
|
|
|
|
}
|
|
|
|
|
smartAttrs := measurements.Smart{}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdBoth
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesAll
|
|
|
|
|
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
//assert
|
|
|
|
|
require.True(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.True(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusThresholdSmart_FailingSmartDevice(t *testing.T) {
|
|
|
|
@ -47,9 +57,11 @@ func TestShouldNotify_MetricsStatusThresholdSmart_FailingSmartDevice(t *testing.
|
|
|
|
|
smartAttrs := measurements.Smart{}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdSmart
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesAll
|
|
|
|
|
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
//assert
|
|
|
|
|
require.True(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.True(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusThresholdScrutiny_FailingSmartDevice(t *testing.T) {
|
|
|
|
@ -61,9 +73,11 @@ func TestShouldNotify_MetricsStatusThresholdScrutiny_FailingSmartDevice(t *testi
|
|
|
|
|
smartAttrs := measurements.Smart{}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdScrutiny
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesAll
|
|
|
|
|
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
//assert
|
|
|
|
|
require.False(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.False(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithCriticalAttrs(t *testing.T) {
|
|
|
|
@ -79,9 +93,12 @@ func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithCriticalAttrs(t
|
|
|
|
|
}}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdBoth
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesCritical
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
require.True(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.True(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithMultipleCriticalAttrs(t *testing.T) {
|
|
|
|
@ -100,9 +117,12 @@ func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithMultipleCritical
|
|
|
|
|
}}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdBoth
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesCritical
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
require.True(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.True(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithNoCriticalAttrs(t *testing.T) {
|
|
|
|
@ -118,9 +138,12 @@ func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithNoCriticalAttrs(
|
|
|
|
|
}}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdBoth
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesCritical
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
require.False(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.False(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithNoFailingCriticalAttrs(t *testing.T) {
|
|
|
|
@ -136,9 +159,12 @@ func TestShouldNotify_MetricsStatusFilterAttributesCritical_WithNoFailingCritica
|
|
|
|
|
}}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdBoth
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesCritical
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
require.False(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.False(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShouldNotify_MetricsStatusFilterAttributesCritical_MetricsStatusThresholdSmart_WithCriticalAttrsFailingScrutiny(t *testing.T) {
|
|
|
|
@ -157,9 +183,12 @@ func TestShouldNotify_MetricsStatusFilterAttributesCritical_MetricsStatusThresho
|
|
|
|
|
}}
|
|
|
|
|
statusThreshold := pkg.MetricsStatusThresholdSmart
|
|
|
|
|
notifyFilterAttributes := pkg.MetricsStatusFilterAttributesCritical
|
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
fakeDatabase := mock_database.NewMockDeviceRepo(mockCtrl)
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
require.False(t, ShouldNotify(device, smartAttrs, statusThreshold, notifyFilterAttributes))
|
|
|
|
|
require.False(t, ShouldNotify(logrus.StandardLogger(), device, smartAttrs, statusThreshold, notifyFilterAttributes, true, &gin.Context{}, fakeDatabase))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNewPayload(t *testing.T) {
|
|
|
|
|