cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2019.7.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

connection/manager_test.go

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