Skip to content

Commit 88402fc

Browse files
committed
add tests
1 parent 241c162 commit 88402fc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

internal/rule/rule_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"testing"
77
"time"
88

9+
"github.com/centrifugal/centrifugo/v5/internal/tools"
10+
911
"github.com/stretchr/testify/require"
1012
)
1113

@@ -100,6 +102,39 @@ func TestConfigValidatePersonalSingleConnectionOK(t *testing.T) {
100102
require.NoError(t, err)
101103
}
102104

105+
func TestConfigValidateHistoryTTL(t *testing.T) {
106+
t.Run("in_namespace", func(t *testing.T) {
107+
c := DefaultConfig
108+
c.Namespaces = []ChannelNamespace{
109+
{
110+
Name: "name1",
111+
ChannelOptions: ChannelOptions{
112+
HistorySize: 10,
113+
HistoryTTL: tools.Duration(20 * time.Second),
114+
HistoryMetaTTL: tools.Duration(10 * time.Second),
115+
},
116+
},
117+
}
118+
err := c.Validate()
119+
require.ErrorContains(t, err, "history meta ttl")
120+
})
121+
t.Run("on_top_level", func(t *testing.T) {
122+
c := DefaultConfig
123+
c.HistorySize = 10
124+
c.HistoryTTL = tools.Duration(31 * 24 * time.Hour)
125+
err := c.Validate()
126+
require.ErrorContains(t, err, "history meta ttl")
127+
})
128+
t.Run("top_level_non_default_global", func(t *testing.T) {
129+
c := DefaultConfig
130+
c.GlobalHistoryMetaTTL = 10 * time.Hour
131+
c.HistorySize = 10
132+
c.HistoryTTL = tools.Duration(30 * 24 * time.Hour)
133+
err := c.Validate()
134+
require.ErrorContains(t, err, "history meta ttl")
135+
})
136+
}
137+
103138
func TestConfigValidatePersonalSingleConnectionNamespacedFail(t *testing.T) {
104139
c := DefaultConfig
105140
c.Namespaces = []ChannelNamespace{}

0 commit comments

Comments
 (0)