-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_test.go
115 lines (104 loc) · 3.17 KB
/
check_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package netkat_test
import (
"fmt"
"github.com/stevenayers/netkat"
"github.com/stretchr/testify/assert"
)
type (
TargetTest struct {
RawUrl string
Host string
Port int32
Path string
}
PodTest struct {
PodPort netkat.PodPort
Expected int
}
ServiceTest struct {
ServicePort netkat.ServicePort
Expected int
}
)
var (
TargetTests = []TargetTest{
{"google.com", "google.com", 80, "/"},
{"https://google.com", "google.com", 443, "/"},
{"http://google.com", "google.com", 80, "/"},
{"http://google.com:8000", "google.com", 8000, "/"},
{"google.com:8000", "google.com", 8000, "/"},
{"google.com/path", "google.com", 80, "/path"},
{"https://google.com/path", "google.com", 443, "/path"},
{"http://google.com/path", "google.com", 80, "/path"},
{"http://google.com:8000/path", "google.com", 8000, "/path"},
{"google.com:8000/path", "google.com", 8000, "/path"},
}
)
func (s *StoreSuite) TestTarget() {
for _, test := range TargetTests {
var r netkat.Checker
err := r.ParseTarget(test.RawUrl)
if err != nil {
s.T().Fatal(err)
}
assert.Equal(s.T(), test.Host, r.Target.Host)
assert.Equal(s.T(), test.Port, r.Target.Port)
assert.Equal(s.T(), test.Path, r.Target.Path)
fmt.Println(r.Target.IpAddress.String())
}
}
func (s *StoreSuite) TestRunChecks() {
var ch netkat.Checker
err := ch.ParseTarget(s.target)
if err != nil {
s.T().Fatal(err)
}
ch.KubernetesComponents = s.client.GetComponents()
ch.Client = s.client
ch.RunChecks()
assert.Equal(s.T(), 3, len(ch.PassedChecks), "Expected checks to pass")
}
func (s *StoreSuite) TestCheckKubernetesRouteFromHost() {
var ch netkat.Checker
err := ch.ParseTarget(s.target)
if err != nil {
s.T().Fatal(err)
}
ch.KubernetesComponents = s.client.GetComponents()
ch.CheckKubernetesRouteFromHost()
assert.Equal(s.T(), 1, len(ch.PassedChecks), "Expected CheckKubernetesRouteFromHost to pass")
}
func (s *StoreSuite) TestCheckStatusPod() {
var ch netkat.Checker
err := ch.ParseTarget(s.target)
if err != nil {
s.T().Fatal(err)
}
ch.KubernetesComponents = s.client.GetComponents()
ch.KubernetesRoute = &netkat.KubernetesRoute{}
ch.KubernetesRoute.Pods = ch.KubernetesComponents.PodPorts
ch.CheckStatusPod()
assert.Equal(s.T(), 1, len(ch.PassedChecks), "Expected CheckStatusPod to pass")
}
func (s *StoreSuite) TestCheckListeningPod() {
var ch netkat.Checker
ch.KubernetesComponents = s.client.GetComponents()
PodTests := []PodTest{
{netkat.PodPort{PodName: ch.KubernetesComponents.PodPorts[0].PodName, Namespace: "default", ContainerPort: 8080}, 1},
{netkat.PodPort{PodName: ch.KubernetesComponents.PodPorts[0].PodName, Namespace: "default", ContainerPort: 54921}, 0},
{netkat.PodPort{PodName: "bad-name", Namespace: "default", ContainerPort: 8080}, 0},
}
for _, test := range PodTests {
var ch netkat.Checker
err := ch.ParseTarget(s.target)
if err != nil {
s.T().Fatal(err)
}
ch.Client = s.client
ch.KubernetesRoute = &netkat.KubernetesRoute{}
ch.KubernetesRoute.Pods = []*netkat.PodPort{&test.PodPort}
ch.CheckListeningPod()
assert.Equal(s.T(), test.Expected, len(ch.PassedChecks), "Expected CheckListeningPod to pass",
test.PodPort.PodName, test.PodPort.ContainerPort)
}
}