2020-03-27 12:26:39 -06:00
|
|
|
package nebula
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
2020-06-30 16:53:30 -06:00
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
"github.com/slackhq/nebula/config"
|
2021-11-10 20:47:38 -07:00
|
|
|
"github.com/slackhq/nebula/test"
|
2020-06-30 16:53:30 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-03-27 12:26:39 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPunchyFromConfig(t *testing.T) {
|
2021-11-10 20:47:38 -07:00
|
|
|
l := test.NewLogger()
|
2021-11-03 19:54:04 -06:00
|
|
|
c := config.NewC(l)
|
2020-03-27 12:26:39 -06:00
|
|
|
|
|
|
|
// Test defaults
|
2022-03-14 11:35:13 -06:00
|
|
|
p := NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, false, p.GetPunch())
|
|
|
|
assert.Equal(t, false, p.GetRespond())
|
|
|
|
assert.Equal(t, time.Second, p.GetDelay())
|
2023-03-29 13:32:35 -06:00
|
|
|
assert.Equal(t, 5*time.Second, p.GetRespondDelay())
|
2020-03-27 12:26:39 -06:00
|
|
|
|
|
|
|
// punchy deprecation
|
|
|
|
c.Settings["punchy"] = true
|
2022-03-14 11:35:13 -06:00
|
|
|
p = NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, true, p.GetPunch())
|
2020-03-27 12:26:39 -06:00
|
|
|
|
|
|
|
// punchy.punch
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"punch": true}
|
2022-03-14 11:35:13 -06:00
|
|
|
p = NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, true, p.GetPunch())
|
2020-03-27 12:26:39 -06:00
|
|
|
|
|
|
|
// punch_back deprecation
|
|
|
|
c.Settings["punch_back"] = true
|
2022-03-14 11:35:13 -06:00
|
|
|
p = NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, true, p.GetRespond())
|
2020-03-27 12:26:39 -06:00
|
|
|
|
|
|
|
// punchy.respond
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"respond": true}
|
|
|
|
c.Settings["punch_back"] = false
|
2022-03-14 11:35:13 -06:00
|
|
|
p = NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, true, p.GetRespond())
|
2020-03-27 12:26:39 -06:00
|
|
|
|
|
|
|
// punchy.delay
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"delay": "1m"}
|
2022-03-14 11:35:13 -06:00
|
|
|
p = NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, time.Minute, p.GetDelay())
|
2023-03-29 13:32:35 -06:00
|
|
|
|
|
|
|
// punchy.respond_delay
|
|
|
|
c.Settings["punchy"] = map[interface{}]interface{}{"respond_delay": "1m"}
|
|
|
|
p = NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, time.Minute, p.GetRespondDelay())
|
2022-03-14 11:35:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPunchy_reload(t *testing.T) {
|
|
|
|
l := test.NewLogger()
|
|
|
|
c := config.NewC(l)
|
|
|
|
delay, _ := time.ParseDuration("1m")
|
|
|
|
assert.NoError(t, c.LoadString(`
|
|
|
|
punchy:
|
|
|
|
delay: 1m
|
|
|
|
respond: false
|
|
|
|
`))
|
|
|
|
p := NewPunchyFromConfig(l, c)
|
|
|
|
assert.Equal(t, delay, p.GetDelay())
|
|
|
|
assert.Equal(t, false, p.GetRespond())
|
|
|
|
|
|
|
|
newDelay, _ := time.ParseDuration("10m")
|
|
|
|
assert.NoError(t, c.ReloadConfigString(`
|
|
|
|
punchy:
|
|
|
|
delay: 10m
|
|
|
|
respond: true
|
|
|
|
`))
|
|
|
|
p.reload(c, false)
|
|
|
|
assert.Equal(t, newDelay, p.GetDelay())
|
|
|
|
assert.Equal(t, true, p.GetRespond())
|
2020-03-27 12:26:39 -06:00
|
|
|
}
|