crawler_manager_go/crawler_manager_test.go

239 lines
3.9 KiB
Go
Raw Normal View History

2017-04-13 02:53:00 +00:00
package crawler_manager
import (
"testing"
//grpc1 "google.golang.org/grpc"
2017-04-14 02:29:55 +00:00
"os"
"os/exec"
"path/filepath"
"strings"
2017-04-14 07:23:42 +00:00
"io/ioutil"
2017-04-13 02:53:00 +00:00
)
func TestCallInit(t *testing.T) {
2017-04-14 02:29:55 +00:00
//CallInit("")
2017-04-13 02:53:00 +00:00
}
2017-04-15 11:10:33 +00:00
2017-04-14 02:29:55 +00:00
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) {
2017-04-15 11:10:33 +00:00
//c := ReadConfig("/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_go/config/example.json")
//t.Log(c)
2017-04-14 02:29:55 +00:00
}
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())
}
2017-04-14 07:23:42 +00:00
func TestDir22(t *testing.T) {
2017-04-15 11:10:33 +00:00
//cs := IsStartContainer()
2017-04-14 07:23:42 +00:00
2017-04-15 11:10:33 +00:00
//t.Log(cs)
2017-04-14 07:23:42 +00:00
}
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/")
2017-04-14 08:19:02 +00:00
configPath = append(configPath, ConfigFolder + "/network/ldap/")
2017-04-14 07:23:42 +00:00
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) {
2017-04-15 11:10:33 +00:00
//InitContainer()
2017-04-14 07:23:42 +00:00
}
func TestDirs(t *testing.T) {
2017-04-15 11:10:33 +00:00
//cs := IsStartContainer()
//
//for _, c := range cs {
// var ccl []string
// ExistConfigFileDir(ConfigFolder, c, &ccl)
// t.Log(ccl)
//
//}
2017-04-14 07:23:42 +00:00
2017-04-14 08:19:02 +00:00
}
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)
2017-04-14 07:23:42 +00:00
2017-04-15 11:10:33 +00:00
}
func TestInitCM(t *testing.T) {
GetInstance().init()
GetInstance().stopContainerAll()
}
func TestCallAdd(t *testing.T) {
//
c := "java"
cn := "HEALTH_"+"MYSQL"
id := "id.json"
GetInstance().runAndInitContainer(&c)
callAdd(&c, &cn, &id)
GetInstance().stopContainer(&c)
}
func TestCallRemove22(t *testing.T) {
c := "java"
cn := "HEALTH_"+"MYSQL"
id := "id.json"
GetInstance().runAndInitContainer(&c)
callRemove(&c, &cn, &id)
GetInstance().stopContainer(&c)
2017-04-14 07:23:42 +00:00
}