MCPcopy Create free account
hub / github.com/coder/coder / TestAgents

Function TestAgents

coderd/prometheusmetrics/prometheusmetrics_test.go:527–639  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

525}
526
527func TestAgents(t *testing.T) {
528 t.Parallel()
529
530 // Build a sample workspace with test agent and fake application
531 client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
532 db := api.Database
533
534 user := coderdtest.CreateFirstUser(t, client)
535 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
536 Parse: echo.ParseComplete,
537 ProvisionPlan: echo.PlanComplete,
538 ProvisionGraph: []*proto.Response{{
539 Type: &proto.Response_Graph{
540 Graph: &proto.GraphComplete{
541 Resources: []*proto.Resource{{
542 Name: "example",
543 Type: "aws_instance",
544 Agents: []*proto.Agent{{
545 Id: uuid.NewString(),
546 Name: "testagent",
547 Directory: t.TempDir(),
548 Auth: &proto.Agent_Token{
549 Token: uuid.NewString(),
550 },
551 Apps: []*proto.App{
552 {
553 Slug: "fake-app",
554 DisplayName: "Fake application",
555 SharingLevel: proto.AppSharingLevel_OWNER,
556 // Hopefully this IP and port doesn't exist.
557 Url: "http://127.1.0.1:65535",
558 },
559 },
560 }},
561 }},
562 },
563 },
564 }},
565 })
566 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
567 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
568 workspace := coderdtest.CreateWorkspace(t, client, template.ID)
569 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
570
571 // given
572 derpMap, _ := tailnettest.RunDERPAndSTUN(t)
573 derpMapFn := func() *tailcfg.DERPMap {
574 return derpMap
575 }
576 coordinator := tailnet.NewCoordinator(testutil.Logger(t))
577 coordinatorPtr := atomic.Pointer[tailnet.Coordinator]{}
578 coordinatorPtr.Store(&coordinator)
579 agentInactiveDisconnectTimeout := 1 * time.Hour // don't need to focus on this value in tests
580 registry := prometheus.NewRegistry()
581
582 ctx, cancelFunc := context.WithCancel(context.Background())
583 defer cancelFunc()
584

Callers

nothing calls this directly

Calls 15

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
CreateWorkspaceFunction · 0.92
RunDERPAndSTUNFunction · 0.92
NewCoordinatorFunction · 0.92
LoggerFunction · 0.92
AgentsFunction · 0.92
TempDirMethod · 0.65

Tested by

no test coverage detected