@@ -2,9 +2,14 @@ package perconaservermongodb
22
33import (
44 "context"
5+ "os"
6+ "testing"
7+ "time"
58
69 . "github.com/onsi/ginkgo/v2"
710 . "github.com/onsi/gomega"
11+ "github.com/stretchr/testify/assert"
12+ "github.com/stretchr/testify/require"
813 corev1 "k8s.io/api/core/v1"
914 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1015 "k8s.io/apimachinery/pkg/types"
@@ -13,6 +18,67 @@ import (
1318 psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
1419)
1520
21+ func TestGetReconcileInterval (t * testing.T ) {
22+ tests := []struct {
23+ name string
24+ envValue string
25+ setEnv bool
26+ want time.Duration
27+ }{
28+ {
29+ name : "unset" ,
30+ setEnv : false ,
31+ want : 5 * time .Second ,
32+ },
33+ {
34+ name : "valid duration" ,
35+ envValue : "30s" ,
36+ setEnv : true ,
37+ want : 30 * time .Second ,
38+ },
39+ {
40+ name : "invalid duration falls back to default" ,
41+ envValue : "invalid" ,
42+ setEnv : true ,
43+ want : 5 * time .Second ,
44+ },
45+ {
46+ name : "zero duration falls back to default" ,
47+ envValue : "0s" ,
48+ setEnv : true ,
49+ want : 5 * time .Second ,
50+ },
51+ {
52+ name : "negative duration falls back to default" ,
53+ envValue : "-5s" ,
54+ setEnv : true ,
55+ want : 5 * time .Second ,
56+ },
57+ {
58+ name : "duration less than 5s falls back to default" ,
59+ envValue : "1s" ,
60+ setEnv : true ,
61+ want : 5 * time .Second ,
62+ },
63+ }
64+
65+ for _ , tt := range tests {
66+ t .Run (tt .name , func (t * testing.T ) {
67+ defer func () {
68+ err := os .Unsetenv ("RECONCILE_INTERVAL" )
69+ require .NoError (t , err )
70+ }()
71+ if tt .setEnv {
72+ err := os .Setenv ("RECONCILE_INTERVAL" , tt .envValue )
73+ require .NoError (t , err )
74+ }
75+
76+ got := getReconcileInterval ()
77+ assert .Equal (t , tt .want , got )
78+ })
79+ }
80+ }
81+
1682var _ = Describe ("PerconaServerMongoDB" , Ordered , func () {
1783 ctx := context .Background ()
1884 const ns = "psmdb"
0 commit comments