Skip to content

Commit

Permalink
add .travis.yml for Travis CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Savintsev committed Feb 2, 2015
1 parent dca96f5 commit 246d34c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -0,0 +1 @@
language: go
21 changes: 14 additions & 7 deletions utils.go
Expand Up @@ -166,22 +166,29 @@ func CheckPath(path string) (err error) {
// $GOPATH/src/github.com/yahoo/webselab/templates if $GOPATH is set
// and the webseclab directory is present
// or an empty string
func TemplateBaseDefault() string {
func TemplateBaseDefault() (s string, err error) {
pwd, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Printf("Unable to get the current directory in TemplateBaseDefault, returning empty string: %s\n", err)
return ""
return "", err
}
if CheckPath(path.Join(pwd, "templates")) == nil {
return path.Join(pwd, "templates")
return path.Join(pwd, "templates"), nil
}
gopath := os.Getenv("GOPATH")

if gopath == "" {
return ""
return "", errors.New("No GOPATH in the environment in TemplateBaseDefault, bailing out")
}
// fix-up for the case (as with Travis) that GOPATH ends with the ':'
// - colon separator
if strings.HasSuffix(gopath, ":") {
gopath = gopath[:len(gopath)-1]
}
base := path.Join(gopath, "src/github.com/yahoo/webseclab/templates")
if CheckPath(base) == nil {
return base
err = CheckPath(base)
if err == nil {
return base, nil
}
return ""
return "", err
}
17 changes: 14 additions & 3 deletions utils_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"testing"
)

Expand All @@ -33,9 +34,19 @@ func TestCheckPathReal(t *testing.T) {

func TestTemplateBaseDefault(t *testing.T) {
t.Parallel()
base := TemplateBaseDefault()
want := path.Join(os.Getenv("GOPATH"), "src/github.com/yahoo/webseclab/templates")
base, err := TemplateBaseDefault()
if err != nil {
t.Errorf("Error in TemplateBaseDefault call: %s\n", err)
return
}
gopath := os.Getenv("GOPATH")
// fix-up for the case (as with Travis) that GOPATH ends with the ':'
// - colon separator
if strings.HasSuffix(gopath, ":") {
gopath = gopath[0 : len(gopath)-1]
}
want := path.Join(gopath, "src/github.com/yahoo/webseclab/templates")
if base != want {
t.Errorf("Expecting template base %s\n", want)
t.Errorf("Want template base %s, got %s\n", want, base)
}
}
7 changes: 5 additions & 2 deletions webseclab/main.go
Expand Up @@ -33,7 +33,10 @@ func main() {
cpus = 2
}
runtime.GOMAXPROCS(cpus)
defaultBase := webseclab.TemplateBaseDefault()
defaultBase, err := webseclab.TemplateBaseDefault()
if err != nil {
panic(err)
}
base := flag.String("base", defaultBase, "base path for webseclab templates")
port := flag.String("http", ":8080", "port to run the webserver on")
cleanup := flag.Bool("cleanup", false, "cleanup only (terminate existing instance and exit)")
Expand All @@ -58,7 +61,7 @@ func main() {
if *cleanup {
return
}
err := webseclab.ParseTemplates(abspath)
err = webseclab.ParseTemplates(abspath)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 246d34c

Please sign in to comment.