@@ -2,6 +2,7 @@ package cli_test
2
2
3
3
import (
4
4
"context"
5
+ "path/filepath"
5
6
"testing"
6
7
7
8
"github.com/google/uuid"
@@ -113,6 +114,7 @@ func TestTemplateUpdate(t *testing.T) {
113
114
user := coderdtest .CreateFirstUser (t , client )
114
115
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
115
116
_ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
117
+
116
118
template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
117
119
118
120
// Test the cli command.
@@ -152,6 +154,59 @@ func TestTemplateUpdate(t *testing.T) {
152
154
assert .Len (t , templateVersions , 2 )
153
155
assert .NotEqual (t , template .ActiveVersionID , templateVersions [1 ].ID )
154
156
})
157
+
158
+ t .Run ("UseWorkingDir" , func (t * testing.T ) {
159
+ t .Parallel ()
160
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerD : true })
161
+ user := coderdtest .CreateFirstUser (t , client )
162
+ version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
163
+ _ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
164
+
165
+ // Test the cli command.
166
+ source := clitest .CreateTemplateVersionSource (t , & echo.Responses {
167
+ Parse : echo .ParseComplete ,
168
+ Provision : echo .ProvisionComplete ,
169
+ })
170
+
171
+ template := coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID ,
172
+ func (r * codersdk.CreateTemplateRequest ) {
173
+ r .Name = filepath .Base (source )
174
+ })
175
+
176
+ // Don't pass the name of the template, it should use the
177
+ // directory of the source.
178
+ cmd , root := clitest .New (t , "templates" , "update" , "--directory" , source , "--test.provisioner" , string (database .ProvisionerTypeEcho ))
179
+ clitest .SetupConfig (t , client , root )
180
+ pty := ptytest .New (t )
181
+ cmd .SetIn (pty .Input ())
182
+ cmd .SetOut (pty .Output ())
183
+
184
+ execDone := make (chan error )
185
+ go func () {
186
+ execDone <- cmd .Execute ()
187
+ }()
188
+
189
+ matches := []struct {
190
+ match string
191
+ write string
192
+ }{
193
+ {match : "Upload" , write : "yes" },
194
+ }
195
+ for _ , m := range matches {
196
+ pty .ExpectMatch (m .match )
197
+ pty .WriteLine (m .write )
198
+ }
199
+
200
+ require .NoError (t , <- execDone )
201
+
202
+ // Assert that the template version changed.
203
+ templateVersions , err := client .TemplateVersionsByTemplate (context .Background (), codersdk.TemplateVersionsByTemplateRequest {
204
+ TemplateID : template .ID ,
205
+ })
206
+ require .NoError (t , err )
207
+ assert .Len (t , templateVersions , 2 )
208
+ assert .NotEqual (t , template .ActiveVersionID , templateVersions [1 ].ID )
209
+ })
155
210
}
156
211
157
212
func latestTemplateVersion (t * testing.T , client * codersdk.Client , templateID uuid.UUID ) (codersdk.TemplateVersion , []codersdk.Parameter ) {
0 commit comments