Skip to content

Commit

Permalink
fix: update doctor test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziy1-Tan committed Sep 5, 2022
1 parent 187f54b commit 7754db8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions cmd/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,28 +34,27 @@ 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)
})

}
})

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"
Convey("Specify existing out dir", func() {
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)
}
Expand All @@ -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)
})
}
})
Expand Down

0 comments on commit 7754db8

Please sign in to comment.