fix: check all handleMessage return values in tests (errcheck)
This commit is contained in:
parent
8cb4001d30
commit
9230c2c4d4
1 changed files with 14 additions and 14 deletions
|
|
@ -163,7 +163,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"binary": "not-base64!!!"})
|
payload, _ := json.Marshal(map[string]string{"binary": "not-base64!!!"})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid protobuf", func(t *testing.T) {
|
t.Run("invalid protobuf", func(t *testing.T) {
|
||||||
|
|
@ -173,7 +173,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"binary": base64.StdEncoding.EncodeToString([]byte{0xFF, 0xFF, 0xFF})})
|
payload, _ := json.Marshal(map[string]string{"binary": base64.StdEncoding.EncodeToString([]byte{0xFF, 0xFF, 0xFF})})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("restart", func(t *testing.T) {
|
t.Run("restart", func(t *testing.T) {
|
||||||
|
|
@ -239,7 +239,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"url": "https://example.com/agent", "checksum": "abc123"})
|
payload, _ := json.Marshal(map[string]string{"url": "https://example.com/agent", "checksum": "abc123"})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
|
|
||||||
if calledURL != "https://example.com/agent" {
|
if calledURL != "https://example.com/agent" {
|
||||||
t.Errorf("expected update URL %q, got %q", "https://example.com/agent", calledURL)
|
t.Errorf("expected update URL %q, got %q", "https://example.com/agent", calledURL)
|
||||||
|
|
@ -263,7 +263,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
// Missing URL field
|
// Missing URL field
|
||||||
payload, _ := json.Marshal(map[string]string{"checksum": "abc123"})
|
payload, _ := json.Marshal(map[string]string{"checksum": "abc123"})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
|
|
||||||
if called {
|
if called {
|
||||||
t.Error("selfUpdate should not be called with empty URL")
|
t.Error("selfUpdate should not be called with empty URL")
|
||||||
|
|
@ -284,7 +284,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"url": "https://example.com/agent", "checksum": "abc123"})
|
payload, _ := json.Marshal(map[string]string{"url": "https://example.com/agent", "checksum": "abc123"})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
// Should log error but not panic
|
// Should log error but not panic
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -304,7 +304,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"url": "https://example.com/agent"})
|
payload, _ := json.Marshal(map[string]string{"url": "https://example.com/agent"})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "update", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
|
|
||||||
if called {
|
if called {
|
||||||
t.Error("selfUpdate should not be called with empty checksum")
|
t.Error("selfUpdate should not be called with empty checksum")
|
||||||
|
|
@ -317,7 +317,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
credCh := make(chan *pb.CredentialTestResult, 1)
|
credCh := make(chan *pb.CredentialTestResult, 1)
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
handleMessage(context.Background(), channelMsg{Event: "some_unknown_event", Payload: json.RawMessage(`{}`)}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "some_unknown_event", Payload: json.RawMessage(`{}`)}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
// Should just log and not panic
|
// Should just log and not panic
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -334,7 +334,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
credCh := make(chan *pb.CredentialTestResult, 1)
|
credCh := make(chan *pb.CredentialTestResult, 1)
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
select {
|
select {
|
||||||
case <-checkCh:
|
case <-checkCh:
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
|
@ -348,7 +348,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
credCh := make(chan *pb.CredentialTestResult, 1)
|
credCh := make(chan *pb.CredentialTestResult, 1)
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: json.RawMessage(`not json`)}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: json.RawMessage(`not json`)}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
// Should log error but not panic
|
// Should log error but not panic
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -359,7 +359,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"binary": "not-base64!!!"})
|
payload, _ := json.Marshal(map[string]string{"binary": "not-base64!!!"})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
// Should log error but not panic
|
// Should log error but not panic
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -370,7 +370,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
monCh := make(chan *pb.MonitoringCheck, 1)
|
monCh := make(chan *pb.MonitoringCheck, 1)
|
||||||
checkCh := make(chan *pb.CheckResult, 1)
|
checkCh := make(chan *pb.CheckResult, 1)
|
||||||
payload, _ := json.Marshal(map[string]string{"binary": base64.StdEncoding.EncodeToString([]byte{0xFF, 0xFF, 0xFF})})
|
payload, _ := json.Marshal(map[string]string{"binary": base64.StdEncoding.EncodeToString([]byte{0xFF, 0xFF, 0xFF})})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "check_jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
// Should log error but not panic
|
// Should log error but not panic
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -397,7 +397,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
JobType: pb.JobType_DISCOVER,
|
JobType: pb.JobType_DISCOVER,
|
||||||
SnmpDevice: &pb.SnmpDevice{Ip: "10.0.0.1"},
|
SnmpDevice: &pb.SnmpDevice{Ip: "10.0.0.1"},
|
||||||
})
|
})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "discovery_job", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "discovery_job", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
select {
|
select {
|
||||||
case <-snmpCh:
|
case <-snmpCh:
|
||||||
case <-time.After(2 * time.Second):
|
case <-time.After(2 * time.Second):
|
||||||
|
|
@ -425,7 +425,7 @@ func TestHandleMessage(t *testing.T) {
|
||||||
JobType: pb.JobType_MIKROTIK,
|
JobType: pb.JobType_MIKROTIK,
|
||||||
MikrotikDevice: &pb.MikrotikDevice{Ip: "10.0.0.1", SshPort: 22, Username: "admin", Password: "pass"},
|
MikrotikDevice: &pb.MikrotikDevice{Ip: "10.0.0.1", SshPort: 22, Username: "admin", Password: "pass"},
|
||||||
})
|
})
|
||||||
handleMessage(context.Background(), channelMsg{Event: "backup_job", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "backup_job", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
select {
|
select {
|
||||||
case result := <-mtCh:
|
case result := <-mtCh:
|
||||||
if result.Error != "" {
|
if result.Error != "" {
|
||||||
|
|
@ -449,7 +449,7 @@ func TestHandleMessageRejectsOversizedPayload(t *testing.T) {
|
||||||
encoded := base64.StdEncoding.EncodeToString(oversized)
|
encoded := base64.StdEncoding.EncodeToString(oversized)
|
||||||
payload, _ := json.Marshal(map[string]string{"binary": encoded})
|
payload, _ := json.Marshal(map[string]string{"binary": encoded})
|
||||||
|
|
||||||
handleMessage(context.Background(), channelMsg{Event: "jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
_, _ = handleMessage(context.Background(), channelMsg{Event: "jobs", Payload: payload}, testPools(t), snmpCh, mtCh, credCh, monCh, checkCh, make(chan *pb.LldpTopologyResult, 1))
|
||||||
|
|
||||||
// Verify no jobs were dispatched
|
// Verify no jobs were dispatched
|
||||||
select {
|
select {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue