github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/interesting_test.go (about)

     1  package service
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/keybase/client/go/kbtest"
     8  	"github.com/keybase/client/go/libkb"
     9  	"github.com/keybase/client/go/protocol/keybase1"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestInterestingPeople(t *testing.T) {
    14  	tc := libkb.SetupTest(t, "gregor", 3)
    15  	defer tc.Cleanup()
    16  	tc.G.SetService()
    17  
    18  	maxUsers := 3
    19  	var users []*kbtest.FakeUser
    20  	for i := 0; i < maxUsers; i++ {
    21  		u, err := kbtest.CreateAndSignupFakeUser("ppl", tc.G)
    22  		require.NoError(t, err)
    23  		users = append(users, u)
    24  	}
    25  	fn1 := func(uid keybase1.UID) (res []keybase1.UID, err error) {
    26  		for _, u := range users {
    27  			res = append(res, u.User.GetUID())
    28  		}
    29  		return res, nil
    30  	}
    31  
    32  	// Sign up an addition user
    33  	u, err := kbtest.CreateAndSignupFakeUser("ppl", tc.G)
    34  	require.NoError(t, err)
    35  	users = append(users, u)
    36  
    37  	fn2 := func(uid keybase1.UID) (res []keybase1.UID, err error) {
    38  		for i := len(users) - 1; i >= 0; i-- {
    39  			res = append(res, u.User.GetUID())
    40  		}
    41  		return res, nil
    42  	}
    43  
    44  	ip := newInterestingPeople(tc.G)
    45  	ip.AddSource(fn1, 0.9)
    46  	ip.AddSource(fn2, 0.1)
    47  
    48  	res, err := ip.Get(context.TODO(), 20)
    49  	require.NoError(t, err)
    50  	require.Equal(t, maxUsers+1, len(res))
    51  	require.Equal(t, users[0].GetUID(), res[0])
    52  	require.Equal(t, users[len(users)-1].GetUID(), res[len(res)-1])
    53  
    54  }