MCPcopy Index your code
hub / github.com/coder/coder / prepareTestGitSSH

Function prepareTestGitSSH

cli/gitssh_test.go:34–63  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func prepareTestGitSSH(ctx context.Context, t *testing.T) (*agentsdk.Client, string, gossh.PublicKey) {
35 t.Helper()
36
37 client, db := coderdtest.NewWithDatabase(t, nil)
38 user := coderdtest.CreateFirstUser(t, client)
39
40 ctx, cancel := context.WithCancel(ctx)
41 defer t.Cleanup(cancel) // Defer so that cancel is the first cleanup.
42
43 // get user public key
44 keypair, err := client.GitSSHKey(ctx, codersdk.Me)
45 require.NoError(t, err)
46 //nolint:dogsled
47 pubkey, _, _, _, err := gossh.ParseAuthorizedKey([]byte(keypair.PublicKey))
48 require.NoError(t, err)
49
50 // setup template
51 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
52 OrganizationID: user.OrganizationID,
53 OwnerID: user.UserID,
54 }).WithAgent().Do()
55
56 // start workspace agent
57 agentClient := agentsdk.New(client.URL, agentsdk.WithFixedToken(r.AgentToken))
58 _ = agenttest.New(t, client.URL, r.AgentToken, func(o *agent.Options) {
59 o.Client = agentClient
60 })
61 _ = coderdtest.NewWorkspaceAgentWaiter(t, client, r.Workspace.ID).WithContext(ctx).Wait()
62 return agentClient, r.AgentToken, pubkey
63}
64
65func serveSSHForGitSSH(t *testing.T, handler func(ssh.Session), pubkeys ...gossh.PublicKey) *net.TCPAddr {
66 t.Helper()

Callers 1

TestGitSSHFunction · 0.85

Calls 14

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
WithFixedTokenFunction · 0.92
NewFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
WithAgentMethod · 0.80
WithContextMethod · 0.80
HelperMethod · 0.65
CleanupMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected