Skip to content

Commit

Permalink
wip: commit to continue work on train 😬
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 18, 2018
1 parent 6c27acb commit b330414
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 806 deletions.
2 changes: 1 addition & 1 deletion daemon/mock_service.go → client/mock_service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import "testing"

Expand Down
2 changes: 1 addition & 1 deletion daemon/service.go → client/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"io"
Expand Down
2 changes: 1 addition & 1 deletion daemon/service_manager.go → client/service_manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion daemon/service_mock.go → client/service_mock.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"io"
Expand Down
37 changes: 36 additions & 1 deletion daemon/service_test.go → client/service_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"fmt"
Expand Down Expand Up @@ -175,3 +175,38 @@ func TestServiceManager_Start(t *testing.T) {
}
}
}

// Adapted from http://npf.io/2015/06/testing-exec-command/
var fakeExecSuccessCommand = func() *exec.Cmd {
return fakeExecCommand("", true, "")
}

var fakeExecFailCommand = func() *exec.Cmd {
return fakeExecCommand("", false, "")
}

func fakeExecCommand(command string, success bool, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestHelperProcess", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1", fmt.Sprintf("GO_WANT_HELPER_PROCESS_TO_SUCCEED=%t", success)}
return cmd
}

func TestHelperProcess(t *testing.T) {
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
<-time.After(250 * time.Millisecond)

// some code here to check arguments perhaps?
// Fail :(
if os.Getenv("GO_WANT_HELPER_PROCESS_TO_SUCCEED") == "false" {
fmt.Fprintf(os.Stdout, "COMMAND: oh noes!")
os.Exit(1)
}

// Success :)
fmt.Fprintf(os.Stdout, `{"summary_line":"1 examples, 0 failures"}`)
os.Exit(0)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package daemon
package client

import (
"fmt"
Expand Down
201 changes: 0 additions & 201 deletions daemon/daemon.go

This file was deleted.

Loading

0 comments on commit b330414

Please sign in to comment.