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 authored and root committed Sep 4, 2022
1 parent 187f54b commit 1f3fdf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ func getPprofPort(pid string) (int, error) {
return 0, nil
}

cmdStr := "lsof -i -nP | grep LISTEN | grep " + pid
cmdStr := "lsof -i -nP|grep LISTEN|grep " + pid
if os.Getuid() == 0 {
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)
return 0, fmt.Errorf("failed to execute command `%s`: %v", cmdStr, err)
}
lines := strings.Split(string(ret), "\n")
if len(lines) == 0 {
Expand Down
14 changes: 10 additions & 4 deletions cmd/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (

func TestDoctor(t *testing.T) {
Convey("Positive doctor cases", t, func() {
mountTemp(t, nil, nil, nil)
defer umountTemp(t)
cases := []struct {
name string
args []string
Expand All @@ -37,23 +39,27 @@ func TestDoctor(t *testing.T) {

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() {
mountTemp(t, nil, nil, nil)
defer umountTemp(t)
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() {
mountTemp(t, nil, nil, nil)
defer umountTemp(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)
}
Expand All @@ -68,7 +74,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 1f3fdf9

Please sign in to comment.