mirror of
https://github.com/ivuorinen/gibidify.git
synced 2026-02-03 20:44:59 +00:00
Add overflow checks before converting uint64 memory values to int64 to prevent potential integer overflow issues identified by gosec (G115). - Add math.MaxInt64 checks in fileproc/backpressure.go - Add math.MaxInt64 checks in fileproc/resource_monitor_validation.go - Add math.MaxInt64 checks in fileproc/resource_monitor_metrics.go - Add math.MaxInt64 check in benchmark/benchmark.go with nosec annotation Co-authored-by: ivuorinen <11024+ivuorinen@users.noreply.github.com>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package fileproc
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/ivuorinen/gibidify/testutil"
|
|
)
|
|
|
|
func TestResourceMonitor_Metrics(t *testing.T) {
|
|
testutil.ResetViperConfig(t, "")
|
|
|
|
viper.Set("resourceLimits.enabled", true)
|
|
viper.Set("resourceLimits.enableResourceMonitoring", true)
|
|
|
|
rm := NewResourceMonitor()
|
|
defer rm.Close()
|
|
|
|
// Process some files to generate metrics
|
|
rm.RecordFileProcessed(1000)
|
|
rm.RecordFileProcessed(2000)
|
|
rm.RecordFileProcessed(500)
|
|
|
|
metrics := rm.GetMetrics()
|
|
|
|
// Verify metrics
|
|
if metrics.FilesProcessed != 3 {
|
|
t.Errorf("Expected 3 files processed, got %d", metrics.FilesProcessed)
|
|
}
|
|
|
|
if metrics.TotalSizeProcessed != 3500 {
|
|
t.Errorf("Expected total size 3500, got %d", metrics.TotalSizeProcessed)
|
|
}
|
|
|
|
expectedAvgSize := float64(3500) / float64(3)
|
|
if metrics.AverageFileSize != expectedAvgSize {
|
|
t.Errorf("Expected average file size %.2f, got %.2f", expectedAvgSize, metrics.AverageFileSize)
|
|
}
|
|
|
|
if metrics.ProcessingRate <= 0 {
|
|
t.Error("Expected positive processing rate")
|
|
}
|
|
|
|
if !metrics.LastUpdated.After(time.Now().Add(-time.Second)) {
|
|
t.Error("Expected recent LastUpdated timestamp")
|
|
}
|
|
}
|