punchy_test.go 1.0 KB

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