Browse Source

Add some tests for the helper functions

master
Zachary Seguin 5 years ago
parent
commit
e2810e24fe
  1. 63
      networks_test.go
  2. 26
      nginx_test.go

63
networks_test.go

@ -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

@ -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")
}
Loading…
Cancel
Save