Ejemplo n.º 1
0
func main() {
	kmgCmd.MustRun(`kmg GoCrossCompile -platform linux_amd64 github.com/bronze1man/kmg/kmg`)
	kmgCmd.MustRun(`kmg GoCrossCompile -platform linux_amd64 github.com/bronze1man/kmg/kmg/SubCommand/serviceCmd/testBin`)
	kmgFile.MustCopyFile(filepath.Join(kmgConfig.DefaultEnv().ProjectPath, "bin/kmg_linux_amd64"), filepath.Join(dockerPath, "kmg"))
	kmgFile.MustCopyFile(filepath.Join(kmgConfig.DefaultEnv().ProjectPath, "bin/testBin_linux_amd64"), filepath.Join(dockerPath, "testBin"))
	kmgFile.MustWriteFile(filepath.Join(dockerPath, "Dockerfile"), []byte(`FROM ubuntu
WORKDIR /
COPY kmg /bin/
COPY testBin /bin/
RUN chmod +x /bin/kmg
RUN chmod +x /bin/testBin
CMD testBin
`))
	//CMD kmg service setandrestart t testBin && kmg service stop t && kmg service start t && kmg service restart t
	kmgCmd.MustRunAndReturnOutput("docker build -t kmgtest " + dockerPath)
	for i := 0; i < 20; i++ {
		time.Sleep(time.Second)
		kmgCmd.MustRunAndReturnOutput("docker run kmgtest")
	}
}
Ejemplo n.º 2
0
func TestJava(ot *testing.T) {
	closer := testPackage.ListenAndServe_Demo(":34895", &testPackage.Demo{}, kmgCrypto.Get32PskFromString("abc psk"))
	defer closer()
	os.Chdir(filepath.Join("java", "src"))
	MustGenerateCode(&GenerateRequest{
		ObjectPkgPath:   "github.com/bronze1man/kmg/kmgRpc/testPackage",
		ObjectName:      "Demo",
		ObjectIsPointer: true,
		OutFilePath:     "testPackage/RpcDemo.java",
		OutPackageName:  "testPackage",
		OutClassName:    "RpcDemo",
	})
	kmgCmd.MustRun("javac -sourcepath . ./testPackage/Main.java")
	out := kmgCmd.MustRunAndReturnOutput("java -classpath . testPackage.Main")
	kmgTest.Equal(out, []byte("Success\n"))
}
Ejemplo n.º 3
0
func TestGoRunFile(ot *testing.T) {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	defer os.Chdir(wd)
	root := kmgConfig.DefaultEnv().ProjectPath
	os.Chdir(root)
	kmgPath := filepath.Join(root, "bin/kmg")
	kmgFile.MustDelete(kmgPath)
	//kmgCmd.MustRun("kmg go install github.com/bronze1man/kmg/kmg")
	gopath := filepath.Join(wd, "testWorkspace")
	os.Chdir(gopath)
	kmgFile.MustDelete(filepath.Join(gopath, "bin"))
	kmgFile.MustDelete(filepath.Join(gopath, "pkg"))
	kmgFile.MustDelete(filepath.Join(gopath, "tmp"))
	kmgFile.MustDelete(filepath.Join(gopath, "src", "kmgTestMain", "other.go"))
	goRunInstall(gopath, "kmgTestMain")
	output := kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "kmgTestMain"))
	kmgTest.Equal(string(output), "1\n")
	kmgFile.MustWriteFile(filepath.Join(wd, "testWorkspace", "src", "kmgTestMain", "other.go"), []byte(`
package main

func init(){
	a=2
}
`))

	goRunInstall(gopath, "kmgTestMain")
	output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "kmgTestMain"))
	kmgTest.Equal(string(output), "2\n")
	kmgFile.MustDelete(filepath.Join(wd, "testWorkspace", "src", "kmgTestMain", "other.go"))

	goRunInstall(gopath, "kmgTestMain")
	output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "kmgTestMain"))
	kmgTest.Equal(string(output), "1\n")

	goRunInstall(gopath, "kmgTestMain/l2Main")
	output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "l2Main"))
	kmgTest.Equal(string(output), "l2Main\n")

	kmgFile.MustWriteFile(filepath.Join(gopath, "src", "replaceBin", "replaceBin.go"), []byte(`
package main

import "fmt"

func main(){
	fmt.Println("replaceBin")
}
`))
	goRunInstall(gopath, "replaceBin")
	output = kmgCmd.MustRunAndReturnOutput(filepath.Join(gopath, "bin", "replaceBin"))
	kmgTest.Equal(string(output), "replaceBin\n")

	kmgFile.MustWriteFile(filepath.Join(gopath, "src", "replaceBin", "replaceBin.go"), []byte(`
package replaceBin

var A = "1"
`))
	goRunInstall(gopath, "replaceBin")
	// 应该会说这个不是main的package
}