1
0
mirror of https://github.com/nginxinc/nginx-prometheus-exporter.git synced 2025-04-18 12:45:02 +03:00
nginx_exporter/client/nginx_test.go
2022-04-01 09:44:14 +01:00

52 lines
1.1 KiB
Go

package client
import (
"bytes"
"testing"
)
const validStabStats = "Active connections: 1457 \nserver accepts handled requests\n 6717066 6717066 65844359 \nReading: 1 Writing: 8 Waiting: 1448 \n"
func TestParseStubStatsValidInput(t *testing.T) {
t.Parallel()
tests := []struct {
input []byte
expectedResult StubStats
expectedError bool
}{
{
input: []byte(validStabStats),
expectedResult: StubStats{
Connections: StubConnections{
Active: 1457,
Accepted: 6717066,
Handled: 6717066,
Reading: 1,
Writing: 8,
Waiting: 1448,
},
Requests: 65844359,
},
expectedError: false,
},
{
input: []byte("invalid-stats"),
expectedError: true,
},
}
for _, test := range tests {
r := bytes.NewReader(test.input)
result, err := parseStubStats(r)
if err != nil && !test.expectedError {
t.Errorf("parseStubStats() returned error for valid input %q: %v", string(test.input), err)
}
if !test.expectedError && test.expectedResult != *result {
t.Errorf("parseStubStats() result %v != expected %v for input %q", result, test.expectedResult, test.input)
}
}
}