cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2019.11.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

connection/manager_test.go

75lines · modecode

1package connection
2
3import (
4 "testing"
5 "time"
6
7 "github.com/cloudflare/cloudflared/cmd/cloudflared/buildinfo"
8 "github.com/stretchr/testify/assert"
9
10 "github.com/cloudflare/cloudflared/h2mux"
11 "github.com/cloudflare/cloudflared/streamhandler"
12 "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
13
14 "github.com/google/uuid"
15 "github.com/sirupsen/logrus"
16)
17
18var (
19 configurable = &EdgeManagerConfigurable{
20 []h2mux.TunnelHostname{
21 "http.example.com",
22 "ws.example.com",
23 "hello.example.com",
24 },
25 &pogs.EdgeConnectionConfig{
26 NumHAConnections: 1,
27 HeartbeatInterval: 1 * time.Second,
28 Timeout: 5 * time.Second,
29 MaxFailedHeartbeats: 3,
30 UserCredentialPath: "/etc/cloudflared/cert.pem",
31 },
32 }
33 cloudflaredConfig = &CloudflaredConfig{
34 CloudflaredID: uuid.New(),
35 Tags: []pogs.Tag{
36 {Name: "pool", Value: "east-6"},
37 },
38 BuildInfo: &buildinfo.BuildInfo{
39 GoOS: "linux",
40 GoVersion: "1.12",
41 GoArch: "amd64",
42 CloudflaredVersion: "2019.6.0",
43 },
44 }
45)
46
47func mockEdgeManager() *EdgeManager {
48 newConfigChan := make(chan<- *pogs.ClientConfig)
49 useConfigResultChan := make(<-chan *pogs.UseConfigurationResult)
50 logger := logrus.New()
51 return NewEdgeManager(
52 streamhandler.NewStreamHandler(newConfigChan, useConfigResultChan, logger),
53 configurable,
54 []byte{},
55 nil,
56 &mockEdgeServiceDiscoverer{},
57 cloudflaredConfig,
58 logrus.New(),
59 )
60}
61
62func TestUpdateConfigurable(t *testing.T) {
63 m := mockEdgeManager()
64 newConfigurable := &EdgeManagerConfigurable{
65 []h2mux.TunnelHostname{
66 "second.example.com",
67 },
68 &pogs.EdgeConnectionConfig{
69 NumHAConnections: 2,
70 },
71 }
72 m.UpdateConfigurable(newConfigurable)
73
74 assert.Equal(t, newConfigurable, m.state.getConfigurable())
75}
76