github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/pgp_keyfinder_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  // Tests for the PGPKeyfinder engine.
     5  
     6  package engine
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/keybase/client/go/libkb"
    12  )
    13  
    14  func TestPGPKeyfinder(t *testing.T) {
    15  	tc := SetupEngineTest(t, "PGPKeyfinder")
    16  	defer tc.Cleanup()
    17  	sigVersion := libkb.GetDefaultSigVersion(tc.G)
    18  
    19  	u := CreateAndSignupFakeUser(tc, "login")
    20  	// track alice before starting so we have a user already tracked
    21  	trackAlice(tc, u, sigVersion)
    22  	defer untrackAlice(tc, u, sigVersion)
    23  
    24  	arg := &PGPKeyfinderArg{
    25  		Usernames: []string{"t_alice", "t_bob", "t_charlie"},
    26  	}
    27  	eng := NewPGPKeyfinder(tc.G, arg)
    28  	m := NewMetaContextForTest(tc)
    29  	if err := RunEngine2(m, eng); err != nil {
    30  		t.Fatal(err)
    31  	}
    32  
    33  	up := eng.UsersPlusKeys()
    34  	if len(up) != 3 {
    35  		t.Errorf("number of users found: %d, expected 3", len(up))
    36  	}
    37  }
    38  
    39  func TestPGPKeyfinderLoggedOut(t *testing.T) {
    40  	tc := SetupEngineTest(t, "PGPKeyfinder")
    41  	defer tc.Cleanup()
    42  
    43  	arg := &PGPKeyfinderArg{
    44  		Usernames: []string{"t_alice", "t_bob", "t_charlie"},
    45  	}
    46  	eng := NewPGPKeyfinder(tc.G, arg)
    47  	m := NewMetaContextForTest(tc)
    48  	if err := RunEngine2(m, eng); err != nil {
    49  		t.Fatal(err)
    50  	}
    51  
    52  	up := eng.UsersPlusKeys()
    53  	if len(up) != 3 {
    54  		t.Errorf("number of users found: %d, expected 3", len(up))
    55  	}
    56  }