-
Notifications
You must be signed in to change notification settings - Fork 3
/
directaccess_test.go
70 lines (56 loc) · 2.03 KB
/
directaccess_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
package core
import (
"testing"
"github.com/stretchr/testify/assert"
"org.samba/isetta/mocks"
)
var direct DirectAccess
func setupDirect(t *testing.T) {
mockDnsConfigurer = mocks.NewDnsConfigurer(t)
mockLinuxPinger = mocks.NewLinuxPinger(t)
mockLinuxConfigurer = mocks.NewLinuxConfigurer(t)
mockHttpChecker = mocks.NewHttpChecker(t)
mockEnvVarPrinter = mocks.NewEnvVarPrinter(t)
direct = DirectAccess{
PublicDnsServer: "8.8.8.8",
DnsConfigurer: mockDnsConfigurer,
LinuxPinger: mockLinuxPinger,
LinuxConfigurer: mockLinuxConfigurer,
HttpChecker: mockHttpChecker,
EnvVarPrinter: mockEnvVarPrinter,
}
}
func TestConfigureDirectInternetAccess(t *testing.T) {
setupDirect(t)
mockDnsConfigurer.On("ActivateDnsServer", "8.8.8.8").Return()
mockEnvVarPrinter.On("WarnIfProxyVarSet").Return()
// default gateway is ok as we have access to public DNS server
mockLinuxPinger.On("Ping", "8.8.8.8").Return(true)
// test url can be reached directly
mockHttpChecker.On("HasDirectInternetAccess").Return(true)
assert.NoError(t, direct.Configure())
}
func TestConfigureDirectInternetAccessWithDefaultGatewaySetup(t *testing.T) {
setupDirect(t)
mockDnsConfigurer.On("ActivateDnsServer", "8.8.8.8").Return()
mockEnvVarPrinter.On("WarnIfProxyVarSet").Return()
// default gateway is ok as we have access to public DNS server
mockLinuxPinger.On("Ping", "8.8.8.8").Return(false).Once()
mockLinuxConfigurer.On("DeleteDefaultGateway")
mockLinuxConfigurer.On("AddDefaultGateway")
// default GW setup was ok
mockLinuxPinger.On("Ping", "8.8.8.8").Return(true).Once()
// test url can be reached directly
mockHttpChecker.On("HasDirectInternetAccess").Return(true)
assert.NoError(t, direct.Configure())
}
func TestCheckHasDirectAccess(t *testing.T) {
setupDirect(t)
mockHttpChecker.On("HasDirectInternetAccess").Return(true)
assert.NoError(t, direct.checkDirectAccess())
}
func TestCheckHasNoDirectAccess(t *testing.T) {
setupDirect(t)
mockHttpChecker.On("HasDirectInternetAccess").Return(false)
assert.Error(t, direct.checkDirectAccess())
}