Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf88f273

Browse files
authored
fix: resolve template name from working directory "." (#6822)
1 parenta2d3635 commitf88f273

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

‎cli/templatepush.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ func (pf *templateUploadFlags) templateName(args []string) (string, error) {
8585
iflen(args)>0 {
8686
returnargs[0],nil
8787
}
88+
// Have to take absPath to resolve "." and "..".
89+
absPath,err:=filepath.Abs(pf.directory)
90+
iferr!=nil {
91+
return"",err
92+
}
8893
// If no name is provided, use the directory name.
89-
returnfilepath.Base(pf.directory),nil
94+
returnfilepath.Base(absPath),nil
9095
}
9196

9297
func (r*RootCmd)templatePush()*clibase.Cmd {

‎cli/templatepush_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ func TestTemplatePush(t *testing.T) {
155155
require.Equal(t,"example",templateVersions[1].Name)
156156
})
157157

158+
// This test modifies the working directory.
159+
//nolint:paralleltest
158160
t.Run("UseWorkingDir",func(t*testing.T) {
159-
t.Parallel()
160161
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
161162
user:=coderdtest.CreateFirstUser(t,client)
162163
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,nil)
@@ -173,9 +174,18 @@ func TestTemplatePush(t *testing.T) {
173174
r.Name=filepath.Base(source)
174175
})
175176

177+
oldDir,err:=os.Getwd()
178+
require.NoError(t,err)
179+
180+
os.Chdir(source)
181+
182+
t.Cleanup(func() {
183+
os.Chdir(oldDir)
184+
})
185+
176186
// Don't pass the name of the template, it should use the
177187
// directory of the source.
178-
inv,root:=clitest.New(t,"templates","push","--directory",source,"--test.provisioner",string(database.ProvisionerTypeEcho))
188+
inv,root:=clitest.New(t,"templates","push","--test.provisioner",string(database.ProvisionerTypeEcho))
179189
clitest.SetupConfig(t,client,root)
180190
pty:=ptytest.New(t).Attach(inv)
181191

‎codersdk/organizations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ func (c *Client) TemplatesByOrganization(ctx context.Context, organizationID uui
221221

222222
// TemplateByName finds a template inside the organization provided with a case-insensitive name.
223223
func (c*Client)TemplateByName(ctx context.Context,organizationID uuid.UUID,namestring) (Template,error) {
224+
ifname=="" {
225+
returnTemplate{},xerrors.Errorf("template name cannot be empty")
226+
}
224227
res,err:=c.Request(ctx,http.MethodGet,
225228
fmt.Sprintf("/api/v2/organizations/%s/templates/%s",organizationID.String(),name),
226229
nil,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp