punchy_test.go 1.1 KB

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