/
forwarder_test.go
80 lines (67 loc) · 1.69 KB
/
forwarder_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
package forwarder
import (
"fmt"
"testing"
"github.com/eko/monday/internal/config"
mocks "github.com/eko/monday/internal/tests/mocks/proxy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestNewForwarder(t *testing.T) {
// Given
proxy := &mocks.ProxyInterface{}
project := &config.Project{
Name: "My project name",
Forwards: []*config.Forward{
&config.Forward{
Name: "test-kubernetes-forward",
Type: "kubernetes",
Values: config.ForwardValues{
Namespace: "test",
Labels: map[string]string{
"app": "my-test-app",
},
},
},
},
}
// When
forwarder := NewForwarder(proxy, project)
// Then
assert.IsType(t, new(Forwarder), forwarder)
assert.Equal(t, proxy, forwarder.proxy)
assert.Equal(t, project.Forwards, forwarder.forwards)
}
func TestForwardAll(t *testing.T) {
// Given
proxy := &mocks.ProxyInterface{}
proxy.
On("AddProxyForward", mock.AnythingOfType("string"), mock.AnythingOfType("*proxy.ProxyForward")).
Times(2)
proxy.On("Listen").Once().Return(nil)
project := &config.Project{
Name: "My project name",
Forwards: []*config.Forward{
&config.Forward{
Name: "test-ssh-forward",
Type: "ssh",
Values: config.ForwardValues{
Remote: "root@acme.tld",
Ports: []string{"8080:8080"},
},
},
},
}
forwarder := NewForwarder(proxy, project)
// When
forwarder.ForwardAll()
// Then
assert.Len(t, forwarder.forwards, 1)
for _, forward := range project.Forwards {
if v, ok := forwarder.forwarders.Load(forward.Name); ok {
assert.Len(t, v.([]ForwarderTypeInterface), 1)
} else {
t.Fatal(fmt.Sprintf("No forwarder found for forward named '%s'", forward.Name))
}
}
}