initial working version
This commit is contained in:
parent
4d8b83cbb6
commit
8318f9fe70
15 changed files with 917 additions and 4 deletions
61
internal/dnstt/collector_test.go
Normal file
61
internal/dnstt/collector_test.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package dnstt
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCollectorTracksActiveAndPeakClients(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
c := NewCollector([]string{"tunnel.example.com"}, WithNow(func() time.Time { return now }))
|
||||
|
||||
c.RecordQuery("tunnel.example.com", "client-a", 120)
|
||||
c.RecordQuery("tunnel.example.com", "client-b", 80)
|
||||
c.RecordResponse("tunnel.example.com", 200)
|
||||
|
||||
snapshot := c.Snapshot()
|
||||
tunnel := snapshot.Tunnels["tunnel.example.com"]
|
||||
if tunnel.ActiveClients != 2 {
|
||||
t.Fatalf("active clients = %d, want 2", tunnel.ActiveClients)
|
||||
}
|
||||
if tunnel.PeakClients != 2 {
|
||||
t.Fatalf("peak clients = %d, want 2", tunnel.PeakClients)
|
||||
}
|
||||
if tunnel.TotalSessions != 2 {
|
||||
t.Fatalf("total sessions = %d, want 2", tunnel.TotalSessions)
|
||||
}
|
||||
if tunnel.TotalQueries != 2 {
|
||||
t.Fatalf("queries = %d, want 2", tunnel.TotalQueries)
|
||||
}
|
||||
if tunnel.BytesIn != 200 {
|
||||
t.Fatalf("bytes in = %d, want 200", tunnel.BytesIn)
|
||||
}
|
||||
if tunnel.BytesOut != 200 {
|
||||
t.Fatalf("bytes out = %d, want 200", tunnel.BytesOut)
|
||||
}
|
||||
|
||||
now = now.Add(ClientTimeout + time.Second)
|
||||
snapshot = c.Snapshot()
|
||||
tunnel = snapshot.Tunnels["tunnel.example.com"]
|
||||
if tunnel.ActiveClients != 0 {
|
||||
t.Fatalf("active clients after timeout = %d, want 0", tunnel.ActiveClients)
|
||||
}
|
||||
if tunnel.PeakClients != 2 {
|
||||
t.Fatalf("peak clients after timeout = %d, want 2", tunnel.PeakClients)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectorMatchesSubdomainsToRegisteredTunnel(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
c := NewCollector([]string{"tunnel.example.com"}, WithNow(func() time.Time { return now }))
|
||||
|
||||
c.RecordQuery("abcd.tunnel.example.com", "client-a", 120)
|
||||
|
||||
tunnel := c.Snapshot().Tunnels["tunnel.example.com"]
|
||||
if tunnel.TotalQueries != 1 {
|
||||
t.Fatalf("queries = %d, want 1", tunnel.TotalQueries)
|
||||
}
|
||||
if tunnel.ActiveClients != 1 {
|
||||
t.Fatalf("active clients = %d, want 1", tunnel.ActiveClients)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue