fix: resolve template name from working directory "." (#6822)

This commit is contained in:
Ammar Bandukwala
2023-03-27 22:58:20 +00:00
committed by GitHub
parent a2d3635207
commit f88f273cd6
3 changed files with 21 additions and 3 deletions
+6 -1
View File
@@ -85,8 +85,13 @@ func (pf *templateUploadFlags) templateName(args []string) (string, error) {
if len(args) > 0 {
return args[0], nil
}
// Have to take absPath to resolve "." and "..".
absPath, err := filepath.Abs(pf.directory)
if err != nil {
return "", err
}
// If no name is provided, use the directory name.
return filepath.Base(pf.directory), nil
return filepath.Base(absPath), nil
}
func (r *RootCmd) templatePush() *clibase.Cmd {
+12 -2
View File
@@ -155,8 +155,9 @@ func TestTemplatePush(t *testing.T) {
require.Equal(t, "example", templateVersions[1].Name)
})
// This test modifies the working directory.
//nolint:paralleltest
t.Run("UseWorkingDir", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
@@ -173,9 +174,18 @@ func TestTemplatePush(t *testing.T) {
r.Name = filepath.Base(source)
})
oldDir, err := os.Getwd()
require.NoError(t, err)
os.Chdir(source)
t.Cleanup(func() {
os.Chdir(oldDir)
})
// Don't pass the name of the template, it should use the
// directory of the source.
inv, root := clitest.New(t, "templates", "push", "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho))
inv, root := clitest.New(t, "templates", "push", "--test.provisioner", string(database.ProvisionerTypeEcho))
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)