setupAgentWithSecrets is like setupAgent but also injects user secrets into the agent's proto manifest. Separate from setupAgent because agentsdk.Manifest intentionally does not carry secrets; see the Manifest doc comment in codersdk/agentsdk.
(t testing.TB, metadata agentsdk.Manifest, secrets []agentsdk.WorkspaceSecret, ptyTimeout time.Duration, opts ...func(*agenttest.Client, *agent.Options))
| 3807 | // because agentsdk.Manifest intentionally does not carry secrets; see |
| 3808 | // the Manifest doc comment in codersdk/agentsdk. |
| 3809 | func setupAgentWithSecrets(t testing.TB, metadata agentsdk.Manifest, secrets []agentsdk.WorkspaceSecret, ptyTimeout time.Duration, opts ...func(*agenttest.Client, *agent.Options)) ( |
| 3810 | workspacesdk.AgentConn, |
| 3811 | *agenttest.Client, |
| 3812 | <-chan *proto.Stats, |
| 3813 | afero.Fs, |
| 3814 | agent.Agent, |
| 3815 | ) { |
| 3816 | logger := slogtest.Make(t, &slogtest.Options{ |
| 3817 | // Agent can drop errors when shutting down, and some, like the |
| 3818 | // fasthttplistener connection closed error, are unexported. |
| 3819 | IgnoreErrors: true, |
| 3820 | }).Leveled(slog.LevelDebug) |
| 3821 | if metadata.DERPMap == nil { |
| 3822 | metadata.DERPMap, _ = tailnettest.RunDERPAndSTUN(t) |
| 3823 | } |
| 3824 | if metadata.AgentID == uuid.Nil { |
| 3825 | metadata.AgentID = uuid.New() |
| 3826 | } |
| 3827 | if metadata.AgentName == "" { |
| 3828 | metadata.AgentName = "test-agent" |
| 3829 | } |
| 3830 | if metadata.WorkspaceName == "" { |
| 3831 | metadata.WorkspaceName = "test-workspace" |
| 3832 | } |
| 3833 | if metadata.OwnerName == "" { |
| 3834 | metadata.OwnerName = "test-user" |
| 3835 | } |
| 3836 | if metadata.WorkspaceID == uuid.Nil { |
| 3837 | metadata.WorkspaceID = uuid.New() |
| 3838 | } |
| 3839 | coordinator := tailnet.NewCoordinator(logger) |
| 3840 | t.Cleanup(func() { |
| 3841 | _ = coordinator.Close() |
| 3842 | }) |
| 3843 | statsCh := make(chan *proto.Stats, 50) |
| 3844 | fs := afero.NewMemMapFs() |
| 3845 | c := agenttest.NewClientWithSecrets(t, logger.Named("agenttest"), metadata.AgentID, metadata, secrets, statsCh, coordinator) |
| 3846 | t.Cleanup(c.Close) |
| 3847 | |
| 3848 | options := agent.Options{ |
| 3849 | Client: c, |
| 3850 | Filesystem: fs, |
| 3851 | Logger: logger.Named("agent"), |
| 3852 | ReconnectingPTYTimeout: ptyTimeout, |
| 3853 | EnvironmentVariables: map[string]string{}, |
| 3854 | } |
| 3855 | |
| 3856 | for _, opt := range opts { |
| 3857 | opt(c, &options) |
| 3858 | } |
| 3859 | |
| 3860 | agnt := agent.New(options) |
| 3861 | t.Cleanup(func() { |
| 3862 | _ = agnt.Close() |
| 3863 | }) |
| 3864 | conn, err := tailnet.NewConn(&tailnet.Options{ |
| 3865 | Addresses: []netip.Prefix{netip.PrefixFrom(tailnet.TailscaleServicePrefix.RandomAddr(), 128)}, |
| 3866 | DERPMap: metadata.DERPMap, |
no test coverage detected