@@ -78,8 +78,8 @@ func TestSNMPHost(t *testing.T) {
7878
7979 t .Run ("Successfully walks a host" , func (t * testing.T ) {
8080 // Setup
81- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
82- fakeWalker , _ := snmp .NewFakeSNMPWalker ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil )
81+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , logger * slog. Logger ) (snmp.Walker , error ) {
82+ fakeWalker , _ := snmp .NewFakeSNMPWalker ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger )
8383 return fakeWalker , nil
8484 }
8585 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -110,7 +110,7 @@ func TestSNMPHost(t *testing.T) {
110110 interfaceSpeedOID + ".1" : {Value : 1000000 , Type : gosnmp .Integer , IdentifierSize : 1 },
111111 }, nil )
112112
113- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
113+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , _ * slog. Logger ) (snmp.Walker , error ) {
114114 return mockWalker , nil
115115 }
116116 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -136,7 +136,7 @@ func TestSNMPHost(t *testing.T) {
136136 ipAddressObjectID : {Value : "192.168.1.1" , Type : gosnmp .IPAddress , IdentifierSize : 4 },
137137 }, nil )
138138
139- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
139+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , _ * slog. Logger ) (snmp.Walker , error ) {
140140 return mockWalker , nil
141141 }
142142 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -158,7 +158,7 @@ func TestSNMPHost(t *testing.T) {
158158 mockWalker := & MockSNMP {}
159159 mockWalker .On ("Connect" ).Return (assert .AnError )
160160 mockWalker .On ("Close" ).Return (nil )
161- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
161+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , _ * slog. Logger ) (snmp.Walker , error ) {
162162 return mockWalker , nil
163163 }
164164 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -178,7 +178,7 @@ func TestSNMPHost(t *testing.T) {
178178 mockWalker .On ("Connect" ).Return (nil )
179179 mockWalker .On ("Close" ).Return (nil )
180180 mockWalker .On ("Walk" , mock .Anything , mock .Anything ).Return (make (map [string ]snmp.PDU ), assert .AnError )
181- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
181+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , _ * slog. Logger ) (snmp.Walker , error ) {
182182 return mockWalker , nil
183183 }
184184 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -207,7 +207,7 @@ func TestSNMPHost(t *testing.T) {
207207 interfaceSpeedOID + ".1" : {Value : "invalid" , Type : gosnmp .Asn1BER (255 ), IdentifierSize : 1 }, // Invalid type
208208 }, nil )
209209
210- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
210+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , _ * slog. Logger ) (snmp.Walker , error ) {
211211 return mockWalker , nil
212212 }
213213 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -232,7 +232,7 @@ func TestSNMPHost(t *testing.T) {
232232 mockWalker .On ("Connect" ).Return (nil )
233233 mockWalker .On ("Close" ).Return (nil )
234234 mockWalker .On ("Walk" , mock .Anything , mock .Anything ).Return (nil , assert .AnError )
235- snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication ) (snmp.Walker , error ) {
235+ snmpClientFactory := func (_ string , _ uint16 , _ int , _ time.Duration , _ * config.Authentication , _ * slog. Logger ) (snmp.Walker , error ) {
236236 return nil , fmt .Errorf ("error creating client" )
237237 }
238238 host := snmp .NewHost ("192.168.1.1" , 161 , 3 , 1 * time .Second , nil , logger , snmpClientFactory )
@@ -434,7 +434,8 @@ func TestNewClient(t *testing.T) {
434434
435435 for _ , tc := range testCases {
436436 t .Run (tc .name , func (t * testing.T ) {
437- client , err := snmp .NewClient ("192.168.1.1" , 161 , 3 , 1 * time .Second , tc .auth )
437+ logger := slog .New (slog .NewJSONHandler (os .Stdout , & slog.HandlerOptions {Level : slog .LevelDebug }))
438+ client , err := snmp .NewClient ("192.168.1.1" , 161 , 3 , 1 * time .Second , tc .auth , logger )
438439
439440 if tc .expectError {
440441 assert .Error (t , err )
0 commit comments