cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
connection/manager_test.go
77lines · modecode
| 1 | package connection |
| 2 | |
| 3 | import ( |
| 4 | "net" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/google/uuid" |
| 9 | "github.com/sirupsen/logrus" |
| 10 | "github.com/stretchr/testify/assert" |
| 11 | |
| 12 | "github.com/cloudflare/cloudflared/cmd/cloudflared/buildinfo" |
| 13 | "github.com/cloudflare/cloudflared/edgediscovery" |
| 14 | "github.com/cloudflare/cloudflared/h2mux" |
| 15 | "github.com/cloudflare/cloudflared/streamhandler" |
| 16 | "github.com/cloudflare/cloudflared/tunnelrpc/pogs" |
| 17 | ) |
| 18 | |
| 19 | var ( |
| 20 | configurable = &EdgeManagerConfigurable{ |
| 21 | []h2mux.TunnelHostname{ |
| 22 | "http.example.com", |
| 23 | "ws.example.com", |
| 24 | "hello.example.com", |
| 25 | }, |
| 26 | &pogs.EdgeConnectionConfig{ |
| 27 | NumHAConnections: 1, |
| 28 | HeartbeatInterval: 1 * time.Second, |
| 29 | Timeout: 5 * time.Second, |
| 30 | MaxFailedHeartbeats: 3, |
| 31 | UserCredentialPath: "/etc/cloudflared/cert.pem", |
| 32 | }, |
| 33 | } |
| 34 | cloudflaredConfig = &CloudflaredConfig{ |
| 35 | CloudflaredID: uuid.New(), |
| 36 | Tags: []pogs.Tag{ |
| 37 | {Name: "pool", Value: "east-6"}, |
| 38 | }, |
| 39 | BuildInfo: &buildinfo.BuildInfo{ |
| 40 | GoOS: "linux", |
| 41 | GoVersion: "1.12", |
| 42 | GoArch: "amd64", |
| 43 | CloudflaredVersion: "2019.6.0", |
| 44 | }, |
| 45 | } |
| 46 | ) |
| 47 | |
| 48 | func mockEdgeManager() *EdgeManager { |
| 49 | newConfigChan := make(chan<- *pogs.ClientConfig) |
| 50 | useConfigResultChan := make(<-chan *pogs.UseConfigurationResult) |
| 51 | logger := logrus.New() |
| 52 | edge := edgediscovery.MockEdge(logger, []*net.TCPAddr{}) |
| 53 | return NewEdgeManager( |
| 54 | streamhandler.NewStreamHandler(newConfigChan, useConfigResultChan, logger), |
| 55 | configurable, |
| 56 | []byte{}, |
| 57 | nil, |
| 58 | edge, |
| 59 | cloudflaredConfig, |
| 60 | logger, |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | func 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 | |