-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from hyperf/perm
fix: check permission
- Loading branch information
Showing
10 changed files
with
85 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
package gotask | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestClearAddr(t *testing.T) { | ||
if err := clearAddr("unix", "/tmp/non-exist.sock"); err != nil { | ||
t.Errorf("clearAddr should not return error for non-exist files") | ||
dir, _ := ioutil.TempDir("", "") | ||
defer os.Remove(dir) | ||
|
||
if _, err := checkAddr("unix", dir+"/non-exist.sock"); err != nil { | ||
t.Errorf("checkAddr should not return error for non-exist files") | ||
} | ||
if err := clearAddr("tcp", "127.0.0.1:6000"); err != nil { | ||
t.Errorf("clearAddr should not return error for tcp ports") | ||
if _, err := checkAddr("tcp", "127.0.0.1:6000"); err != nil { | ||
t.Errorf("checkAddr should not return error for tcp ports") | ||
} | ||
file, err := os.Create("/tmp/temp.sock") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer file.Close() | ||
if err := clearAddr("unix", "/tmp/temp.sock"); err != nil { | ||
t.Errorf("clearAddr should be able to clear unix socket") | ||
if _, err := checkAddr("unix", "/tmp/temp.sock"); err != nil { | ||
t.Errorf("checkAddr should be able to clear unix socket") | ||
} | ||
_, err = os.Stat("/tmp/temp.sock") | ||
if !os.IsNotExist(err) { | ||
t.Errorf("unix socket are not cleared, %v", err) | ||
} | ||
|
||
if _, err := checkAddr("unix", dir+"/path/to/dir/temp.sock"); err != nil { | ||
t.Errorf("checkAddr should be able to create directory if not exist") | ||
} | ||
|
||
if _, err := checkAddr("unix", "/private/temp.sock"); err == nil { | ||
t.Error("unix socket shouldn't be created") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters