2021-12-08 14:03:07 +01:00
|
|
|
package config_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gotest.tools/assert"
|
2022-05-05 12:12:43 +02:00
|
|
|
"k8s.io/client-go/rest"
|
2021-12-08 14:03:07 +01:00
|
|
|
|
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_CreateClientConfig_WithKubeConfig(t *testing.T) {
|
2022-05-05 12:12:43 +02:00
|
|
|
c := &rest.Config{}
|
|
|
|
err := config.ConfigureClientConfig(c, 0, 0)
|
2021-12-08 14:03:07 +01:00
|
|
|
assert.NilError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_CreateClientConfig_SetBurstQPS(t *testing.T) {
|
|
|
|
const (
|
|
|
|
qps = 55
|
|
|
|
burst = 99
|
|
|
|
)
|
2022-05-05 12:12:43 +02:00
|
|
|
c := &rest.Config{}
|
|
|
|
err := config.ConfigureClientConfig(c, qps, burst)
|
2021-12-08 14:03:07 +01:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, float32(qps), c.QPS)
|
|
|
|
assert.Equal(t, burst, c.Burst)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_CreateClientConfig_LimitQPStoFloat32(t *testing.T) {
|
|
|
|
qps := float64(math.MaxFloat32) * 2
|
2022-05-05 12:12:43 +02:00
|
|
|
c := &rest.Config{}
|
|
|
|
err := config.ConfigureClientConfig(c, qps, 0)
|
2021-12-08 14:03:07 +01:00
|
|
|
assert.ErrorContains(t, err, "QPS")
|
|
|
|
}
|