@@ -538,14 +538,18 @@ func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *c
538538 return client , provisionerCloser , coderAPI
539539}
540540
541- // provisionerdCloser wraps a provisioner daemon as an io.Closer that can be called multiple times
542- type provisionerdCloser struct {
541+ // ProvisionerdCloser wraps a provisioner daemon as an io.Closer that can be called multiple times
542+ type ProvisionerdCloser struct {
543543 mu sync.Mutex
544544 closed bool
545545 d * provisionerd.Server
546546}
547547
548- func (c * provisionerdCloser ) Close () error {
548+ func NewProvisionerDaemonCloser (d * provisionerd.Server ) * ProvisionerdCloser {
549+ return & ProvisionerdCloser {d : d }
550+ }
551+
552+ func (c * ProvisionerdCloser ) Close () error {
549553 c .mu .Lock ()
550554 defer c .mu .Unlock ()
551555 if c .closed {
@@ -605,71 +609,10 @@ func NewTaggedProvisionerDaemon(t testing.TB, coderAPI *coderd.API, name string,
605609 string (database .ProvisionerTypeEcho ): sdkproto .NewDRPCProvisionerClient (echoClient ),
606610 },
607611 })
608- closer := & provisionerdCloser {d : daemon }
609- t .Cleanup (func () {
610- _ = closer .Close ()
611- })
612- return closer
613- }
614-
615- func NewExternalProvisionerDaemon (t testing.TB , client * codersdk.Client , org uuid.UUID , tags map [string ]string ) io.Closer {
616- t .Helper ()
617-
618- // Without this check, the provisioner will silently fail.
619- entitlements , err := client .Entitlements (context .Background ())
620- if err != nil {
621- // AGPL instances will throw this error. They cannot use external
622- // provisioners.
623- t .Errorf ("external provisioners requires a license with entitlements. The client failed to fetch the entitlements, is this an enterprise instance of coderd?" )
624- t .FailNow ()
625- return nil
626- }
627-
628- feature := entitlements .Features [codersdk .FeatureExternalProvisionerDaemons ]
629- if ! feature .Enabled || feature .Entitlement != codersdk .EntitlementEntitled {
630- require .NoError (t , xerrors .Errorf ("external provisioner daemons require an entitled license" ))
631- return nil
632- }
633-
634- echoClient , echoServer := drpc .MemTransportPipe ()
635- ctx , cancelFunc := context .WithCancel (context .Background ())
636- serveDone := make (chan struct {})
637- t .Cleanup (func () {
638- _ = echoClient .Close ()
639- _ = echoServer .Close ()
640- cancelFunc ()
641- <- serveDone
642- })
643- go func () {
644- defer close (serveDone )
645- err := echo .Serve (ctx , & provisionersdk.ServeOptions {
646- Listener : echoServer ,
647- WorkDirectory : t .TempDir (),
648- })
649- assert .NoError (t , err )
650- }()
651-
652- daemon := provisionerd .New (func (ctx context.Context ) (provisionerdproto.DRPCProvisionerDaemonClient , error ) {
653- return client .ServeProvisionerDaemon (ctx , codersdk.ServeProvisionerDaemonRequest {
654- ID : uuid .New (),
655- Name : t .Name (),
656- Organization : org ,
657- Provisioners : []codersdk.ProvisionerType {codersdk .ProvisionerTypeEcho },
658- Tags : tags ,
659- })
660- }, & provisionerd.Options {
661- Logger : slogtest .Make (t , nil ).Named ("provisionerd" ).Leveled (slog .LevelDebug ),
662- UpdateInterval : 250 * time .Millisecond ,
663- ForceCancelInterval : 5 * time .Second ,
664- Connector : provisionerd.LocalProvisioners {
665- string (database .ProvisionerTypeEcho ): sdkproto .NewDRPCProvisionerClient (echoClient ),
666- },
667- })
668- closer := & provisionerdCloser {d : daemon }
612+ closer := NewProvisionerDaemonCloser (daemon )
669613 t .Cleanup (func () {
670614 _ = closer .Close ()
671615 })
672-
673616 return closer
674617}
675618
@@ -841,37 +784,6 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
841784 return other , user
842785}
843786
844- type CreateOrganizationOptions struct {
845- // IncludeProvisionerDaemon will spin up an external provisioner for the organization.
846- // This requires enterprise and the feature 'codersdk.FeatureExternalProvisionerDaemons'
847- IncludeProvisionerDaemon bool
848- }
849-
850- func CreateOrganization (t * testing.T , client * codersdk.Client , opts CreateOrganizationOptions , mutators ... func (* codersdk.CreateOrganizationRequest )) codersdk.Organization {
851- ctx := testutil .Context (t , testutil .WaitMedium )
852- req := codersdk.CreateOrganizationRequest {
853- Name : strings .ReplaceAll (strings .ToLower (namesgenerator .GetRandomName (0 )), "_" , "-" ),
854- DisplayName : namesgenerator .GetRandomName (1 ),
855- Description : namesgenerator .GetRandomName (1 ),
856- Icon : "" ,
857- }
858- for _ , mutator := range mutators {
859- mutator (& req )
860- }
861-
862- org , err := client .CreateOrganization (ctx , req )
863- require .NoError (t , err )
864-
865- if opts .IncludeProvisionerDaemon {
866- closer := NewExternalProvisionerDaemon (t , client , org .ID , map [string ]string {})
867- t .Cleanup (func () {
868- _ = closer .Close ()
869- })
870- }
871-
872- return org
873- }
874-
875787// CreateTemplateVersion creates a template import provisioner job
876788// with the responses provided. It uses the "echo" provisioner for compatibility
877789// with testing.
0 commit comments