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

Commit0049603

Browse files
committed
fix: wait for prompt on rich param CLI test
1 parentf0a4de5 commit0049603

File tree

2 files changed

+72
-47
lines changed

2 files changed

+72
-47
lines changed

‎cli/update_test.go

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
323323
err:=inv.Run()
324324
require.NoError(t,err)
325325

326+
ctx:=testutil.Context(t,testutil.WaitLong)
326327
inv,root=clitest.New(t,"update","my-workspace","--always-prompt")
328+
inv=inv.WithContext(ctx)
327329
clitest.SetupConfig(t,member,root)
328330
doneChan:=make(chanstruct{})
329331
pty:=ptytest.New(t).Attach(inv)
@@ -333,18 +335,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
333335
assert.NoError(t,err)
334336
}()
335337

336-
matches:= []string{
337-
stringParameterName,"$$",
338-
"does not match","",
339-
"Enter a value","abc",
340-
}
341-
fori:=0;i<len(matches);i+=2 {
342-
match:=matches[i]
343-
value:=matches[i+1]
344-
pty.ExpectMatch(match)
345-
pty.WriteLine(value)
346-
}
347-
<-doneChan
338+
pty.ExpectMatch(stringParameterName)
339+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
340+
pty.WriteLine("$$")
341+
pty.ExpectMatch("does not match")
342+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
343+
pty.WriteLine("")
344+
pty.ExpectMatch("does not match")
345+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
346+
pty.WriteLine("abc")
347+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
348348
})
349349

350350
t.Run("ValidateNumber",func(t*testing.T) {
@@ -369,7 +369,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
369369
err:=inv.Run()
370370
require.NoError(t,err)
371371

372+
ctx:=testutil.Context(t,testutil.WaitLong)
372373
inv,root=clitest.New(t,"update","my-workspace","--always-prompt")
374+
inv.WithContext(ctx)
373375
clitest.SetupConfig(t,member,root)
374376
doneChan:=make(chanstruct{})
375377
pty:=ptytest.New(t).Attach(inv)
@@ -379,21 +381,30 @@ func TestUpdateValidateRichParameters(t *testing.T) {
379381
assert.NoError(t,err)
380382
}()
381383

382-
matches:= []string{
383-
numberParameterName,"12",
384-
"is more than the maximum","",
385-
"Enter a value","8",
386-
}
387-
fori:=0;i<len(matches);i+=2 {
388-
match:=matches[i]
389-
value:=matches[i+1]
390-
pty.ExpectMatch(match)
391-
392-
ifvalue!="" {
393-
pty.WriteLine(value)
394-
}
395-
}
396-
<-doneChan
384+
//matches := []string{
385+
//numberParameterName, "12",
386+
//"is more than the maximum", "",
387+
//"Enter a value", "8",
388+
//}
389+
//for i := 0; i < len(matches); i += 2 {
390+
//match := matches[i]
391+
//value := matches[i+1]
392+
//pty.ExpectMatch(match)
393+
//
394+
//if value != "" {
395+
//pty.WriteLine(value)
396+
//}
397+
//}
398+
pty.ExpectMatch(numberParameterName)
399+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
400+
pty.WriteLine("12")
401+
pty.ExpectMatch("is more than the maximum")
402+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
403+
pty.WriteLine("")
404+
pty.ExpectMatch("is not a number")
405+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
406+
pty.WriteLine("8")
407+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
397408
})
398409

399410
t.Run("ValidateBool",func(t*testing.T) {
@@ -418,7 +429,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
418429
err:=inv.Run()
419430
require.NoError(t,err)
420431

432+
ctx:=testutil.Context(t,testutil.WaitLong)
421433
inv,root=clitest.New(t,"update","my-workspace","--always-prompt")
434+
inv=inv.WithContext(ctx)
422435
clitest.SetupConfig(t,member,root)
423436
doneChan:=make(chanstruct{})
424437
pty:=ptytest.New(t).Attach(inv)
@@ -428,18 +441,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
428441
assert.NoError(t,err)
429442
}()
430443

431-
matches:= []string{
432-
boolParameterName,"cat",
433-
"boolean value can be either","",
434-
"Enter a value","false",
435-
}
436-
fori:=0;i<len(matches);i+=2 {
437-
match:=matches[i]
438-
value:=matches[i+1]
439-
pty.ExpectMatch(match)
440-
pty.WriteLine(value)
441-
}
442-
<-doneChan
444+
pty.ExpectMatch(boolParameterName)
445+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
446+
pty.WriteLine("cat")
447+
pty.ExpectMatch("boolean value can be either\"true\" or\"false\"")
448+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
449+
pty.WriteLine("")
450+
pty.ExpectMatch("boolean value can be either\"true\" or\"false\"")
451+
pty.ExpectMatch("> Enter a value (default:\"\"): ")
452+
pty.WriteLine("false")
453+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
443454
})
444455

445456
t.Run("RequiredParameterAdded",func(t*testing.T) {
@@ -485,7 +496,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
485496
require.NoError(t,err)
486497

487498
// Update the workspace
499+
ctx:=testutil.Context(t,testutil.WaitLong)
488500
inv,root=clitest.New(t,"update","my-workspace")
501+
inv.WithContext(ctx)
489502
clitest.SetupConfig(t,member,root)
490503
doneChan:=make(chanstruct{})
491504
pty:=ptytest.New(t).Attach(inv)
@@ -508,7 +521,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
508521
pty.WriteLine(value)
509522
}
510523
}
511-
<-doneChan
524+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
512525
})
513526

514527
t.Run("OptionalParameterAdded",func(t*testing.T) {
@@ -555,7 +568,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
555568
require.NoError(t,err)
556569

557570
// Update the workspace
571+
ctx:=testutil.Context(t,testutil.WaitLong)
558572
inv,root=clitest.New(t,"update","my-workspace")
573+
inv.WithContext(ctx)
559574
clitest.SetupConfig(t,member,root)
560575
doneChan:=make(chanstruct{})
561576
pty:=ptytest.New(t).Attach(inv)
@@ -566,7 +581,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
566581
}()
567582

568583
pty.ExpectMatch("Planning workspace...")
569-
<-doneChan
584+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
570585
})
571586

572587
t.Run("ParameterOptionChanged",func(t*testing.T) {
@@ -612,7 +627,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
612627
require.NoError(t,err)
613628

614629
// Update the workspace
630+
ctx:=testutil.Context(t,testutil.WaitLong)
615631
inv,root=clitest.New(t,"update","my-workspace")
632+
inv.WithContext(ctx)
616633
clitest.SetupConfig(t,member,root)
617634
doneChan:=make(chanstruct{})
618635
pty:=ptytest.New(t).Attach(inv)
@@ -636,7 +653,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
636653
}
637654
}
638655

639-
<-doneChan
656+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
640657
})
641658

642659
t.Run("ParameterOptionDisappeared",func(t*testing.T) {
@@ -683,7 +700,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
683700
require.NoError(t,err)
684701

685702
// Update the workspace
703+
ctx:=testutil.Context(t,testutil.WaitLong)
686704
inv,root=clitest.New(t,"update","my-workspace")
705+
inv.WithContext(ctx)
687706
clitest.SetupConfig(t,member,root)
688707
doneChan:=make(chanstruct{})
689708
pty:=ptytest.New(t).Attach(inv)
@@ -707,7 +726,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
707726
}
708727
}
709728

710-
<-doneChan
729+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
711730
})
712731

713732
t.Run("ParameterOptionFailsMonotonicValidation",func(t*testing.T) {
@@ -739,7 +758,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
739758
require.NoError(t,err)
740759

741760
// Update the workspace
761+
ctx:=testutil.Context(t,testutil.WaitLong)
742762
inv,root=clitest.New(t,"update","my-workspace","--always-prompt=true")
763+
inv.WithContext(ctx)
743764
clitest.SetupConfig(t,member,root)
744765

745766
doneChan:=make(chanstruct{})
@@ -762,7 +783,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
762783
pty.ExpectMatch(match)
763784
}
764785

765-
<-doneChan
786+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
766787
})
767788

768789
t.Run("ImmutableRequiredParameterExists_MutableRequiredParameterAdded",func(t*testing.T) {
@@ -804,7 +825,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
804825
require.NoError(t,err)
805826

806827
// Update the workspace
828+
ctx:=testutil.Context(t,testutil.WaitLong)
807829
inv,root=clitest.New(t,"update","my-workspace")
830+
inv.WithContext(ctx)
808831
clitest.SetupConfig(t,member,root)
809832
doneChan:=make(chanstruct{})
810833
pty:=ptytest.New(t).Attach(inv)
@@ -828,7 +851,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
828851
}
829852
}
830853

831-
<-doneChan
854+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
832855
})
833856

834857
t.Run("MutableRequiredParameterExists_ImmutableRequiredParameterAdded",func(t*testing.T) {
@@ -874,7 +897,9 @@ func TestUpdateValidateRichParameters(t *testing.T) {
874897
require.NoError(t,err)
875898

876899
// Update the workspace
900+
ctx:=testutil.Context(t,testutil.WaitLong)
877901
inv,root=clitest.New(t,"update","my-workspace")
902+
inv.WithContext(ctx)
878903
clitest.SetupConfig(t,member,root)
879904
doneChan:=make(chanstruct{})
880905
pty:=ptytest.New(t).Attach(inv)
@@ -898,6 +923,6 @@ func TestUpdateValidateRichParameters(t *testing.T) {
898923
}
899924
}
900925

901-
<-doneChan
926+
_=testutil.RequireRecvCtx(ctx,t,doneChan)
902927
})
903928
}

‎pty/ptytest/ptytest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (e *outExpecter) expectMatcherFunc(ctx context.Context, str string, fn func
198198
e.fatalf("read error","%v (wanted %q; got %q)",err,str,buffer.String())
199199
return""
200200
}
201-
e.logf("matched %q = %q",str,stripansi.Strip(buffer.String()))
201+
e.logf("matched %q = %q",str,buffer.String())
202202
returnbuffer.String()
203203
}
204204

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp