Skip to content

Commit 8d2dffe

Browse files
authored
Fix defects where done is called before the command's Run method is invoked (#36852)
* Fix defects where `done` is called before the command's `Run` method is invoked We're attempting to reading output from a command that hasn't been executed yet! * Another one
1 parent 36fb64f commit 8d2dffe

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

internal/command/test_test.go

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,9 +1494,8 @@ func TestTest_ModuleDependencies(t *testing.T) {
14941494
Meta: meta,
14951495
}
14961496

1497-
output := done(t)
1498-
14991497
if code := init.Run(nil); code != 0 {
1498+
output := done(t)
15001499
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
15011500
}
15021501

@@ -1510,7 +1509,7 @@ func TestTest_ModuleDependencies(t *testing.T) {
15101509
}
15111510

15121511
code := command.Run(nil)
1513-
output = done(t)
1512+
output := done(t)
15141513

15151514
printedOutput := false
15161515

@@ -1812,9 +1811,8 @@ can remove the provider configuration again.
18121811
Meta: meta,
18131812
}
18141813

1815-
output := done(t)
1816-
18171814
if code := init.Run(nil); code != 0 {
1815+
output := done(t)
18181816
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
18191817
}
18201818

@@ -1828,7 +1826,7 @@ can remove the provider configuration again.
18281826
}
18291827

18301828
code := c.Run([]string{"-no-color"})
1831-
output = done(t)
1829+
output := done(t)
18321830

18331831
if code != 1 {
18341832
t.Errorf("expected status code 1 but got %d", code)
@@ -1935,9 +1933,8 @@ func TestTest_StatePropagation(t *testing.T) {
19351933
Meta: meta,
19361934
}
19371935

1938-
output := done(t)
1939-
19401936
if code := init.Run(nil); code != 0 {
1937+
output := done(t)
19411938
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
19421939
}
19431940

@@ -1951,7 +1948,7 @@ func TestTest_StatePropagation(t *testing.T) {
19511948
}
19521949

19531950
code := c.Run([]string{"-verbose", "-no-color"})
1954-
output = done(t)
1951+
output := done(t)
19551952

19561953
if code != 0 {
19571954
t.Errorf("expected status code 0 but got %d", code)
@@ -2075,9 +2072,8 @@ func TestTest_OnlyExternalModules(t *testing.T) {
20752072
Meta: meta,
20762073
}
20772074

2078-
output := done(t)
2079-
20802075
if code := init.Run(nil); code != 0 {
2076+
output := done(t)
20812077
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
20822078
}
20832079

@@ -2091,7 +2087,7 @@ func TestTest_OnlyExternalModules(t *testing.T) {
20912087
}
20922088

20932089
code := c.Run([]string{"-no-color"})
2094-
output = done(t)
2090+
output := done(t)
20952091

20962092
if code != 0 {
20972093
t.Errorf("expected status code 0 but got %d", code)
@@ -2211,9 +2207,8 @@ func TestTest_InvalidWarningsInCleanup(t *testing.T) {
22112207
Meta: meta,
22122208
}
22132209

2214-
output := done(t)
2215-
22162210
if code := init.Run(nil); code != 0 {
2211+
output := done(t)
22172212
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
22182213
}
22192214

@@ -2227,7 +2222,7 @@ func TestTest_InvalidWarningsInCleanup(t *testing.T) {
22272222
}
22282223

22292224
code := c.Run([]string{"-no-color"})
2230-
output = done(t)
2225+
output := done(t)
22312226

22322227
if code != 0 {
22332228
t.Errorf("expected status code 0 but got %d", code)
@@ -2810,9 +2805,8 @@ func TestTest_SensitiveInputValues(t *testing.T) {
28102805
Meta: meta,
28112806
}
28122807

2813-
output := done(t)
2814-
28152808
if code := init.Run(nil); code != 0 {
2809+
output := done(t)
28162810
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
28172811
}
28182812

@@ -2826,7 +2820,7 @@ func TestTest_SensitiveInputValues(t *testing.T) {
28262820
}
28272821

28282822
code := c.Run([]string{"-no-color", "-verbose"})
2829-
output = done(t)
2823+
output := done(t)
28302824

28312825
if code != 1 {
28322826
t.Errorf("expected status code 1 but got %d", code)
@@ -3088,9 +3082,8 @@ func TestTest_InvalidOverrides(t *testing.T) {
30883082
Meta: meta,
30893083
}
30903084

3091-
output := done(t)
3092-
30933085
if code := init.Run(nil); code != 0 {
3086+
output := done(t)
30943087
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
30953088
}
30963089

@@ -3104,7 +3097,7 @@ func TestTest_InvalidOverrides(t *testing.T) {
31043097
}
31053098

31063099
code := c.Run([]string{"-no-color"})
3107-
output = done(t)
3100+
output := done(t)
31083101

31093102
if code != 0 {
31103103
t.Errorf("expected status code 0 but got %d", code)
@@ -3188,9 +3181,8 @@ func TestTest_InvalidConfig(t *testing.T) {
31883181
Meta: meta,
31893182
}
31903183

3191-
output := done(t)
3192-
31933184
if code := init.Run(nil); code != 0 {
3185+
output := done(t)
31943186
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
31953187
}
31963188

@@ -3204,7 +3196,7 @@ func TestTest_InvalidConfig(t *testing.T) {
32043196
}
32053197

32063198
code := c.Run([]string{"-no-color"})
3207-
output = done(t)
3199+
output := done(t)
32083200

32093201
if code != 1 {
32103202
t.Errorf("expected status code ! but got %d", code)
@@ -3271,9 +3263,8 @@ func TestTest_RunBlocksInProviders(t *testing.T) {
32713263
Meta: meta,
32723264
}
32733265

3274-
output := done(t)
3275-
32763266
if code := init.Run(nil); code != 0 {
3267+
output := done(t)
32773268
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
32783269
}
32793270

@@ -3287,7 +3278,7 @@ func TestTest_RunBlocksInProviders(t *testing.T) {
32873278
}
32883279

32893280
code := test.Run([]string{"-no-color"})
3290-
output = done(t)
3281+
output := done(t)
32913282

32923283
if code != 0 {
32933284
t.Errorf("expected status code 0 but got %d", code)
@@ -3339,9 +3330,8 @@ func TestTest_RunBlocksInProviders_BadReferences(t *testing.T) {
33393330
Meta: meta,
33403331
}
33413332

3342-
output := done(t)
3343-
33443333
if code := init.Run(nil); code != 0 {
3334+
output := done(t)
33453335
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
33463336
}
33473337

@@ -3355,7 +3345,7 @@ func TestTest_RunBlocksInProviders_BadReferences(t *testing.T) {
33553345
}
33563346

33573347
code := test.Run([]string{"-no-color"})
3358-
output = done(t)
3348+
output := done(t)
33593349

33603350
if code != 1 {
33613351
t.Errorf("expected status code 1 but got %d", code)

0 commit comments

Comments
 (0)