2020-03-27 19:26:39 +01:00
|
|
|
package nebula
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
2020-07-01 00:53:30 +02:00
|
|
|
|
2021-11-04 02:54:04 +01:00
|
|
|
"github.com/slackhq/nebula/config"
|
2021-11-11 04:47:38 +01:00
|
|
|
"github.com/slackhq/nebula/test"
|
2020-07-01 00:53:30 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-03-27 19:26:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPunchyFromConfig(t *testing.T) {
|
2021-11-11 04:47:38 +01:00
|
|
|
l := test.NewLogger()
|
2021-11-04 02:54:04 +01:00
|
|
|
c := config.NewC(l)
|
2020-03-27 19:26:39 +01:00
|
|
|
|
|
|
|
// Test defaults
|
|
|
|
p := NewPunchyFromConfig(c)
|
|
|
|
assert.Equal(t, false, p.Punch)
|
|
|
|
assert.Equal(t, false, p.Respond)
|
|
|
|
assert.Equal(t, time.Second, p.Delay)
|
|
|
|
|
|
|
|
// punchy deprecation
|
|
|
|
c.Settings["punchy"] = true
|
|
|
|
p = NewPunchyFromConfig(c)
|
|
|
|
assert.Equal(t, true, p.Punch)
|
|
|
|
|
|
|
|
// punchy.punch
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"punch": true}
|
|
|
|
p = NewPunchyFromConfig(c)
|
|
|
|
assert.Equal(t, true, p.Punch)
|
|
|
|
|
|
|
|
// punch_back deprecation
|
|
|
|
c.Settings["punch_back"] = true
|
|
|
|
p = NewPunchyFromConfig(c)
|
|
|
|
assert.Equal(t, true, p.Respond)
|
|
|
|
|
|
|
|
// punchy.respond
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"respond": true}
|
|
|
|
c.Settings["punch_back"] = false
|
|
|
|
p = NewPunchyFromConfig(c)
|
|
|
|
assert.Equal(t, true, p.Respond)
|
|
|
|
|
|
|
|
// punchy.delay
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"delay": "1m"}
|
|
|
|
p = NewPunchyFromConfig(c)
|
|
|
|
assert.Equal(t, time.Minute, p.Delay)
|
|
|
|
}
|