github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/server/appengine/build_test.go (about) 1 /* 2 Copyright 2013 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package appengine_test 18 19 import ( 20 "io/ioutil" 21 "os" 22 "os/exec" 23 "path/filepath" 24 "runtime" 25 "strings" 26 "testing" 27 28 "camlistore.org/pkg/osutil" 29 ) 30 31 func TestAppEngineBuilds(t *testing.T) { 32 camRoot, err := osutil.GoPackagePath("camlistore.org") 33 if err != nil { 34 t.Errorf("No camlistore.org package in GOPATH: %v", err) 35 } 36 sdkLink := filepath.Join(camRoot, "appengine-sdk") 37 if _, err := os.Lstat(sdkLink); os.IsNotExist(err) { 38 t.Skipf("Skipping test; no App Engine SDK symlink at %s pointing to App Engine SDK.", sdkLink) 39 } 40 sdk, err := os.Readlink(sdkLink) 41 if err != nil { 42 t.Fatal(err) 43 } 44 45 td, err := ioutil.TempDir("", "camli-appengine") 46 if err != nil { 47 t.Fatal(err) 48 } 49 defer os.RemoveAll(td) 50 51 gab := filepath.Join(sdk, "goroot", "bin", "go-app-builder") 52 if runtime.GOOS == "windows" { 53 gab += ".exe" 54 } 55 56 appBase := filepath.Join(camRoot, "server", "appengine") 57 f, err := os.Open(filepath.Join(appBase, "camli")) 58 if err != nil { 59 t.Fatal(err) 60 } 61 defer f.Close() 62 srcFilesAll, err := f.Readdirnames(-1) 63 if err != nil { 64 t.Fatal(err) 65 } 66 67 cmd := exec.Command(gab, 68 "-app_base", appBase, 69 "-arch", archChar(), 70 "-binary_name", "_go_app", 71 "-dynamic", 72 "-extra_imports", "appengine_internal/init", 73 "-goroot", filepath.Join(sdk, "goroot"), 74 "-nobuild_files", "^^$", 75 "-unsafe", 76 "-work_dir", td, 77 "-gopath", os.Getenv("GOPATH"), 78 ) 79 for _, f := range srcFilesAll { 80 if strings.HasSuffix(f, ".go") { 81 cmd.Args = append(cmd.Args, filepath.Join("camli", f)) 82 } 83 } 84 85 out, err := cmd.CombinedOutput() 86 if err != nil { 87 t.Fatalf("Error: %v\n%s", err, out) 88 } 89 target := filepath.Join(td, "_go_app") 90 if _, err := os.Stat(target); os.IsNotExist(err) { 91 t.Errorf("target binary doesn't exist") 92 } 93 } 94 95 func archChar() string { 96 switch runtime.GOARCH { 97 case "386": 98 return "8" 99 case "amd64": 100 return "6" 101 case "arm": 102 return "5" 103 } 104 panic("unknown arch " + runtime.GOARCH) 105 }