github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/storage/version_test.go (about) 1 package storage 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/keybase/client/go/protocol/chat1" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestServerVersionSync(t *testing.T) { 12 tc := setupCommonTest(t, "version") 13 defer tc.Cleanup() 14 15 err := tc.Context().ServerCacheVersions.Set(context.TODO(), chat1.ServerCacheVers{ 16 InboxVers: 10, 17 BodiesVers: 5, 18 }) 19 require.NoError(t, err) 20 21 res, err := tc.Context().ServerCacheVersions.Fetch(context.TODO()) 22 require.NoError(t, err) 23 require.Equal(t, 10, res.InboxVers) 24 require.Equal(t, 5, res.BodiesVers) 25 26 err = tc.Context().ServerCacheVersions.Set(context.TODO(), chat1.ServerCacheVers{ 27 InboxVers: 10, 28 BodiesVers: 5, 29 }) 30 require.NoError(t, err) 31 32 vers, err := tc.Context().ServerCacheVersions.MatchInbox(context.TODO(), 10) 33 require.NoError(t, err) 34 require.Equal(t, 10, vers) 35 36 vers, err = tc.Context().ServerCacheVersions.MatchBodies(context.TODO(), 5) 37 require.NoError(t, err) 38 require.Equal(t, 5, vers) 39 40 _, err = tc.Context().ServerCacheVersions.MatchInbox(context.TODO(), 11) 41 require.Error(t, err) 42 require.IsType(t, VersionMismatchError{}, err) 43 }