From f899e71aabc58052606f1b2a44d78423e37522d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Fri, 8 Dec 2023 18:15:21 +0100 Subject: [PATCH] fix(inputs.intel_powerstat): Unit tests should work on every CPU/platform (#14420) --- .../intel_powerstat/intel_powerstat_test.go | 22 +++++++++++++++- .../testdata/vendor_not_supported/cpuinfo | 25 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 plugins/inputs/intel_powerstat/testdata/vendor_not_supported/cpuinfo diff --git a/plugins/inputs/intel_powerstat/intel_powerstat_test.go b/plugins/inputs/intel_powerstat/intel_powerstat_test.go index 282e97250..91877b455 100644 --- a/plugins/inputs/intel_powerstat/intel_powerstat_test.go +++ b/plugins/inputs/intel_powerstat/intel_powerstat_test.go @@ -702,6 +702,8 @@ func TestInit(t *testing.T) { }) t.Run("FailedToParseConfigWithDuplicates", func(t *testing.T) { + t.Setenv("HOST_PROC", "./testdata") + logger := &testutil.CaptureLogger{} p := &PowerStat{ @@ -715,6 +717,8 @@ func TestInit(t *testing.T) { }) t.Run("FailedToParseConfigWithNegativeTimeout", func(t *testing.T) { + t.Setenv("HOST_PROC", "./testdata") + logger := &testutil.CaptureLogger{} p := &PowerStat{ @@ -729,7 +733,7 @@ func TestInit(t *testing.T) { } func TestStart(t *testing.T) { - t.Run("FailedToStart", func(t *testing.T) { + t.Run("FailedToStartCPUDoesNotExist", func(t *testing.T) { t.Setenv("HOST_PROC", "./testdata") acc := &testutil.Accumulator{} @@ -747,7 +751,23 @@ func TestStart(t *testing.T) { require.Empty(t, logger.Warnings()) }) + t.Run("FailedToStartNotSupportedCPUVendor", func(t *testing.T) { + t.Setenv("HOST_PROC", "./testdata/vendor_not_supported") + + acc := &testutil.Accumulator{} + logger := &testutil.CaptureLogger{} + + p := &PowerStat{ + Log: logger, + option: &optGenerator{}, + } + + require.ErrorContains(t, p.Start(acc), "host processor is not supported") + }) + t.Run("WithWarning", func(t *testing.T) { + t.Setenv("HOST_PROC", "./testdata") + acc := &testutil.Accumulator{} logger := &testutil.CaptureLogger{} diff --git a/plugins/inputs/intel_powerstat/testdata/vendor_not_supported/cpuinfo b/plugins/inputs/intel_powerstat/testdata/vendor_not_supported/cpuinfo new file mode 100644 index 000000000..7ec11e8a6 --- /dev/null +++ b/plugins/inputs/intel_powerstat/testdata/vendor_not_supported/cpuinfo @@ -0,0 +1,25 @@ +processor : 0 +vendor_id : AuthenticAMD +cpu family : 16 +model : 2 +model name : AMD Phenom(tm) 9550 Quad-Core Processor +stepping : 3 +cpu MHz : 1100.000 +cache size : 512 KB +physical id : 0 +siblings : 4 +core id : 0 +cpu cores : 4 +apicid : 0 +initial apicid : 0 +fpu : yes +fpu_exception : yes +cpuid level : 5 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs +bogomips : 4409.53 +TLB size : 1024 4K pages +clflush size : 64 +cache_alignment : 64 +address sizes : 48 bits physical, 48 bits virtual +power management: ts ttp tm stc 100mhzsteps hwpstate