Skip to content

Commit

Permalink
fix(windows): ability to pass in network and address into Pact DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 21, 2017
1 parent e97226d commit 0bcca95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions dsl/pact.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ type Pact struct {
// Specify which version of the Pact Specification should be used (1 or 2).
// Defaults to 2.
SpecificationVersion int

// Host is the address of the Daemon, Mock and Verification Service runs on
// Examples include 'localhost', '127.0.0.1', '[::1]'
// Defaults to 'localhost'
Host string

// Network is the network of the Daemon, Mock and Verification Service
// Examples include 'tcp', 'tcp4', 'tcp6'
// Defaults to 'tcp'
Network string
}

// AddInteraction creates a new Pact interaction, initialising all
Expand All @@ -71,6 +81,14 @@ func (p *Pact) Setup() *Pact {
log.Printf("[DEBUG] pact setup")
dir, _ := os.Getwd()

if p.Network == "" {
p.Network = "tcp"
}

if p.Host == "" {
p.Host = "localhost"
}

if p.LogDir == "" {
p.LogDir = fmt.Sprintf(filepath.Join(dir, "logs"))
}
Expand All @@ -96,7 +114,7 @@ func (p *Pact) Setup() *Pact {
"--provider",
p.Provider,
}
client := &PactClient{Port: p.Port}
client := &PactClient{Port: p.Port, Network: p.Network, Address: p.Host}
p.pactClient = client
p.Server = client.StartServer(args)
}
Expand Down Expand Up @@ -136,7 +154,7 @@ func (p *Pact) Verify(integrationTest func() error) error {
p.Setup()
log.Printf("[DEBUG] pact verify")
mockServer := &MockService{
BaseURL: fmt.Sprintf("http://localhost:%d", p.Server.Port),
BaseURL: fmt.Sprintf("http://%s:%d", p.Host, p.Server.Port),
Consumer: p.Consumer,
Provider: p.Provider,
}
Expand Down Expand Up @@ -170,7 +188,7 @@ func (p *Pact) WritePact() error {
p.Setup()
log.Printf("[DEBUG] pact write Pact file")
mockServer := MockService{
BaseURL: fmt.Sprintf("http://localhost:%d", p.Server.Port),
BaseURL: fmt.Sprintf("http://%s:%d", p.Host, p.Server.Port),
Consumer: p.Consumer,
Provider: p.Provider,
}
Expand Down
1 change: 1 addition & 0 deletions examples/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
Port: 6666, // Ensure this port matches the daemon port!
Consumer: "MyConsumer",
Provider: "MyProvider",
Host: "localhost",
}
defer pact.Teardown()

Expand Down

0 comments on commit 0bcca95

Please sign in to comment.