Add tag/integer pair for result to net_response (#3455)
This commit is contained in:
committed by
Daniel Nelson
parent
1d9488bd42
commit
54a0532604
@@ -13,6 +13,21 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
c := &NetResponse{}
|
||||
output := c.SampleConfig()
|
||||
if output != sampleConfig {
|
||||
t.Error("Sample config doesn't match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
c := &NetResponse{}
|
||||
output := c.Description()
|
||||
if output != description {
|
||||
t.Error("Description output is not correct")
|
||||
}
|
||||
}
|
||||
func TestBadProtocol(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
// Init plugin
|
||||
@@ -26,6 +41,50 @@ func TestBadProtocol(t *testing.T) {
|
||||
assert.Equal(t, "Bad protocol", err1.Error())
|
||||
}
|
||||
|
||||
func TestNoPort(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
c := NetResponse{
|
||||
Protocol: "tcp",
|
||||
Address: ":",
|
||||
}
|
||||
err1 := c.Gather(&acc)
|
||||
require.Error(t, err1)
|
||||
assert.Equal(t, "Bad port", err1.Error())
|
||||
}
|
||||
|
||||
func TestAddressOnly(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
c := NetResponse{
|
||||
Protocol: "tcp",
|
||||
Address: "127.0.0.1",
|
||||
}
|
||||
err1 := c.Gather(&acc)
|
||||
require.Error(t, err1)
|
||||
assert.Equal(t, "address 127.0.0.1: missing port in address", err1.Error())
|
||||
}
|
||||
|
||||
func TestSendExpectStrings(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
tc := NetResponse{
|
||||
Protocol: "udp",
|
||||
Address: "127.0.0.1:7",
|
||||
Send: "",
|
||||
Expect: "toast",
|
||||
}
|
||||
uc := NetResponse{
|
||||
Protocol: "udp",
|
||||
Address: "127.0.0.1:7",
|
||||
Send: "toast",
|
||||
Expect: "",
|
||||
}
|
||||
err1 := tc.Gather(&acc)
|
||||
require.Error(t, err1)
|
||||
assert.Equal(t, "Send string cannot be empty", err1.Error())
|
||||
err2 := uc.Gather(&acc)
|
||||
require.Error(t, err2)
|
||||
assert.Equal(t, "Expected string cannot be empty", err2.Error())
|
||||
}
|
||||
|
||||
func TestTCPError(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
// Init plugin
|
||||
@@ -39,12 +98,14 @@ func TestTCPError(t *testing.T) {
|
||||
acc.AssertContainsTaggedFields(t,
|
||||
"net_response",
|
||||
map[string]interface{}{
|
||||
"result_code": 1,
|
||||
"result_type": "connection_failed",
|
||||
},
|
||||
map[string]string{
|
||||
"server": "",
|
||||
"port": "9999",
|
||||
"protocol": "tcp",
|
||||
"server": "",
|
||||
"port": "9999",
|
||||
"protocol": "tcp",
|
||||
"result_text": "connection_failed",
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -77,13 +138,16 @@ func TestTCPOK1(t *testing.T) {
|
||||
acc.AssertContainsTaggedFields(t,
|
||||
"net_response",
|
||||
map[string]interface{}{
|
||||
"result_code": 0,
|
||||
"result_type": "success",
|
||||
"string_found": true,
|
||||
"response_time": 1.0,
|
||||
},
|
||||
map[string]string{"server": "127.0.0.1",
|
||||
"port": "2004",
|
||||
"protocol": "tcp",
|
||||
map[string]string{
|
||||
"result_text": "success",
|
||||
"server": "127.0.0.1",
|
||||
"port": "2004",
|
||||
"protocol": "tcp",
|
||||
},
|
||||
)
|
||||
// Waiting TCPserver
|
||||
@@ -118,20 +182,23 @@ func TestTCPOK2(t *testing.T) {
|
||||
acc.AssertContainsTaggedFields(t,
|
||||
"net_response",
|
||||
map[string]interface{}{
|
||||
"result_code": 1,
|
||||
"result_type": "string_mismatch",
|
||||
"string_found": false,
|
||||
"response_time": 1.0,
|
||||
},
|
||||
map[string]string{"server": "127.0.0.1",
|
||||
"port": "2004",
|
||||
"protocol": "tcp",
|
||||
map[string]string{
|
||||
"result_text": "string_mismatch",
|
||||
"server": "127.0.0.1",
|
||||
"port": "2004",
|
||||
"protocol": "tcp",
|
||||
},
|
||||
)
|
||||
// Waiting TCPserver
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestUDPrror(t *testing.T) {
|
||||
func TestUDPError(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
// Init plugin
|
||||
c := NetResponse{
|
||||
@@ -151,13 +218,15 @@ func TestUDPrror(t *testing.T) {
|
||||
acc.AssertContainsTaggedFields(t,
|
||||
"net_response",
|
||||
map[string]interface{}{
|
||||
"result_code": 1,
|
||||
"result_type": "read_failed",
|
||||
"response_time": 1.0,
|
||||
},
|
||||
map[string]string{
|
||||
"server": "",
|
||||
"port": "9999",
|
||||
"protocol": "udp",
|
||||
"result_text": "read_failed",
|
||||
"server": "",
|
||||
"port": "9999",
|
||||
"protocol": "udp",
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -190,13 +259,16 @@ func TestUDPOK1(t *testing.T) {
|
||||
acc.AssertContainsTaggedFields(t,
|
||||
"net_response",
|
||||
map[string]interface{}{
|
||||
"result_code": 0,
|
||||
"result_type": "success",
|
||||
"string_found": true,
|
||||
"response_time": 1.0,
|
||||
},
|
||||
map[string]string{"server": "127.0.0.1",
|
||||
"port": "2004",
|
||||
"protocol": "udp",
|
||||
map[string]string{
|
||||
"result_text": "success",
|
||||
"server": "127.0.0.1",
|
||||
"port": "2004",
|
||||
"protocol": "udp",
|
||||
},
|
||||
)
|
||||
// Waiting TCPserver
|
||||
|
||||
Reference in New Issue
Block a user