|
5 | 5 | "context"
|
6 | 6 | "encoding/json"
|
7 | 7 | "fmt"
|
8 |
| - "strings" |
9 | 8 | "testing"
|
10 | 9 | "time"
|
11 | 10 |
|
@@ -41,43 +40,6 @@ func TestStartCommand_Execute(t *testing.T) {
|
41 | 40 | s.AddKnownType(kind, &spec.Meta{})
|
42 | 41 | s.AddCodec(kind, codec)
|
43 | 42 |
|
44 |
| - t.Run(flagDebug, func(t *testing.T) { |
45 |
| - ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
46 |
| - defer cancel() |
47 |
| - |
48 |
| - output := new(bytes.Buffer) |
49 |
| - |
50 |
| - cmd := NewStartCommand(StartConfig{ |
51 |
| - Scheme: s, |
52 |
| - Hook: h, |
53 |
| - FS: fs, |
54 |
| - ChartStore: chartStore, |
55 |
| - SpecStore: specStore, |
56 |
| - SecretStore: secretStore, |
57 |
| - }) |
58 |
| - cmd.SetOut(output) |
59 |
| - cmd.SetErr(output) |
60 |
| - cmd.SetContext(ctx) |
61 |
| - |
62 |
| - cmd.SetArgs([]string{fmt.Sprintf("--%s", flagDebug)}) |
63 |
| - |
64 |
| - go func() { |
65 |
| - _ = cmd.Execute() |
66 |
| - }() |
67 |
| - |
68 |
| - for { |
69 |
| - select { |
70 |
| - case <-ctx.Done(): |
71 |
| - assert.Fail(t, ctx.Err().Error()) |
72 |
| - return |
73 |
| - default: |
74 |
| - if strings.Contains(output.String(), "debug") { |
75 |
| - return |
76 |
| - } |
77 |
| - } |
78 |
| - } |
79 |
| - }) |
80 |
| - |
81 | 43 | t.Run(flagFromCharts, func(t *testing.T) {
|
82 | 44 | ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
83 | 45 | defer cancel()
|
@@ -111,20 +73,17 @@ func TestStartCommand_Execute(t *testing.T) {
|
111 | 73 |
|
112 | 74 | cmd.SetArgs([]string{fmt.Sprintf("--%s", flagFromCharts), filename})
|
113 | 75 |
|
| 76 | + chartStream, _ := chartStore.Watch(ctx) |
| 77 | + defer chartStream.Close() |
| 78 | + |
114 | 79 | go func() {
|
115 | 80 | _ = cmd.Execute()
|
116 | 81 | }()
|
117 | 82 |
|
118 |
| - for { |
119 |
| - select { |
120 |
| - case <-ctx.Done(): |
121 |
| - assert.Fail(t, ctx.Err().Error()) |
122 |
| - return |
123 |
| - default: |
124 |
| - if r, _ := chartStore.Load(ctx, chrt); len(r) > 0 { |
125 |
| - return |
126 |
| - } |
127 |
| - } |
| 83 | + select { |
| 84 | + case <-chartStream.Next(): |
| 85 | + case <-ctx.Done(): |
| 86 | + assert.Fail(t, ctx.Err().Error()) |
128 | 87 | }
|
129 | 88 | })
|
130 | 89 |
|
@@ -161,20 +120,17 @@ func TestStartCommand_Execute(t *testing.T) {
|
161 | 120 |
|
162 | 121 | cmd.SetArgs([]string{fmt.Sprintf("--%s", flagFromNodes), filename})
|
163 | 122 |
|
| 123 | + specStream, _ := specStore.Watch(ctx) |
| 124 | + defer specStream.Close() |
| 125 | + |
164 | 126 | go func() {
|
165 | 127 | _ = cmd.Execute()
|
166 | 128 | }()
|
167 | 129 |
|
168 |
| - for { |
169 |
| - select { |
170 |
| - case <-ctx.Done(): |
171 |
| - assert.Fail(t, ctx.Err().Error()) |
172 |
| - return |
173 |
| - default: |
174 |
| - if r, _ := specStore.Load(ctx, meta); len(r) > 0 { |
175 |
| - return |
176 |
| - } |
177 |
| - } |
| 130 | + select { |
| 131 | + case <-specStream.Next(): |
| 132 | + case <-ctx.Done(): |
| 133 | + assert.Fail(t, ctx.Err().Error()) |
178 | 134 | }
|
179 | 135 | })
|
180 | 136 |
|
@@ -211,18 +167,17 @@ func TestStartCommand_Execute(t *testing.T) {
|
211 | 167 |
|
212 | 168 | cmd.SetArgs([]string{fmt.Sprintf("--%s", flagFromSecrets), filename})
|
213 | 169 |
|
| 170 | + secretStream, _ := secretStore.Watch(ctx) |
| 171 | + defer secretStream.Close() |
| 172 | + |
214 | 173 | go func() {
|
215 | 174 | _ = cmd.Execute()
|
216 | 175 | }()
|
217 | 176 |
|
218 | 177 | select {
|
| 178 | + case <-secretStream.Next(): |
219 | 179 | case <-ctx.Done():
|
220 | 180 | assert.Fail(t, ctx.Err().Error())
|
221 |
| - return |
222 |
| - default: |
223 |
| - if r, _ := secretStore.Load(ctx, scrt); len(r) > 0 { |
224 |
| - return |
225 |
| - } |
226 | 181 | }
|
227 | 182 | })
|
228 | 183 | }
|
0 commit comments