@@ -1743,6 +1743,55 @@ func TestIntegration_FieldTransforms_Set(t *testing.T) {
17431743
17441744type imap map [string ]interface {}
17451745
1746+ func TestIntegration_Serialize_Deserialize_WatchQuery (t * testing.T ) {
1747+ h := testHelper {t }
1748+ collID := collectionIDs .New ()
1749+ ctx := context .Background ()
1750+ client := integrationClient (t )
1751+
1752+ partitionedQueries , err := client .CollectionGroup (collID ).GetPartitionedQueries (ctx , 10 )
1753+ h .failIfNotNil (err )
1754+
1755+ qProtoBytes , err := partitionedQueries [0 ].Serialize ()
1756+ h .failIfNotNil (err )
1757+
1758+ q , err := client .CollectionGroup (collID ).Deserialize (qProtoBytes )
1759+ h .failIfNotNil (err )
1760+
1761+ qSnapIt := q .Snapshots (ctx )
1762+ defer qSnapIt .Stop ()
1763+
1764+ // Check if at least one snapshot exists
1765+ _ , err = qSnapIt .Next ()
1766+ if err == iterator .Done {
1767+ t .Fatalf ("Expected snapshot, found none" )
1768+ }
1769+
1770+ // Add new document to query results
1771+ createdDocRefs := h .mustCreateMulti (collID , []testDocument {
1772+ {data : map [string ]interface {}{"some-key" : "should-be-found" }},
1773+ })
1774+ wds := h .mustGet (createdDocRefs [0 ])
1775+
1776+ // Check if new snapshot is available
1777+ qSnap , err := qSnapIt .Next ()
1778+ if err == iterator .Done {
1779+ t .Fatalf ("Expected snapshot, found none" )
1780+ }
1781+
1782+ // Check the changes in snapshot
1783+ if len (qSnap .Changes ) != 1 {
1784+ t .Fatalf ("Expected one change, found none" )
1785+ }
1786+
1787+ wantChange := DocumentChange {Kind : DocumentAdded , Doc : wds , OldIndex : - 1 , NewIndex : 0 }
1788+ gotChange := qSnap .Changes [0 ]
1789+ copts := append ([]cmp.Option {cmpopts .IgnoreFields (DocumentSnapshot {}, "ReadTime" )}, cmpOpts ... )
1790+ if diff := testutil .Diff (gotChange , wantChange , copts ... ); diff != "" {
1791+ t .Errorf ("got: %v, want: %v, diff: %v" , gotChange , wantChange , diff )
1792+ }
1793+ }
1794+
17461795func TestIntegration_WatchQuery (t * testing.T ) {
17471796 ctx := context .Background ()
17481797 coll := integrationColl (t )
@@ -1957,6 +2006,39 @@ type testHelper struct {
19572006 t * testing.T
19582007}
19592008
2009+ func (h testHelper ) failIfNotNil (err error ) {
2010+ if err != nil {
2011+ h .t .Fatal (err )
2012+ }
2013+ }
2014+
2015+ type testDocument struct {
2016+ id string
2017+ data map [string ]interface {}
2018+ }
2019+
2020+ func (h testHelper ) mustCreateMulti (collectionPath string , docsData []testDocument ) []* DocumentRef {
2021+ client := integrationClient (h .t )
2022+ collRef := client .Collection (collectionPath )
2023+ docsCreated := []* DocumentRef {}
2024+ for _ , data := range docsData {
2025+ var docRef * DocumentRef
2026+ if len (data .id ) == 0 {
2027+ docRef = collRef .NewDoc ()
2028+ } else {
2029+ docRef = collRef .Doc (data .id )
2030+ }
2031+ h .mustCreate (docRef , data .data )
2032+ docsCreated = append (docsCreated , docRef )
2033+ }
2034+
2035+ h .t .Cleanup (func () {
2036+ deleteDocuments (docsCreated )
2037+ })
2038+
2039+ return docsCreated
2040+ }
2041+
19602042func (h testHelper ) mustCreate (doc * DocumentRef , data interface {}) * WriteResult {
19612043 wr , err := doc .Create (context .Background (), data )
19622044 if err != nil {
0 commit comments