@@ -64,16 +64,16 @@ func DirectoryExists(d string) bool {
6464
6565// Common state while running an e2etest.
6666type TestContext struct {
67- t * testing.T
67+ t * testing.T
6868 tempdir string
6969
7070 // This is used instead of `T.Cleanup()` to support running commands during
7171 // cleanup. The context from `T.Context()` is cancelled before `T.Cleanup()`
7272 // registered cleanup functions are invoked.
73- cleanups []func ()
73+ cleanups []func ()
7474 teardownCalled bool
7575
76- context context.Context
76+ context context.Context
7777 cancelled bool
7878
7979 usePodcvd bool
@@ -87,7 +87,7 @@ func runCmdWithContextEnv(ctx context.Context, command []string, envvars map[str
8787 cmd .Stdout = cmdWriter
8888 cmd .Stderr = cmdWriter
8989
90- envvarPairs := []string {};
90+ envvarPairs := []string {}
9191 for k , v := range envvars {
9292 envvarPairs = append (envvarPairs , fmt .Sprintf ("%s=%s" , k , v ))
9393 }
@@ -124,7 +124,7 @@ func (tc *TestContext) RunAdbWaitForDevice() error {
124124}
125125
126126// Runs the given command with the existing envvars.
127- func (tc * TestContext ) RunCmd (args ... string ) (string , error ) {
127+ func (tc * TestContext ) RunCmd (args ... string ) (string , error ) {
128128 command := []string {}
129129 command = append (command , args ... )
130130 return tc .RunCmdWithEnv (command , map [string ]string {})
@@ -140,8 +140,8 @@ func (tc *TestContext) TargetBin() string {
140140
141141// Common parameters passed to `cvd fetch`.
142142type FetchArgs struct {
143- DefaultBuildBranch string
144- DefaultBuildTarget string
143+ DefaultBuildBranch string
144+ DefaultBuildTarget string
145145 TestSuiteBuildBranch string
146146 TestSuiteBuildTarget string
147147}
@@ -153,7 +153,7 @@ type CreateArgs struct {
153153
154154// Common parameters to fetch and create a Cuttlefish device.
155155type FetchAndCreateArgs struct {
156- Fetch FetchArgs
156+ Fetch FetchArgs
157157 Create CreateArgs
158158}
159159
@@ -196,7 +196,7 @@ func (tc *TestContext) CVDCreate(args CreateArgs) error {
196196 "HOME" : tc .tempdir ,
197197 }
198198
199- createCmd := []string {tc .TargetBin (), "--verbosity=DEBUG" , "create" };
199+ createCmd := []string {tc .TargetBin (), "--verbosity=DEBUG" , "create" }
200200 createCmd = append (createCmd , "--report_anonymous_usage_stats=y" )
201201 createCmd = append (createCmd , "--undefok=report_anonymous_usage_stats" )
202202 if len (args .Args ) > 0 {
@@ -217,7 +217,7 @@ func (tc *TestContext) CVDStop() error {
217217 "HOME" : tc .tempdir ,
218218 }
219219
220- stopCmd := []string {tc .TargetBin (), "stop" };
220+ stopCmd := []string {tc .TargetBin (), "stop" }
221221 if _ , err := tc .RunCmdWithEnv (stopCmd , tempdirEnv ); err != nil {
222222 log .Printf ("Failed to stop instance(s): %w" , err )
223223 return err
@@ -243,7 +243,6 @@ func (tc *TestContext) LaunchCVD(args CreateArgs) error {
243243 return err
244244 }
245245
246-
247246 tc .Cleanup (func () { tc .StopCVD () })
248247 return nil
249248}
@@ -254,7 +253,7 @@ func (tc *TestContext) StopCVD() error {
254253 "HOME" : tc .tempdir ,
255254 }
256255
257- stopCmd := []string {"bin/stop_cvd" };
256+ stopCmd := []string {"bin/stop_cvd" }
258257 if _ , err := tc .RunCmdWithEnv (stopCmd , tempdirEnv ); err != nil {
259258 log .Printf ("Failed to stop instance(s): %w" , err )
260259 return err
@@ -269,7 +268,7 @@ func (tc *TestContext) CVDPowerwash() error {
269268 "HOME" : tc .tempdir ,
270269 }
271270
272- createCmd := []string {tc .TargetBin (), "powerwash" };
271+ createCmd := []string {tc .TargetBin (), "powerwash" }
273272 if _ , err := tc .RunCmdWithEnv (createCmd , tempdirEnv ); err != nil {
274273 log .Printf ("Failed to powerwash instance(s): %w" , err )
275274 return err
@@ -284,7 +283,7 @@ type LoadArgs struct {
284283}
285284
286285// Performs `cvd load`.
287- func (tc * TestContext ) CVDLoad (load LoadArgs ) error {
286+ func (tc * TestContext ) CVDLoad (load LoadArgs ) error {
288287 configpath := path .Join (tc .tempdir , "cvd_load_config.json" )
289288
290289 log .Printf ("Writing config to %s" , configpath )
@@ -300,7 +299,7 @@ func (tc *TestContext) CVDLoad(load LoadArgs) error {
300299 tc .TargetBin (),
301300 "load" ,
302301 configpath ,
303- };
302+ }
304303 credentialArg := os .Getenv ("CREDENTIAL_SOURCE" )
305304 if credentialArg != "" {
306305 loadCmd = append (loadCmd , fmt .Sprintf ("--credential_source=%s" , credentialArg ))
@@ -316,22 +315,22 @@ func (tc *TestContext) CVDLoad(load LoadArgs) error {
316315}
317316
318317func (tc * TestContext ) GetMetricsDir () (string , error ) {
319- output , err := tc .RunCmd ("cvd" , "fleet" )
320- if err != nil {
321- return "" , fmt .Errorf ("failed to run `cvd fleet`" )
322- }
318+ output , err := tc .RunCmd ("cvd" , "fleet" )
319+ if err != nil {
320+ return "" , fmt .Errorf ("failed to run `cvd fleet`" )
321+ }
323322
324- re := regexp .MustCompile (`"metrics_dir" : "(.*)",` )
325- matches := re .FindStringSubmatch (output )
326- if len (matches ) != 2 {
327- return "" , fmt .Errorf ("failed to find metrics directory" )
328- }
323+ re := regexp .MustCompile (`"metrics_dir" : "(.*)",` )
324+ matches := re .FindStringSubmatch (output )
325+ if len (matches ) != 2 {
326+ return "" , fmt .Errorf ("failed to find metrics directory" )
327+ }
329328
330- metricsdir := matches [1 ]
331- if ! DirectoryExists (metricsdir ) {
332- return "" , fmt .Errorf ("failed to find directory %s" , metricsdir )
333- }
334- return metricsdir , nil
329+ metricsdir := matches [1 ]
330+ if ! DirectoryExists (metricsdir ) {
331+ return "" , fmt .Errorf ("failed to find directory %s" , metricsdir )
332+ }
333+ return metricsdir , nil
335334}
336335
337336// Creates a standard environment for an e2etests.
@@ -462,10 +461,10 @@ func (tc *TestContext) TearDown() {
462461 outmetricsdir := path .Join (testoutdir , "metrics_files" )
463462 err := os .MkdirAll (outmetricsdir , os .ModePerm )
464463 if err == nil {
465- _ , err := runCmdWithContextEnv (context .TODO (), []string {"cp" , "-r" , "--dereference" , metricsdir , outmetricsdir }, map [string ]string {})
466- if err != nil {
467- log .Printf ("failed to copy %s to %s: %w" , metricsdir , outmetricsdir , err )
468- }
464+ _ , err := runCmdWithContextEnv (context .TODO (), []string {"cp" , "-r" , "--dereference" , metricsdir , outmetricsdir }, map [string ]string {})
465+ if err != nil {
466+ log .Printf ("failed to copy %s to %s: %w" , metricsdir , outmetricsdir , err )
467+ }
469468 }
470469 }
471470
@@ -488,13 +487,13 @@ func findLocalXTS(cuttlefishArgs FetchAndCreateArgs, xtsArgs XtsArgs) string {
488487 // TODO: explore adding a non-user-specific cache option to cvd.
489488
490489 homedir , err := os .UserHomeDir ()
491- if err != nil {
490+ if err != nil {
492491 user := os .Getenv ("USER" )
493492 if user == "" {
494493 return ""
495494 }
496495 homedir = path .Join ("/home" , user )
497- }
496+ }
498497
499498 possibleDir := path .Join (homedir , cuttlefishArgs .Fetch .TestSuiteBuildBranch , cuttlefishArgs .Fetch .TestSuiteBuildTarget )
500499 log .Printf ("Checking %s" , possibleDir )
@@ -511,29 +510,29 @@ func findLocalXTS(cuttlefishArgs FetchAndCreateArgs, xtsArgs XtsArgs) string {
511510}
512511
513512type xtsTest struct {
514- Name string `xml:"name,attr"`
513+ Name string `xml:"name,attr"`
515514 Result string `xml:"result,attr"`
516515}
517516
518517type xtsTestCase struct {
519- Name string `xml:"name,attr"`
518+ Name string `xml:"name,attr"`
520519 Tests []xtsTest `xml:"Test"`
521520}
522521
523522type xtsModule struct {
524- Name string `xml:"name,attr"`
523+ Name string `xml:"name,attr"`
525524 TestCases []xtsTestCase `xml:"TestCase"`
526525}
527526
528527type xtsSummary struct {
529- Pass int `xml:"pass,attr"`
530- Failed int `xml:"failed,attr"`
531- ModulesDone int `xml:"modules_done,attr"`
528+ Pass int `xml:"pass,attr"`
529+ Failed int `xml:"failed,attr"`
530+ ModulesDone int `xml:"modules_done,attr"`
532531 ModulesTotal int `xml:"modules_total,attr"`
533532}
534533
535534type xtsResult struct {
536- Summary xtsSummary `xml:"Summary"`
535+ Summary xtsSummary `xml:"Summary"`
537536 Modules []xtsModule `xml:"Module"`
538537}
539538
@@ -585,7 +584,7 @@ func RunXts(t *testing.T, cuttlefishArgs FetchAndCreateArgs, xtsArgs XtsArgs) {
585584 "commandAndExit" ,
586585 xtsArgs .XtsType ,
587586 "--log-level-display=INFO" ,
588- };
587+ }
589588 xtsCommand = append (xtsCommand , xtsArgs .XtsArgs ... )
590589 if _ , err := tc .RunCmd (xtsCommand ... ); err != nil {
591590 t .Fatalf ("failed to fully run XTS: %w" , err )
@@ -604,9 +603,9 @@ func RunXts(t *testing.T, cuttlefishArgs FetchAndCreateArgs, xtsArgs XtsArgs) {
604603 t .Fatalf ("failed to parse XTS XML results from %s: %w" , xtsResultsPath , err )
605604 }
606605
607- for _ , xtsModule := range ( xtsResult .Modules ) {
608- for _ , xtsTestCase := range ( xtsModule .TestCases ) {
609- for _ , xtsTest := range ( xtsTestCase .Tests ) {
606+ for _ , xtsModule := range xtsResult .Modules {
607+ for _ , xtsTestCase := range xtsModule .TestCases {
608+ for _ , xtsTest := range xtsTestCase .Tests {
610609 testname := fmt .Sprintf ("%s#%s" , xtsTestCase .Name , xtsTest .Name )
611610 t .Run (testname , func (t * testing.T ) {
612611 log .Printf ("%s result: %s" , testname , xtsTest .Result )
0 commit comments