package crawler_manager import ( "testing" //grpc1 "google.golang.org/grpc" "os" "os/exec" "path/filepath" "strings" "io/ioutil" ) 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 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()) } func TestDir22(t *testing.T) { cs := IsStartContainer() t.Log(cs) } func TestCrateDir(t *testing.T) { var configPath []string; configPath = append(configPath, ConfigFolder + "/java/oracle/") configPath = append(configPath, ConfigFolder + "/go/test/") configPath = append(configPath, ConfigFolder + "/java/mysql/") configPath = append(configPath, ConfigFolder + "/network/http/") configPath = append(configPath, ConfigFolder + "/network/redis/") configPath = append(configPath, ConfigFolder + "/network/ldap/") var containerPath []string; containerPath = append(containerPath, BinaryFolder + "/java/") containerPath = append(containerPath, BinaryFolder + "/go/") containerPath = append(containerPath, BinaryFolder + "/network/") containerPath = append(containerPath, PidFolder) b, _:=ioutil.ReadFile("/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/example.json") for i, p := range configPath { pp := filepath.Join(p) os.MkdirAll(pp, os.ModePerm) if i % 2 == 0 { ioutil.WriteFile(pp + "/id.json", b, os.ModePerm) } } for _, p := range containerPath { pp := filepath.Join(p) os.MkdirAll(pp, os.ModePerm) } } func TestInit(t *testing.T) { InitContainer() } func TestDirs(t *testing.T) { cs := IsStartContainer() for _, c := range cs { var ccl []string ExistConfigFileDir(ConfigFolder, c, &ccl) t.Log(ccl) } } func TestSplitPath(t *testing.T) { ff :="/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/ffff" a := filepath.Dir(ff) t.Log(a) a = filepath.Clean(a) t.Log(a) a = filepath.Base(a) t.Log(a) }