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

Function TestProvisionerDaemonServe

enterprise/coderd/provisionerdaemons_test.go:39–708  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37)
38
39func TestProvisionerDaemonServe(t *testing.T) {
40 t.Parallel()
41 t.Run("OK", func(t *testing.T) {
42 t.Parallel()
43 client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
44 Features: license.Features{
45 codersdk.FeatureExternalProvisionerDaemons: 1,
46 },
47 }})
48 templateAdminClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleTemplateAdmin())
49 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
50 defer cancel()
51 daemonName := testutil.MustRandString(t, 63)
52 srv, err := templateAdminClient.ServeProvisionerDaemon(ctx, codersdk.ServeProvisionerDaemonRequest{
53 Name: daemonName,
54 Organization: user.OrganizationID,
55 Provisioners: []codersdk.ProvisionerType{
56 codersdk.ProvisionerTypeEcho,
57 },
58 Tags: map[string]string{},
59 })
60 require.NoError(t, err)
61 srv.DRPCConn().Close()
62
63 daemons, err := client.ProvisionerDaemons(ctx) //nolint:gocritic // Test assertion.
64 require.NoError(t, err)
65 if assert.Len(t, daemons, 1) {
66 assert.Equal(t, daemonName, daemons[0].Name)
67 assert.Equal(t, buildinfo.Version(), daemons[0].Version)
68 assert.Equal(t, proto.CurrentVersion.String(), daemons[0].APIVersion)
69 }
70 })
71
72 t.Run("NoVersion", func(t *testing.T) {
73 t.Parallel()
74 // In this test, we just send a HTTP request with minimal parameters to the provisionerdaemons
75 // endpoint. We do not pass the required machinery to start a websocket connection, so we expect a
76 // WebSocket protocol violation. This just means the pre-flight checks have passed though.
77
78 // Sending a HTTP request triggers an error log, which would otherwise fail the test.
79 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
80 client, user := coderdenttest.New(t, &coderdenttest.Options{
81 LicenseOptions: &coderdenttest.LicenseOptions{
82 Features: license.Features{
83 codersdk.FeatureExternalProvisionerDaemons: 1,
84 },
85 },
86 ProvisionerDaemonPSK: "provisionersftw",
87 Options: &coderdtest.Options{
88 Logger: &logger,
89 },
90 })
91 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
92 defer cancel()
93
94 // Formulate the correct URL for provisionerd server.
95 srvURL, err := client.URL.Parse(fmt.Sprintf("/api/v2/organizations/%s/provisionerdaemons/serve", user.OrganizationID))
96 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleTemplateAdminFunction · 0.92
MustRandStringFunction · 0.92
VersionFunction · 0.92
NewFunction · 0.92
ScopedRoleOrgAdminFunction · 0.92
TarFunction · 0.92
ProvisionGraphWithAgentFunction · 0.92

Tested by

no test coverage detected