1// Copyright 2015 Keybase, Inc. All rights reserved. Use of
2// this source code is governed by the included BSD license.
3
4package engine
5
6import (
7	"testing"
8
9	"github.com/keybase/client/go/libkb"
10)
11
12// TestTrackerList2 creates a new fake user and has that user track
13// t_alice. It then uses the TrackerList engine to get the
14// t_alice's trackers and makes sure that the new fake user is in
15// the list.
16func TestListTrackers2(t *testing.T) {
17	doWithSigChainVersions(func(sigVersion libkb.SigVersion) {
18		_testListTrackers2(t, sigVersion)
19	})
20}
21
22func _testListTrackers2(t *testing.T, sigVersion libkb.SigVersion) {
23	tc := SetupEngineTest(t, "trackerlist")
24	defer tc.Cleanup()
25
26	fu := CreateAndSignupFakeUser(tc, "login")
27	trackAlice(tc, fu, sigVersion)
28	defer untrackAlice(tc, fu, sigVersion)
29
30	e := NewListTrackersUnverifiedEngine(tc.G, ListTrackersUnverifiedEngineArg{Assertion: "t_alice"})
31	m := NewMetaContextForTestWithLogUI(tc)
32	if err := RunEngine2(m, e); err != nil {
33		t.Fatal(err)
34	}
35	res := e.GetResults()
36	if len(res.Users) == 0 {
37		t.Errorf("t_alice tracker count: 0. expected > 0.")
38	}
39
40	found := false
41	for _, x := range res.Users {
42		if x.Username == fu.Username {
43			found = true
44			break
45		}
46	}
47	if !found {
48		t.Errorf("fake user %q not included in list of t_alice trackers.", fu.Username)
49		t.Logf("tracker list:")
50		for i, x := range res.Users {
51			t.Logf("%d: %s", i, x.Username)
52		}
53	}
54}
55