configuration_test.go 1.8 KB

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