@@ -13,93 +13,9 @@ import (
1313 rendererMock "github.com/tarantool/sdvg/internal/generator/cli/render/mock"
1414)
1515
16- func TestConfirmTTY (t * testing.T ) {
17- input := bytes.Buffer {}
18- output := bytes.Buffer {}
19-
20- confirm := BuildConfirmTTY (& input , & output )
21-
22- testCases := []struct {
23- name string
24- ctx context.Context
25- question string
26- input string
27- expected bool
28- expectedErr error
29- }{
30- {
31- name : "Y" ,
32- question : "question" ,
33- input : "Y" ,
34- expected : true ,
35- },
36- {
37- name : "y" ,
38- question : "question" ,
39- input : "y" ,
40- expected : true ,
41- },
42- {
43- name : "yes" ,
44- question : "question" ,
45- input : "yes" ,
46- expectedErr : ErrPromptFailed ,
47- },
48- {
49- name : "N" ,
50- question : "question" ,
51- input : "N" ,
52- expected : false ,
53- },
54- {
55- name : "n" ,
56- question : "question" ,
57- input : "n" ,
58- expected : false ,
59- },
60- {
61- name : "no" ,
62- question : "question" ,
63- input : "no" ,
64- expectedErr : ErrPromptFailed ,
65- },
66- {
67- name : "Context canceled" ,
68- expectedErr : context .Canceled ,
69- },
70- }
71-
72- for _ , tc := range testCases {
73- t .Run (tc .name , func (t * testing.T ) {
74- ctx := context .Background ()
75-
76- if errors .Is (tc .expectedErr , context .Canceled ) {
77- var cancel context.CancelFunc
78-
79- ctx , cancel = context .WithCancel (ctx )
80- cancel ()
81- }
82-
83- input .WriteString (tc .input + "\n " )
84-
85- res , err := confirm (ctx , tc .question )
86- require .True (t , errors .Is (err , tc .expectedErr ), fmt .Sprintf ("expected: %v, got: %v" , tc .expectedErr , err ))
87-
88- require .Equal (t , tc .expected , res )
89-
90- input .Reset ()
91- output .Reset ()
92- })
93- }
94- }
95-
9616var errMockTest = errors .New ("mock test error" )
9717
9818func TestConfirmNoTTY (t * testing.T ) {
99- output := bytes.Buffer {}
100-
101- isUpdatePaused := atomic.Bool {}
102-
10319 testCases := []struct {
10420 name string
10521 ctx context.Context
@@ -192,9 +108,11 @@ func TestConfirmNoTTY(t *testing.T) {
192108 for _ , tc := range testCases {
193109 t .Run (tc .name , func (t * testing.T ) {
194110 r := rendererMock .NewRenderer (t )
195-
196111 tc .mockFunc (r )
197112
113+ output := bytes.Buffer {}
114+ isUpdatePaused := atomic.Bool {}
115+
198116 confirm := BuildConfirmNoTTY (r , & output , & isUpdatePaused )
199117
200118 ctx := context .Background ()
@@ -210,8 +128,6 @@ func TestConfirmNoTTY(t *testing.T) {
210128 require .True (t , errors .Is (err , tc .expectedErr ), fmt .Sprintf ("expected: %v, got: %v" , tc .expectedErr , err ))
211129
212130 require .Equal (t , tc .expected , res )
213-
214- output .Reset ()
215131 })
216132 }
217133}
0 commit comments