@@ -79,6 +79,63 @@ func TestCreate(t *testing.T) {
7979 }
8080 })
8181
82+ t .Run ("CreateForOtherUser" , func (t * testing.T ) {
83+ t .Parallel ()
84+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
85+ owner := coderdtest .CreateFirstUser (t , client )
86+ version := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , & echo.Responses {
87+ Parse : echo .ParseComplete ,
88+ ProvisionApply : provisionCompleteWithAgent ,
89+ ProvisionPlan : provisionCompleteWithAgent ,
90+ })
91+ coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
92+ template := coderdtest .CreateTemplate (t , client , owner .OrganizationID , version .ID )
93+ _ , user := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
94+ args := []string {
95+ "create" ,
96+ user .Username + "/their-workspace" ,
97+ "--template" , template .Name ,
98+ "--start-at" , "9:30AM Mon-Fri US/Central" ,
99+ "--stop-after" , "8h" ,
100+ }
101+
102+ inv , root := clitest .New (t , args ... )
103+ clitest .SetupConfig (t , client , root )
104+ doneChan := make (chan struct {})
105+ pty := ptytest .New (t ).Attach (inv )
106+ go func () {
107+ defer close (doneChan )
108+ err := inv .Run ()
109+ assert .NoError (t , err )
110+ }()
111+ matches := []struct {
112+ match string
113+ write string
114+ }{
115+ {match : "compute.main" },
116+ {match : "smith (linux, i386)" },
117+ {match : "Confirm create" , write : "yes" },
118+ }
119+ for _ , m := range matches {
120+ pty .ExpectMatch (m .match )
121+ if len (m .write ) > 0 {
122+ pty .WriteLine (m .write )
123+ }
124+ }
125+ <- doneChan
126+
127+ ws , err := client .WorkspaceByOwnerAndName (context .Background (), user .Username , "their-workspace" , codersdk.WorkspaceOptions {})
128+ if assert .NoError (t , err , "expected workspace to be created" ) {
129+ assert .Equal (t , ws .TemplateName , template .Name )
130+ if assert .NotNil (t , ws .AutostartSchedule ) {
131+ assert .Equal (t , * ws .AutostartSchedule , "CRON_TZ=US/Central 30 9 * * Mon-Fri" )
132+ }
133+ if assert .NotNil (t , ws .TTLMillis ) {
134+ assert .Equal (t , * ws .TTLMillis , 8 * time .Hour .Milliseconds ())
135+ }
136+ }
137+ })
138+
82139 t .Run ("InheritStopAfterFromTemplate" , func (t * testing.T ) {
83140 t .Parallel ()
84141 client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
0 commit comments