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

Commit32ee661

Browse files
committed
fix(cli/templatepush): only implicitly read from stdin if the directory flag is unset
1 parent6606d8b commit32ee661

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

‎cli/templatepush.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ func (pf *templateUploadFlags) stdin(inv *serpent.Invocation) (out bool) {
309309
inv.Logger.Info(inv.Context(),"uploading tar read from stdin")
310310
}
311311
}()
312-
// We let the directory override our isTTY check
313-
returnpf.directory=="-"|| (!isTTYIn(inv)&&pf.directory==".")
312+
// We read a tar from stdin if the directory is "-" or if we're not in a
313+
// TTY and the directory flag is unset.
314+
returnpf.directory=="-"|| (!isTTYIn(inv)&&!inv.ParsedFlags().Lookup("directory").Changed)
314315
}
315316

316317
func (pf*templateUploadFlags)upload(inv*serpent.Invocation,client*codersdk.Client) (*codersdk.UploadResponse,error) {

‎cli/templatepush_test.go‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ func TestTemplatePush(t *testing.T) {
339339
inv,root:=clitest.New(t,"templates","push",
340340
"--test.provisioner",string(database.ProvisionerTypeEcho),
341341
"--test.workdir",source,
342+
"--force-tty",
342343
)
343344
clitest.SetupConfig(t,templateAdmin,root)
344345
pty:=ptytest.New(t).Attach(inv)
@@ -1075,6 +1076,45 @@ func TestTemplatePush(t *testing.T) {
10751076
require.Equal(t,templateName,template.Name)
10761077
require.NotEqual(t,uuid.Nil,template.ActiveVersionID)
10771078
})
1079+
1080+
t.Run("NoStdinWithCurrentDirectory",func(t*testing.T) {
1081+
t.Parallel()
1082+
client:=coderdtest.New(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
1083+
owner:=coderdtest.CreateFirstUser(t,client)
1084+
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
1085+
version:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil)
1086+
_=coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID)
1087+
1088+
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,version.ID)
1089+
1090+
source:=clitest.CreateTemplateVersionSource(t,&echo.Responses{
1091+
Parse:echo.ParseComplete,
1092+
ProvisionApply:echo.ApplyComplete,
1093+
})
1094+
1095+
inv,root:=clitest.New(t,"templates","push",template.Name,
1096+
"--directory",".",
1097+
"--test.provisioner",string(database.ProvisionerTypeEcho),
1098+
"--test.workdir",source,
1099+
"--name","example",
1100+
"--yes")
1101+
clitest.SetupConfig(t,templateAdmin,root)
1102+
1103+
inv.Stdin=strings.NewReader("invalid tar content that would cause failure")
1104+
1105+
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitMedium)
1106+
defercancel()
1107+
1108+
err:=inv.WithContext(ctx).Run()
1109+
require.NoError(t,err,"Should succeed without reading from stdin")
1110+
1111+
templateVersions,err:=client.TemplateVersionsByTemplate(ctx, codersdk.TemplateVersionsByTemplateRequest{
1112+
TemplateID:template.ID,
1113+
})
1114+
require.NoError(t,err)
1115+
require.Len(t,templateVersions,2)
1116+
require.Equal(t,"example",templateVersions[1].Name)
1117+
})
10781118
})
10791119
}
10801120

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp