-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
439 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
package command | ||
|
||
import "testing" | ||
|
||
func init() { | ||
// os.Args = append(os.Args, "mock") | ||
// os.Args = append(os.Args, "--help") | ||
} | ||
|
||
func Test_PactMockServiceCommand(t *testing.T) { | ||
err := mockServiceCmd.Help() | ||
if err != nil { | ||
t.Fatalf("Error: %v", err) | ||
} | ||
|
||
// mockServiceCmd.Run(nil, os.Args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package command | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
// Set CLI flags to simulate real | ||
// os.Args = append(os.Args, "version") | ||
os.Args = []string{"version"} | ||
} | ||
|
||
func Test_VersionCommand(t *testing.T) { | ||
err := versionCmd.Execute() | ||
if err != nil { | ||
t.Fatalf("Error: %v", err) | ||
} | ||
versionCmd.Run(nil, os.Args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dsl | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"net/rpc" | ||
"time" | ||
|
||
"github.com/mefellows/pact-go/daemon" | ||
) | ||
|
||
// Client is the simplified remote interface to the Pact Daemon | ||
type Client interface { | ||
StartServer() *daemon.PactMockServer | ||
} | ||
|
||
// PactClient is the default implementation of the Client interface. | ||
type PactClient struct { | ||
port int | ||
} | ||
|
||
func getHTTPClient(port int) (*rpc.Client, error) { | ||
waitForPort(port) | ||
return rpc.DialHTTP("tcp", fmt.Sprintf(":%d", port)) | ||
} | ||
|
||
// Use this to wait for a daemon to be running prior | ||
// to running tests | ||
func waitForPort(port int) { | ||
fmt.Printf("client - Waiting for daemon port: %d", port) | ||
timeout := time.After(10 * time.Second) | ||
|
||
for { | ||
select { | ||
case <-timeout: | ||
log.Fatalf("Expected server to start < 1s.") | ||
case <-time.After(50 * time.Millisecond): | ||
_, err := net.Dial("tcp", fmt.Sprintf(":%d", port)) | ||
if err == nil { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
// StartServer starts a remote Pact Mock Server. | ||
func (p *PactClient) StartServer() *daemon.PactMockServer { | ||
var res daemon.PactMockServer | ||
client, err := getHTTPClient(p.port) | ||
if err != nil { | ||
log.Fatal("rpc error:", err) | ||
} | ||
err = client.Call("Daemon.StartServer", daemon.PactMockServer{}, &res) | ||
if err != nil { | ||
log.Fatal("rpc error:", err) | ||
} | ||
return &res | ||
} | ||
|
||
// ListServers starts a remote Pact Mock Server. | ||
func (p *PactClient) ListServers() *daemon.PactListResponse { | ||
var res daemon.PactListResponse | ||
client, err := getHTTPClient(p.port) | ||
err = client.Call("Daemon.ListServers", daemon.PactMockServer{}, &res) | ||
if err != nil { | ||
log.Fatal("rpc error:", err) | ||
} | ||
return &res | ||
} | ||
|
||
// StopServer stops a remote Pact Mock Server. | ||
func (p *PactClient) StopServer(server *daemon.PactMockServer) *daemon.PactMockServer { | ||
client, err := getHTTPClient(p.port) | ||
var res daemon.PactMockServer | ||
err = client.Call("Daemon.StopServer", server, &res) | ||
if err != nil { | ||
log.Fatal("rpc error:", err) | ||
} | ||
return &res | ||
} |
Oops, something went wrong.