11package config_test
22
33import (
4+ "path"
5+ "testing"
6+
47 "github.com/analogj/scrutiny/collector/pkg/config"
58 "github.com/analogj/scrutiny/collector/pkg/models"
9+ "github.com/sirupsen/logrus"
610 "github.com/stretchr/testify/require"
7- "path"
8- "testing"
911)
1012
13+ func testLogger () * logrus.Entry {
14+ return logrus .WithFields (logrus.Fields {"type" : "test" })
15+ }
16+
1117func TestConfiguration_InvalidConfigPath (t * testing.T ) {
1218 t .Parallel ()
1319
1420 //setup
1521 testConfig , _ := config .Create ()
1622
1723 //test
18- err := testConfig .ReadConfig ("does_not_exist.yaml" )
24+ err := testConfig .ReadConfig ("does_not_exist.yaml" , testLogger () )
1925
2026 //assert
2127 require .Error (t , err , "should return an error" )
@@ -28,7 +34,7 @@ func TestConfiguration_GetScanOverrides_Simple(t *testing.T) {
2834 testConfig , _ := config .Create ()
2935
3036 //test
31- err := testConfig .ReadConfig (path .Join ("testdata" , "simple_device.yaml" ))
37+ err := testConfig .ReadConfig (path .Join ("testdata" , "simple_device.yaml" ), testLogger () )
3238 require .NoError (t , err , "should correctly load simple device config" )
3339 scanOverrides := testConfig .GetDeviceOverrides ()
3440
@@ -44,7 +50,7 @@ func TestConfiguration_GetScanOverrides_DeviceTypeComma(t *testing.T) {
4450 testConfig , _ := config .Create ()
4551
4652 //test
47- err := testConfig .ReadConfig (path .Join ("testdata" , "device_type_comma.yaml" ))
53+ err := testConfig .ReadConfig (path .Join ("testdata" , "device_type_comma.yaml" ), testLogger () )
4854 require .NoError (t , err , "should correctly load simple device config" )
4955 scanOverrides := testConfig .GetDeviceOverrides ()
5056
@@ -62,7 +68,7 @@ func TestConfiguration_GetScanOverrides_Ignore(t *testing.T) {
6268 testConfig , _ := config .Create ()
6369
6470 //test
65- err := testConfig .ReadConfig (path .Join ("testdata" , "ignore_device.yaml" ))
71+ err := testConfig .ReadConfig (path .Join ("testdata" , "ignore_device.yaml" ), testLogger () )
6672 require .NoError (t , err , "should correctly load ignore device config" )
6773 scanOverrides := testConfig .GetDeviceOverrides ()
6874
@@ -77,7 +83,7 @@ func TestConfiguration_GetScanOverrides_Raid(t *testing.T) {
7783 testConfig , _ := config .Create ()
7884
7985 //test
80- err := testConfig .ReadConfig (path .Join ("testdata" , "raid_device.yaml" ))
86+ err := testConfig .ReadConfig (path .Join ("testdata" , "raid_device.yaml" ), testLogger () )
8187 require .NoError (t , err , "should correctly load ignore device config" )
8288 scanOverrides := testConfig .GetDeviceOverrides ()
8389
@@ -102,7 +108,7 @@ func TestConfiguration_InvalidCommands_MissingJson(t *testing.T) {
102108 testConfig , _ := config .Create ()
103109
104110 //test
105- err := testConfig .ReadConfig (path .Join ("testdata" , "invalid_commands_missing_json.yaml" ))
111+ err := testConfig .ReadConfig (path .Join ("testdata" , "invalid_commands_missing_json.yaml" ), testLogger () )
106112 require .EqualError (t , err , `ConfigValidationError: "configuration key 'commands.metrics_scan_args' is missing '--json' flag"` , "should throw an error because json flag is missing" )
107113}
108114
@@ -113,7 +119,7 @@ func TestConfiguration_InvalidCommands_IncludesDevice(t *testing.T) {
113119 testConfig , _ := config .Create ()
114120
115121 //test
116- err := testConfig .ReadConfig (path .Join ("testdata" , "invalid_commands_includes_device.yaml" ))
122+ err := testConfig .ReadConfig (path .Join ("testdata" , "invalid_commands_includes_device.yaml" ), testLogger () )
117123 require .EqualError (t , err , `ConfigValidationError: "configuration key 'commands.metrics_info_args' must not contain '--device' or '-d' flag, configuration key 'commands.metrics_smart_args' must not contain '--device' or '-d' flag"` , "should throw an error because device flags detected" )
118124}
119125
@@ -124,7 +130,7 @@ func TestConfiguration_OverrideCommands(t *testing.T) {
124130 testConfig , _ := config .Create ()
125131
126132 //test
127- err := testConfig .ReadConfig (path .Join ("testdata" , "override_commands.yaml" ))
133+ err := testConfig .ReadConfig (path .Join ("testdata" , "override_commands.yaml" ), testLogger () )
128134 require .NoError (t , err , "should not throw an error" )
129135 require .Equal (t , "--xall --json -T permissive" , testConfig .GetString ("commands.metrics_smart_args" ))
130136}
@@ -136,7 +142,7 @@ func TestConfiguration_OverrideDeviceCommands_MetricsInfoArgs(t *testing.T) {
136142 testConfig , _ := config .Create ()
137143
138144 //test
139- err := testConfig .ReadConfig (path .Join ("testdata" , "override_device_commands.yaml" ))
145+ err := testConfig .ReadConfig (path .Join ("testdata" , "override_device_commands.yaml" ), testLogger () )
140146 require .NoError (t , err , "should correctly override device command" )
141147
142148 //assert
@@ -152,7 +158,7 @@ func TestConfiguration_DeviceAllowList(t *testing.T) {
152158 testConfig , err := config .Create ()
153159 require .NoError (t , err )
154160
155- require .NoError (t , testConfig .ReadConfig (path .Join ("testdata" , "allow_listed_devices_present.yaml" )))
161+ require .NoError (t , testConfig .ReadConfig (path .Join ("testdata" , "allow_listed_devices_present.yaml" ), testLogger () ))
156162
157163 require .True (t , testConfig .IsAllowlistedDevice ("/dev/sda" ), "/dev/sda should be allow listed" )
158164 require .False (t , testConfig .IsAllowlistedDevice ("/dev/sdc" ), "/dev/sda should not be allow listed" )
@@ -163,7 +169,7 @@ func TestConfiguration_DeviceAllowList(t *testing.T) {
163169 require .NoError (t , err )
164170
165171 // Really just any other config where the key is full missing
166- require .NoError (t , testConfig .ReadConfig (path .Join ("testdata" , "override_device_commands.yaml" )))
172+ require .NoError (t , testConfig .ReadConfig (path .Join ("testdata" , "override_device_commands.yaml" ), testLogger () ))
167173
168174 // Anything should be allow listed if the key isnt there
169175 require .True (t , testConfig .IsAllowlistedDevice ("/dev/sda" ), "/dev/sda should be allow listed" )
0 commit comments