github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/maps/trackstorage_test.go (about)

     1  package maps
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/keybase/client/go/chat/globals"
     9  	"github.com/keybase/client/go/kbtest"
    10  	"github.com/keybase/client/go/protocol/chat1"
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"github.com/keybase/client/go/libkb"
    14  )
    15  
    16  func TestTrackStorage(t *testing.T) {
    17  	tc := libkb.SetupTest(t, "TestTrackStorage", 1)
    18  	defer tc.Cleanup()
    19  	_, err := kbtest.CreateAndSignupFakeUser("t", tc.G)
    20  	require.NoError(t, err)
    21  	ts := newTrackStorage(&globals.Context{GlobalContext: tc.G, ChatContext: nil})
    22  	trackers := []*locationTrack{
    23  		{
    24  			convID:  chat1.ConversationID([]byte{0, 0, 1}),
    25  			msgID:   5,
    26  			endTime: time.Now().Add(time.Hour),
    27  			allCoords: []chat1.Coordinate{
    28  				{
    29  					Lat: -41.8983,
    30  					Lon: 79.882,
    31  				},
    32  			},
    33  		},
    34  	}
    35  	require.NoError(t, ts.Save(context.TODO(), trackers))
    36  	res, err := ts.Restore(context.TODO())
    37  	require.NoError(t, err)
    38  	require.Equal(t, 1, len(res))
    39  	require.Equal(t, len(trackers[0].allCoords), len(res[0].allCoords))
    40  	require.Equal(t, trackers[0].allCoords[0].Lat, res[0].allCoords[0].Lat)
    41  }