141 lines
2.2 KiB
Go
141 lines
2.2 KiB
Go
package crawler_manager
|
|
|
|
import (
|
|
"testing"
|
|
//grpc1 "google.golang.org/grpc"
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
)
|
|
|
|
func TestManageCrawler(t *testing.T) {
|
|
ManageCrawler("/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_manager_go/config/example.json")
|
|
}
|
|
|
|
func TestAdd(t *testing.T) {
|
|
|
|
|
|
CallAdd();
|
|
|
|
}
|
|
|
|
func TestCallInit(t *testing.T) {
|
|
//CallInit("")
|
|
}
|
|
|
|
func TestCallRemove(t *testing.T) {
|
|
CallRemove()
|
|
}
|
|
|
|
func TestPid(t *testing.T) {
|
|
|
|
pp, err := os.FindProcess(12314)
|
|
if err != nil{
|
|
t.Log("err : ", err)
|
|
}
|
|
|
|
t.Log(pp.Pid)
|
|
|
|
}
|
|
|
|
func TestPr(t *testing.T) {
|
|
//ps -aux | awk '{print $2}' | grep 15538
|
|
bytes, _ := exec.Command("ps","-aux", "awk", "{print $2}").Output()
|
|
|
|
t.Log(string(bytes))
|
|
|
|
}
|
|
|
|
func TestExe(t *testing.T) {
|
|
ps := exec.Command("ps", "-aux")
|
|
awk := exec.Command("awk", "{print $2}")
|
|
grep := exec.Command("grep", "22373")
|
|
|
|
awk.Stdin, _ = ps.StdoutPipe()
|
|
grep.Stdin,_ = awk.StdoutPipe()
|
|
|
|
ps.Start()
|
|
awk.Start()
|
|
|
|
byt, _ := grep.Output()
|
|
|
|
t.Log(len(byt))
|
|
}
|
|
|
|
func TestExeState(t *testing.T) {
|
|
ps := exec.Command("ps", "-aux")
|
|
awk := exec.Command("awk", "{print $2, $7}")
|
|
grep := exec.Command("grep", "22373")
|
|
awk2 := exec.Command("awk", "{print $2}")
|
|
|
|
awk.Stdin, _ = ps.StdoutPipe()
|
|
grep.Stdin,_ = awk.StdoutPipe()
|
|
awk2.Stdin,_ = grep.StdoutPipe()
|
|
|
|
ps.Start()
|
|
awk.Start()
|
|
grep.Start()
|
|
|
|
byt, _ := awk2.Output()
|
|
|
|
t.Log(len(byt))
|
|
t.Log(string(byt))
|
|
t.Log(len(strings.TrimSpace(string(byt))))
|
|
}
|
|
|
|
func TestPipe(t *testing.T) {
|
|
c1 := exec.Command("ls")
|
|
c2 := exec.Command("wc", "-l")
|
|
c2.Stdin, _ = c1.StdoutPipe()
|
|
//c2.Stdout = os.Stdout
|
|
|
|
_ = c1.Start()
|
|
aa, _ := c2.Output()
|
|
|
|
t.Log(string(aa))
|
|
}
|
|
|
|
func TestIsAlive(t *testing.T) {
|
|
|
|
IsAlive(15538)
|
|
|
|
}
|
|
|
|
func TestIsState(t *testing.T) {
|
|
|
|
b := IsState(225931)
|
|
t.Log(b)
|
|
|
|
}
|
|
|
|
func TestCom(t *testing.T) {
|
|
str:= "Z"
|
|
|
|
if str == "Z" {
|
|
t.Log("aaa")
|
|
}
|
|
}
|
|
|
|
func TestReadConfig(t *testing.T) {
|
|
|
|
c := ReadConfig("/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/example.json")
|
|
t.Log(c)
|
|
|
|
}
|
|
|
|
|
|
func TestDir(t *testing.T) {
|
|
a := filepath.Dir("/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/example.json")
|
|
|
|
t.Log(a)
|
|
}
|
|
|
|
|
|
func TestMyPid(t *testing.T) {
|
|
t.Log(os.Getpid())
|
|
}
|