b923860b1a
test environment
293 lines
4.6 KiB
Go
293 lines
4.6 KiB
Go
package crawler_manager
|
|
|
|
import (
|
|
"testing"
|
|
//grpc1 "google.golang.org/grpc"
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
"io/ioutil"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCallInit(t *testing.T) {
|
|
//CallInit("")
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
cp := "/home/snoop/develop/path/go/src/loafle.com/overflow/crawler_manager_go/"
|
|
|
|
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(cp + "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)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
bbb, _:=ioutil.ReadFile(cp + "config/ttnc")
|
|
|
|
for _, p := range containerPath {
|
|
pp := filepath.Join(p)
|
|
os.MkdirAll(pp, os.ModePerm)
|
|
|
|
pp += "/"
|
|
pp += "/ttnc"
|
|
ioutil.WriteFile(pp, bbb, 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)
|
|
|
|
|
|
}
|
|
|
|
func TestInitCM(t *testing.T) {
|
|
GetInstance().init()
|
|
|
|
GetInstance().stopContainerAll()
|
|
}
|
|
|
|
func TestCallStatus(t *testing.T) {
|
|
c := "java"
|
|
GetInstance().runAndInitContainer(&c)
|
|
|
|
callStatus(&c)
|
|
|
|
GetInstance().stopContainer(&c)
|
|
}
|
|
|
|
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)
|
|
|
|
|
|
}
|
|
|
|
func TestRunRun(t *testing.T) {
|
|
c := "java"
|
|
GetInstance().runContainer(&c)
|
|
GetInstance().runContainer(&c)
|
|
GetInstance().runContainer(&c)
|
|
|
|
|
|
GetInstance().stopContainer(&c)
|
|
|
|
}
|
|
|
|
func TestActiveCrawler(t *testing.T) {
|
|
|
|
c := "java"
|
|
GetInstance().runContainer(&c)
|
|
|
|
aa := GetInstance().activeCrawler(&c)
|
|
|
|
t.Log(aa)
|
|
|
|
GetInstance().stopContainer(&c)
|
|
|
|
}
|
|
|
|
func TestErer(t *testing.T) {
|
|
|
|
var asdf []string
|
|
|
|
asdf = nil
|
|
|
|
t.Log(len(asdf))
|
|
|
|
}
|
|
|
|
|