From 7754db8619ed385a667cd7615d4f89c117580edf Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Sun, 4 Sep 2022 22:56:26 +0800 Subject: [PATCH] fix: update doctor test cases --- cmd/doctor.go | 6 +++--- cmd/doctor_test.go | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/doctor.go b/cmd/doctor.go index c85bc062f1d5..e502d861c7b4 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -117,7 +117,7 @@ func getCmdMount(mp string) (pid, cmd string, err error) { } ret, err := exec.Command("bash", "-c", "ps -ef | grep 'juicefs mount' | grep "+mp).CombinedOutput() - if err != nil { + if err != nil && !strings.Contains(err.Error(), "exit status 1") { return "", "", fmt.Errorf("failed to execute command `ps -ef | grep juicefs | grep %s`: %v", mp, err) } @@ -240,8 +240,8 @@ func getPprofPort(pid string) (int, error) { cmdStr = "sudo " + cmdStr } ret, err := exec.Command("bash", "-c", cmdStr).CombinedOutput() - if err != nil { - return 0, fmt.Errorf("failed to execute command `ps -ef | grep juicefs`: %v", err) + if err != nil && !strings.Contains(err.Error(), "exit status 1") { + return 0, fmt.Errorf("failed to execute command `%s`: %v", cmdStr, err) } lines := strings.Split(string(ret), "\n") if len(lines) == 0 { diff --git a/cmd/doctor_test.go b/cmd/doctor_test.go index f2535dc453ca..7078aabc77d5 100644 --- a/cmd/doctor_test.go +++ b/cmd/doctor_test.go @@ -24,6 +24,8 @@ import ( ) func TestDoctor(t *testing.T) { + mountTemp(t, nil, nil, nil) + defer umountTemp(t) Convey("Positive doctor cases", t, func() { cases := []struct { name string @@ -32,12 +34,11 @@ func TestDoctor(t *testing.T) { {"Simple cases", []string{"", "doctor"}}, {"Enable collecting syslog", []string{"", "doctor", "--collect-log"}}, {"Max 5 log entries", []string{"", "doctor", "--collect-log", "--limit", "5"}}, - {"Enable collecting pprof metric", []string{"", "doctor", "--collect-log", "--collect-pprof"}}, } for _, c := range cases { Convey(c.name, func() { - So(Main(c.args), ShouldBeNil) + So(Main(append(c.args, testMountPoint)), ShouldBeNil) }) } @@ -45,7 +46,7 @@ func TestDoctor(t *testing.T) { Convey("Specify out dir", t, func() { Convey("Use default out dir", func() { - So(Main([]string{"", "doctor"}), ShouldBeNil) + So(Main([]string{"", "doctor", testMountPoint}), ShouldBeNil) }) outDir := "./doctor/ok" @@ -53,7 +54,7 @@ func TestDoctor(t *testing.T) { if err := os.MkdirAll(outDir, 0755); err != nil { t.Fatalf("doctor error: %v", err) } - So(Main([]string{"", "doctor", "--out-dir", outDir}), ShouldBeNil) + So(Main([]string{"", "doctor", "--out-dir", outDir, testMountPoint}), ShouldBeNil) if err := os.RemoveAll(outDir); err != nil { t.Fatalf("doctor error: %v", err) } @@ -68,7 +69,7 @@ func TestDoctor(t *testing.T) { } for _, c := range edgeCases { Convey(c.name, func() { - So(Main([]string{"", "doctor", "--out-dir", c.outDir}), ShouldNotBeNil) + So(Main([]string{"", "doctor", "--out-dir", c.outDir, testMountPoint}), ShouldNotBeNil) }) } })