1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00

More test case for building

This commit is contained in:
V2Ray 2015-11-04 21:20:06 +01:00
parent 8204c9923d
commit 581e6b7104
2 changed files with 72 additions and 25 deletions

View File

@ -11,16 +11,17 @@ import (
) )
var ( var (
targetOS = flag.String("os", runtime.GOOS, "Target OS of this build.") flagTargetOS = flag.String("os", runtime.GOOS, "Target OS of this build.")
targetArch = flag.String("arch", runtime.GOARCH, "Target CPU arch of this build.") flagTargetArch = flag.String("arch", runtime.GOARCH, "Target CPU arch of this build.")
archive = flag.Bool("zip", false, "Whether to make an archive of files or not.") flagArchive = flag.Bool("zip", false, "Whether to make an archive of files or not.")
binPath string
) )
func createTargetDirectory(version string, goOS GoOS, goArch GoArch) (string, error) { func createTargetDirectory(version string, goOS GoOS, goArch GoArch) (string, error) {
suffix := getSuffix(goOS, goArch) suffix := getSuffix(goOS, goArch)
GOPATH := os.Getenv("GOPATH")
targetDir := filepath.Join(GOPATH, "bin", "v2ray-"+version+suffix) targetDir := filepath.Join(binPath, "v2ray-"+version+suffix)
if version != "custom" { if version != "custom" {
os.RemoveAll(targetDir) os.RemoveAll(targetDir)
} }
@ -36,19 +37,31 @@ func getTargetFile(goOS GoOS) string {
return "v2ray" + suffix return "v2ray" + suffix
} }
func getBinPath() string {
GOPATH := os.Getenv("GOPATH")
return filepath.Join(GOPATH, "bin")
}
func main() { func main() {
flag.Parse() flag.Parse()
binPath = getBinPath()
build(*flagTargetOS, *flagTargetArch, *flagArchive, "")
}
v2rayOS := parseOS(*targetOS) func build(targetOS, targetArch string, archive bool, version string) {
v2rayArch := parseArch(*targetArch) v2rayOS := parseOS(targetOS)
v2rayArch := parseArch(targetArch)
version, err := git.RepoVersionHead() if len(version) == 0 {
if version == git.VersionUndefined { v, err := git.RepoVersionHead()
version = "custom" if v == git.VersionUndefined {
} v = "custom"
if err != nil { }
fmt.Println("Unable to detect V2Ray version: " + err.Error()) if err != nil {
return fmt.Println("Unable to detect V2Ray version: " + err.Error())
return
}
version = v
} }
fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch) fmt.Printf("Building V2Ray (%s) for %s %s\n", version, v2rayOS, v2rayArch)
@ -68,9 +81,7 @@ func main() {
fmt.Println("Unable to copy config files: " + err.Error()) fmt.Println("Unable to copy config files: " + err.Error())
} }
if *archive { if archive {
GOPATH := os.Getenv("GOPATH")
binPath := filepath.Join(GOPATH, "bin")
err := os.Chdir(binPath) err := os.Chdir(binPath)
if err != nil { if err != nil {
fmt.Printf("Unable to switch to directory (%s): %v\n", binPath, err) fmt.Printf("Unable to switch to directory (%s): %v\n", binPath, err)

View File

@ -1,23 +1,59 @@
package main package main
import ( import (
"fmt"
"os" "os"
"path/filepath"
"testing" "testing"
"github.com/v2ray/v2ray-core/testing/unit" "github.com/v2ray/v2ray-core/testing/unit"
) )
func cleanBinPath() {
os.RemoveAll(binPath)
os.Mkdir(binPath, os.ModeDir|0777)
}
func fileExists(file string) bool {
_, err := os.Stat(file)
return err == nil
}
func allFilesExists(files ...string) bool {
for _, file := range files {
fullPath := filepath.Join(binPath, file)
if !fileExists(fullPath) {
fmt.Println(fullPath + " doesn't exist.")
return false
}
}
return true
}
func TestBuildMacOS(t *testing.T) { func TestBuildMacOS(t *testing.T) {
assert := unit.Assert(t) assert := unit.Assert(t)
binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
cleanBinPath()
targetFile := os.ExpandEnv("$GOPATH/bin/v2ray-macos.zip") build("macos", "amd64", true, "test")
os.Remove(targetFile) assert.Bool(allFilesExists(
"v2ray-macos.zip",
"v2ray-test-macos",
filepath.Join("v2ray-test-macos", "config.json"),
filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()
*targetOS = "macos" build("windows", "amd64", true, "test")
*targetArch = "amd64" assert.Bool(allFilesExists(
*archive = true "v2ray-windows-64.zip",
main() "v2ray-test-windows-64",
filepath.Join("v2ray-test-windows-64", "config.json"),
filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()
_, err := os.Stat(targetFile) build("linux", "amd64", true, "test")
assert.Error(err).IsNil() assert.Bool(allFilesExists(
"v2ray-linux-64.zip",
"v2ray-test-linux-64",
filepath.Join("v2ray-test-linux-64", "vpoint_socks_vmess.json"),
filepath.Join("v2ray-test-linux-64", "vpoint_vmess_freedom.json"),
filepath.Join("v2ray-test-linux-64", "v2ray"))).IsTrue()
} }