@@ -19,8 +19,11 @@ limitations under the License.
19
19
package integration
20
20
21
21
import (
22
+ "bufio"
23
+ "bytes"
22
24
"context"
23
25
"crypto/md5"
26
+ "encoding/json"
24
27
"fmt"
25
28
"io/ioutil"
26
29
"os"
@@ -41,7 +44,6 @@ func TestDownloadOnly(t *testing.T) {
41
44
t .Run (r , func (t * testing.T ) {
42
45
// Stores the startup run result for later error messages
43
46
var rrr * RunResult
44
- var err error
45
47
46
48
profile := UniqueProfileName (r )
47
49
ctx , cancel := context .WithTimeout (context .Background (), Minutes (30 ))
@@ -58,18 +60,32 @@ func TestDownloadOnly(t *testing.T) {
58
60
defer PostMortemLogs (t , profile )
59
61
60
62
// --force to avoid uid check
61
- args := append ([]string {"start" , "--download-only" , "-p" , profile , "--force" , "--alsologtostderr" , fmt .Sprintf ("--kubernetes-version=%s" , v ), fmt .Sprintf ("--container-runtime=%s" , r )}, StartArgs ()... )
63
+ args := append ([]string {"start" , "-o=json" , "- -download-only" , "-p" , profile , "--force" , "--alsologtostderr" , fmt .Sprintf ("--kubernetes-version=%s" , v ), fmt .Sprintf ("--container-runtime=%s" , r )}, StartArgs ()... )
62
64
63
- // Preserve the initial run-result for debugging
65
+ rt , err := Run ( t , exec . CommandContext ( ctx , Target (), args ... ))
64
66
if rrr == nil {
65
- rrr , err = Run (t , exec .CommandContext (ctx , Target (), args ... ))
66
- } else {
67
- _ , err = Run (t , exec .CommandContext (ctx , Target (), args ... ))
67
+ // Preserve the initial run-result for debugging
68
+ rrr = rt
68
69
}
69
-
70
70
if err != nil {
71
71
t .Errorf ("failed to download only. args: %q %v" , args , err )
72
72
}
73
+ t .Run ("check json events" , func (t * testing.T ) {
74
+ s := bufio .NewScanner (bytes .NewReader (rt .Stdout .Bytes ()))
75
+ for s .Scan () {
76
+ var rtObj map [string ]interface {}
77
+ err = json .Unmarshal (s .Bytes (), & rtObj )
78
+ if err != nil {
79
+ t .Errorf ("failed to parse output: %v" , err )
80
+ } else if step , ok := rtObj ["data" ]; ok {
81
+ if stepMap , ok := step .(map [string ]interface {}); ok {
82
+ if stepMap ["currentstep" ] == "" {
83
+ t .Errorf ("Empty step number for %v" , stepMap ["name" ])
84
+ }
85
+ }
86
+ }
87
+ }
88
+ })
73
89
74
90
// skip for none, as none driver does not have preload feature.
75
91
if ! NoneDriver () {
0 commit comments