Fix several bugs in minecraft input (#2970)
This commit is contained in:
committed by
Daniel Nelson
parent
f2bb4acd4a
commit
cc3d420551
36
plugins/inputs/minecraft/rcon_disconnect_error_test.go
Normal file
36
plugins/inputs/minecraft/rcon_disconnect_error_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package minecraft
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type MockRCONProducer struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (m *MockRCONProducer) newClient() (RCONClient, error) {
|
||||
return nil, m.Err
|
||||
}
|
||||
|
||||
func TestRCONErrorHandling(t *testing.T) {
|
||||
m := &MockRCONProducer{
|
||||
Err: errors.New("Error: failed connection"),
|
||||
}
|
||||
c := &RCON{
|
||||
Server: "craftstuff.com",
|
||||
Port: "2222",
|
||||
Password: "pass",
|
||||
//Force fetching of new client
|
||||
client: nil,
|
||||
}
|
||||
|
||||
_, err := c.Gather(m)
|
||||
if err == nil {
|
||||
t.Errorf("Error nil, unexpected result")
|
||||
}
|
||||
|
||||
if c.client != nil {
|
||||
t.Fatal("c.client should be nil, unexpected result")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user