Skip to content

Commit

Permalink
better testing for scripts outside of GOPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmueller committed Dec 17, 2017
1 parent 9ee3e79 commit c230884
Show file tree
Hide file tree
Showing 29 changed files with 509 additions and 461 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ TEST:="./..."

test: embed
@echo "$(INFOLOG) Running go tests..."
@go list $(TEST) \
| grep -v "/vendor/" \
| xargs -n1 go test -timeout=5m -parallel=10 $(TESTARGS)
@go test -timeout=10m -parallel=10 $(TEST)
.PHONY: tests

# Install the commands.
Expand Down
20 changes: 2 additions & 18 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,12 @@ func Test(t *testing.T) {
t.Fatal(e)
}

root, err := paths.Joy()
chromePath, err := paths.Chrome()
if err != nil {
t.Fatal(err)
}

exists:
chromePath, err := chrome.Exists(path.Join(root, "chrome"))
if err != nil {
t.Fatal(err)
} else if chromePath == "" {
log.Infof("downloading headless chrome (this only needs to be done once)")
if err := chrome.Download(path.Join(root, "chrome")); err != nil {
t.Fatal(err)
}
goto exists
}

ch, err := chrome.New(ctx, &chrome.Settings{
ExecutablePath: chromePath,
Stderr: ioutil.Discard,
Stdout: ioutil.Discard,
})
ch, err := chrome.Start(ctx, chromePath)
if err != nil {
t.Fatal(err)
}
Expand Down
32 changes: 6 additions & 26 deletions api/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ type Config struct {
Context context.Context
Packages []string
Development bool
MacroPath string
RuntimePath string
StdPath string
JoyPath string
Log log.Interface // Log (optional)
}

Expand All @@ -32,28 +30,12 @@ func (c *Config) defaults() error {
c.Log = log.Log
}

if c.MacroPath == "" {
p, err := paths.Macro()
if c.JoyPath == "" {
p, err := paths.Joy()
if err != nil {
return errors.Wrapf(err, "error getting macro path")
return errors.Wrapf(err, "error getting joy's root path")
}
c.MacroPath = p
}

if c.RuntimePath == "" {
p, err := paths.Runtime()
if err != nil {
return errors.Wrapf(err, "error getting runtime path")
}
c.RuntimePath = p
}

if c.StdPath == "" {
p, err := paths.Stdlib()
if err != nil {
return errors.Wrapf(err, "error getting std path")
}
c.StdPath = p
c.JoyPath = p
}

return nil
Expand All @@ -73,9 +55,7 @@ func Build(cfg *Config) (scripts []*script.Script, err error) {
scripts, err = compiler.Compile(&compiler.Config{
Packages: packages,
Development: cfg.Development,
MacroPath: cfg.MacroPath,
RuntimePath: cfg.RuntimePath,
StdPath: cfg.StdPath,
JoyPath: cfg.JoyPath,
})
if err != nil {
return scripts, errors.Wrapf(err, "error compiling")
Expand Down
69 changes: 16 additions & 53 deletions api/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package run
import (
"context"
"fmt"
"path"

"github.com/apex/log"
"github.com/matthewmueller/joy/internal/mains"
Expand All @@ -18,10 +19,7 @@ type Config struct {
Context context.Context
FilePath string
Development bool
ChromePath string
MacroPath string
RuntimePath string
StdPath string
JoyPath string
Log log.Interface // Log (optional)
}

Expand All @@ -34,36 +32,12 @@ func (c *Config) defaults() error {
c.Log = log.Log
}

if c.MacroPath == "" {
p, err := paths.Macro()
if c.JoyPath == "" {
p, err := paths.Joy()
if err != nil {
return errors.Wrapf(err, "error getting macro path")
return errors.Wrapf(err, "error getting joy's root path")
}
c.MacroPath = p
}

if c.RuntimePath == "" {
p, err := paths.Runtime()
if err != nil {
return errors.Wrapf(err, "error getting runtime path")
}
c.RuntimePath = p
}

if c.StdPath == "" {
p, err := paths.Stdlib()
if err != nil {
return errors.Wrapf(err, "error getting std path")
}
c.StdPath = p
}

if c.ChromePath == "" {
p, err := paths.Chrome()
if err != nil {
return errors.Wrapf(err, "error getting chrome path")
}
c.ChromePath = p
c.JoyPath = p
}

return nil
Expand All @@ -82,10 +56,8 @@ func Run(cfg *Config) (result string, err error) {

files, err := compiler.Compile(&compiler.Config{
Packages: packages,
JoyPath: cfg.JoyPath,
Development: cfg.Development,
MacroPath: cfg.MacroPath,
RuntimePath: cfg.RuntimePath,
StdPath: cfg.StdPath,
})
if err != nil {
return result, errors.Wrapf(err, "unable to compile file")
Expand All @@ -94,31 +66,22 @@ func Run(cfg *Config) (result string, err error) {
}

// download chrome if it doesn't already exist
exists:
fullpath, err := chrome.Exists(cfg.ChromePath)
if err != nil {
return result, errors.Wrapf(err, "unable to get chrome path")
} else if fullpath == "" {
cfg.Log.Infof("downloading headless chrome (this only needs to be done once)")
if err := chrome.Download(cfg.ChromePath); err != nil {
return result, errors.Wrapf(err, "error downloading headless chrome")
}
goto exists
}

ch, err := chrome.New(cfg.Context, &chrome.Settings{
ExecutablePath: cfg.ChromePath,
})
ch, err := chrome.Start(cfg.Context, path.Join(cfg.JoyPath, "chrome"))
if err != nil {
return result, err
return result, errors.Wrapf(err, "error starting chrome")
}
defer ch.Close()

tar, err := ch.Target()
if err != nil {
return result, err
return result, errors.Wrapf(err, "error leasing target")
}
defer tar.Close()

return tar.Run(files[0].Source())
result, err = tar.Run(files[0].Source())
if err != nil {
return result, errors.Wrapf(err, "error running chrome target")
}

return result, nil
}
Loading

0 comments on commit c230884

Please sign in to comment.