cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2021.10.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

config/configuration_test.go

83lines · modecode

1package config
2
3import (
4 "testing"
5 "time"
6
7 "github.com/stretchr/testify/assert"
8 yaml "gopkg.in/yaml.v2"
9)
10
11func TestConfigFileSettings(t *testing.T) {
12 var (
13 firstIngress = UnvalidatedIngressRule{
14 Hostname: "tunnel1.example.com",
15 Path: "/id",
16 Service: "https://localhost:8000",
17 }
18 secondIngress = UnvalidatedIngressRule{
19 Hostname: "*",
20 Path: "",
21 Service: "https://localhost:8001",
22 }
23 warpRouting = WarpRoutingConfig{
24 Enabled: true,
25 }
26 )
27 rawYAML := `
28tunnel: config-file-test
29ingress:
30 - hostname: tunnel1.example.com
31 path: /id
32 service: https://localhost:8000
33 - hostname: "*"
34 service: https://localhost:8001
35warp-routing:
36 enabled: true
37retries: 5
38grace-period: 30s
39percentage: 3.14
40hostname: example.com
41tag:
42 - test
43 - central-1
44counters:
45 - 123
46 - 456
47`
48 var config configFileSettings
49 err := yaml.Unmarshal([]byte(rawYAML), &config)
50 assert.NoError(t, err)
51
52 assert.Equal(t, "config-file-test", config.TunnelID)
53 assert.Equal(t, firstIngress, config.Ingress[0])
54 assert.Equal(t, secondIngress, config.Ingress[1])
55 assert.Equal(t, warpRouting, config.WarpRouting)
56
57 retries, err := config.Int("retries")
58 assert.NoError(t, err)
59 assert.Equal(t, 5, retries)
60
61 gracePeriod, err := config.Duration("grace-period")
62 assert.NoError(t, err)
63 assert.Equal(t, time.Second*30, gracePeriod)
64
65 percentage, err := config.Float64("percentage")
66 assert.NoError(t, err)
67 assert.Equal(t, 3.14, percentage)
68
69 hostname, err := config.String("hostname")
70 assert.NoError(t, err)
71 assert.Equal(t, "example.com", hostname)
72
73 tags, err := config.StringSlice("tag")
74 assert.NoError(t, err)
75 assert.Equal(t, "test", tags[0])
76 assert.Equal(t, "central-1", tags[1])
77
78 counters, err := config.IntSlice("counters")
79 assert.NoError(t, err)
80 assert.Equal(t, 123, counters[0])
81 assert.Equal(t, 456, counters[1])
82
83}
84