blob: 78afd2272b8822a1d8c62c41e33e0bbd592900d0 [file] [log] [blame]
Serge Bazanski6b649f82021-05-24 15:09:25 +02001package kubenat
2
3import (
4 "context"
5 "flag"
6 "net"
7 "testing"
8)
9
10func TestResolvePod(t *testing.T) {
11 t.Skip("needs containerd running on host and unhardcoded test data")
12 flag.Set("logtostderr", "true")
13
14 ctx, ctxC := context.WithCancel(context.Background())
15 defer ctxC()
16
17 r, err := NewResolver(ctx, "/tmp/conntrack", "/tmp/containerd.sock")
18 if err != nil {
19 t.Fatalf("NewResolver: %v", err)
20 }
21
22 pi, err := r.ResolvePod(ctx, &Tuple4{
23 RemoteIP: net.IPv4(185, 191, 225, 10),
24 RemotePort: 6697,
25 LocalIP: net.IPv4(185, 236, 240, 36),
26 LocalPort: 53449,
27 })
28 if err != nil {
29 t.Fatalf("ResolvePod: %v", err)
30 }
31 if want, got := net.IPv4(10, 10, 26, 23), pi.PodIP; !want.Equal(got) {
32 t.Errorf("Wanted pod IP %v, got %v", want, got)
33 }
34 if want, got := uint16(54782), pi.PodTranslatedPort; want != got {
35 t.Errorf("Wanted pod port %d, got %d", want, got)
36 }
37 if want, got := "matrix", pi.KubernetesNamespace; want != got {
38 t.Errorf("Wanted pod namespace %q, got %q", want, got)
39 }
40 if want, got := "appservice-irc-freenode-68977cdd5f-kfzl6", pi.Name; want != got {
41 t.Errorf("Wanted pod name %q, got %q", want, got)
42 }
43}