punchy_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package nebula
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestNewPunchyFromConfig(t *testing.T) {
  8. l := NewTestLogger()
  9. c := NewConfig(l)
  10. // Test defaults
  11. p := NewPunchyFromConfig(c)
  12. assert.Equal(t, false, p.Punch)
  13. assert.Equal(t, false, p.Respond)
  14. assert.Equal(t, time.Second, p.Delay)
  15. // punchy deprecation
  16. c.Settings["punchy"] = true
  17. p = NewPunchyFromConfig(c)
  18. assert.Equal(t, true, p.Punch)
  19. // punchy.punch
  20. c.Settings["punchy"] = map[interface{}]interface{}{"punch": true}
  21. p = NewPunchyFromConfig(c)
  22. assert.Equal(t, true, p.Punch)
  23. // punch_back deprecation
  24. c.Settings["punch_back"] = true
  25. p = NewPunchyFromConfig(c)
  26. assert.Equal(t, true, p.Respond)
  27. // punchy.respond
  28. c.Settings["punchy"] = map[interface{}]interface{}{"respond": true}
  29. c.Settings["punch_back"] = false
  30. p = NewPunchyFromConfig(c)
  31. assert.Equal(t, true, p.Respond)
  32. // punchy.delay
  33. c.Settings["punchy"] = map[interface{}]interface{}{"delay": "1m"}
  34. p = NewPunchyFromConfig(c)
  35. assert.Equal(t, time.Minute, p.Delay)
  36. }