Skip to content

Commit 1de77b0

Browse files
hifaizskclaude
andcommitted
test: add retention policy integration tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a135930 commit 1de77b0

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

chat_retention_integration_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package getstream_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
. "github.com/GetStream/getstream-go/v4"
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestChatRetentionPolicyIntegration(t *testing.T) {
13+
t.Parallel()
14+
skipIfShort(t)
15+
client := initClient(t)
16+
ctx := context.Background()
17+
18+
t.Run("SetGetDeleteRetentionPolicy", func(t *testing.T) {
19+
policyName := "old-messages"
20+
maxAge := 720
21+
22+
// Set a retention policy
23+
setResp, err := client.Chat().SetRetentionPolicy(ctx, &SetRetentionPolicyRequest{
24+
Policy: PtrTo(policyName),
25+
MaxAgeHours: PtrTo(maxAge),
26+
})
27+
require.NoError(t, err)
28+
assert.Equal(t, policyName, setResp.Data.Policy.Policy)
29+
assert.Equal(t, maxAge, setResp.Data.Policy.Config.MaxAgeHours)
30+
31+
// Get retention policies and verify ours is present
32+
getResp, err := client.Chat().GetRetentionPolicy(ctx, &GetRetentionPolicyRequest{})
33+
require.NoError(t, err)
34+
35+
found := false
36+
for _, p := range getResp.Data.Policies {
37+
if p.Policy == policyName {
38+
found = true
39+
assert.Equal(t, maxAge, p.Config.MaxAgeHours)
40+
}
41+
}
42+
assert.True(t, found, "Created retention policy should appear in list")
43+
44+
// Update the retention policy with a new max age
45+
updatedMaxAge := 360
46+
updateResp, err := client.Chat().SetRetentionPolicy(ctx, &SetRetentionPolicyRequest{
47+
Policy: PtrTo(policyName),
48+
MaxAgeHours: PtrTo(updatedMaxAge),
49+
})
50+
require.NoError(t, err)
51+
assert.Equal(t, policyName, updateResp.Data.Policy.Policy)
52+
assert.Equal(t, updatedMaxAge, updateResp.Data.Policy.Config.MaxAgeHours)
53+
54+
// Delete the retention policy
55+
_, err = client.Chat().DeleteRetentionPolicy(ctx, &DeleteRetentionPolicyRequest{
56+
Policy: PtrTo(policyName),
57+
})
58+
require.NoError(t, err)
59+
60+
// Verify it was deleted
61+
getResp, err = client.Chat().GetRetentionPolicy(ctx, &GetRetentionPolicyRequest{})
62+
require.NoError(t, err)
63+
64+
for _, p := range getResp.Data.Policies {
65+
assert.NotEqual(t, policyName, p.Policy, "Deleted retention policy should not appear in list")
66+
}
67+
})
68+
69+
t.Run("GetRetentionPolicyRuns", func(t *testing.T) {
70+
// List retention policy runs (may be empty, but should not error)
71+
runsResp, err := client.Chat().GetRetentionPolicyRuns(ctx, &GetRetentionPolicyRunsRequest{})
72+
require.NoError(t, err)
73+
assert.NotNil(t, runsResp.Data.Runs)
74+
})
75+
76+
t.Run("GetRetentionPolicyRunsWithPagination", func(t *testing.T) {
77+
runsResp, err := client.Chat().GetRetentionPolicyRuns(ctx, &GetRetentionPolicyRunsRequest{
78+
Limit: PtrTo(5),
79+
Offset: PtrTo(0),
80+
})
81+
require.NoError(t, err)
82+
assert.NotNil(t, runsResp.Data.Runs)
83+
})
84+
}

0 commit comments

Comments
 (0)