Skip to content

Commit f2e80f6

Browse files
committed
go fmt cvd e2e tests.
1 parent 3124b17 commit f2e80f6

9 files changed

Lines changed: 64 additions & 65 deletions

File tree

e2etests/cvd/common/common.go

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ func DirectoryExists(d string) bool {
6464

6565
// Common state while running an e2etest.
6666
type 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`.
142142
type 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.
155155
type 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

318317
func (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

513512
type xtsTest struct {
514-
Name string `xml:"name,attr"`
513+
Name string `xml:"name,attr"`
515514
Result string `xml:"result,attr"`
516515
}
517516

518517
type xtsTestCase struct {
519-
Name string `xml:"name,attr"`
518+
Name string `xml:"name,attr"`
520519
Tests []xtsTest `xml:"Test"`
521520
}
522521

523522
type xtsModule struct {
524-
Name string `xml:"name,attr"`
523+
Name string `xml:"name,attr"`
525524
TestCases []xtsTestCase `xml:"TestCase"`
526525
}
527526

528527
type 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

535534
type 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)

e2etests/cvd/cvd_load_tests/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
package main
1616

1717
import (
18-
"fmt"
18+
"fmt"
1919
"testing"
2020

2121
"github.com/google/android-cuttlefish/e2etests/cvd/common"
2222
)
2323

2424
func TestCvdLoad(t *testing.T) {
2525
testcases := []struct {
26-
name string
26+
name string
2727
loadconfig string
2828
}{
2929
{
@@ -144,7 +144,7 @@ func TestCvdLoad(t *testing.T) {
144144

145145
err := c.CVDLoad(e2etests.LoadArgs{
146146
LoadConfig: tc.loadconfig,
147-
});
147+
})
148148
if err != nil {
149149
t.Fatal(err)
150150
}

e2etests/cvd/cvd_powerwash_tests/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ func TestCvdPowerwash(t *testing.T) {
7070
}
7171
})
7272
}
73-
}
73+
}

e2etests/cvd/display_tests/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func addDisplay(c e2etests.TestContext, t *testing.T) {
3535
t.Fatal(err)
3636
}
3737

38-
if _, err := c.RunCmd(c.TargetBin(), "display", "add", "--display=width=500,height=500",); err != nil {
38+
if _, err := c.RunCmd(c.TargetBin(), "display", "add", "--display=width=500,height=500"); err != nil {
3939
t.Fatal(err)
4040
}
4141
}
@@ -55,7 +55,7 @@ func listDisplays(c e2etests.TestContext, t *testing.T) {
5555
t.Fatal(err)
5656
}
5757

58-
if _, err := c.RunCmd(c.TargetBin(), "display", "list",); err != nil {
58+
if _, err := c.RunCmd(c.TargetBin(), "display", "list"); err != nil {
5959
t.Fatal(err)
6060
}
6161
}

e2etests/cvd/env_tests/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestListEnvServices(t *testing.T) {
3636
t.Fatal(err)
3737
}
3838

39-
if _, err := c.RunCmd(c.TargetBin(), "env", "ls",); err != nil {
39+
if _, err := c.RunCmd(c.TargetBin(), "env", "ls"); err != nil {
4040
t.Fatal(err)
4141
}
4242
}

e2etests/cvd/graphics_tests/gfxstream/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func TestGfxstream(t *testing.T) {
2424
e2etests.RunXts(t,
2525
e2etests.FetchAndCreateArgs{
2626
Fetch: e2etests.FetchArgs{
27-
DefaultBuildBranch: "aosp-android-latest-release",
28-
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
27+
DefaultBuildBranch: "aosp-android-latest-release",
28+
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
2929
TestSuiteBuildBranch: "aosp-android15-tests-release",
3030
TestSuiteBuildTarget: "test_suites_x86_64",
3131
},

e2etests/cvd/graphics_tests/gfxstream_guest_angle/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func TestGfxstreamGuestAngleHostSwiftShader(t *testing.T) {
2424
e2etests.RunXts(t,
2525
e2etests.FetchAndCreateArgs{
2626
Fetch: e2etests.FetchArgs{
27-
DefaultBuildBranch: "aosp-android-latest-release",
28-
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
27+
DefaultBuildBranch: "aosp-android-latest-release",
28+
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
2929
TestSuiteBuildBranch: "aosp-android15-tests-release",
3030
TestSuiteBuildTarget: "test_suites_x86_64",
3131
},

e2etests/cvd/graphics_tests/gfxstream_guest_angle_host_swiftshader/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func TestGfxstreamGuestAngleHostSwiftShader(t *testing.T) {
2424
e2etests.RunXts(t,
2525
e2etests.FetchAndCreateArgs{
2626
Fetch: e2etests.FetchArgs{
27-
DefaultBuildBranch: "aosp-android-latest-release",
28-
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
27+
DefaultBuildBranch: "aosp-android-latest-release",
28+
DefaultBuildTarget: "aosp_cf_x86_64_only_phone-userdebug",
2929
TestSuiteBuildBranch: "aosp-android15-tests-release",
3030
TestSuiteBuildTarget: "test_suites_x86_64",
3131
},

e2etests/cvd/launch_cvd_tests/main_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,32 @@ import (
2222

2323
func TestLaunchCvd(t *testing.T) {
2424
testcases := []struct {
25-
name string
25+
name string
2626
branch string
2727
target string
2828
}{
2929
{
30-
name: "GitMainPhone",
30+
name: "GitMainPhone",
3131
branch: "git_main",
3232
target: "aosp_cf_x86_64_only_phone-trunk_staging-userdebug",
3333
},
3434
{
35-
name: "AospMainPhone",
35+
name: "AospMainPhone",
3636
branch: "aosp-android-latest-release",
3737
target: "aosp_cf_x86_64_only_phone-userdebug",
3838
},
3939
{
40-
name: "Aosp14GsiPhone",
40+
name: "Aosp14GsiPhone",
4141
branch: "aosp-android14-gsi",
4242
target: "aosp_cf_x86_64_phone-userdebug",
4343
},
4444
{
45-
name: "Aosp13GsiPhone",
45+
name: "Aosp13GsiPhone",
4646
branch: "aosp-android13-gsi",
4747
target: "aosp_cf_x86_64_phone-userdebug",
4848
},
4949
{
50-
name: "Aosp12GsiPhone",
50+
name: "Aosp12GsiPhone",
5151
branch: "aosp-android12-gsi",
5252
target: "aosp_cf_x86_64_phone-userdebug",
5353
},

0 commit comments

Comments
 (0)