Add some tests for the helper functions

This commit is contained in:
Zachary Seguin 2017-06-19 14:12:36 -04:00
parent ab12f1f445
commit e2810e24fe
2 changed files with 89 additions and 0 deletions

63
networks_test.go Normal file
View File

@ -0,0 +1,63 @@
package main
import (
"net"
"testing"
)
func TestUWaterlooIPv4(t *testing.T) {
expected := "uwaterloo"
actual := IdentifyNetwork(net.ParseIP("129.97.134.71"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}
func TestUWaterlooIPv6(t *testing.T) {
expected := "uwaterloo"
actual := IdentifyNetwork(net.ParseIP("2620:101:f000:4901:c5c::f:1055"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}
func TestOtherIPv4(t *testing.T) {
expected := "other"
actual := IdentifyNetwork(net.ParseIP("8.8.8.8"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}
func TestOtherIPv6(t *testing.T) {
expected := "other"
actual := IdentifyNetwork(net.ParseIP("2001:4860:4860::8888"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}
func TestIPv4Protocol(t *testing.T) {
expected := "ipv4"
actual := IdentifyIPProtocol(net.ParseIP("129.97.134.71"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}
func TestIPv6Protocol(t *testing.T) {
expected := "ipv6"
actual := IdentifyIPProtocol(net.ParseIP("2620:101:f000:4901:c5c::f:1055"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}
func TestUnknownProtocol(t *testing.T) {
expected := "other"
actual := IdentifyIPProtocol(net.ParseIP("computer"))
if actual != expected {
t.Fatalf("Expected %s, got %s", expected, actual)
}
}

26
nginx_test.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"testing"
)
func testCreate(t *testing.T, path string) {
exporter, err := NewNginxExporter(path)
if err != nil {
t.Fatal("err was not nil.", err)
}
// Check path on exporter
if exporter.AccessLogPath != path {
t.Fatalf("Wrong path in Nginx Exporter object. Expected %s, got %s", path, exporter.AccessLogPath)
}
}
func TestCreateNginxExporter(t *testing.T) {
testCreate(t, "/var/log/nginx/access.log")
}
func TestCreateNginxExporterWithNonStandardNginxPath(t *testing.T) {
testCreate(t, "/tmp/nginx.log")
}