forked from pact-foundation/pact-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(windows): add Windows PoSH build script
- Runs examples as integration tests - Closes pact-foundation#28 - Closes pact-foundation#42
- Loading branch information
Showing
9 changed files
with
505 additions
and
429 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
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,41 +1,42 @@ | ||
version: "{build}" | ||
|
||
# fix lineendings in Windows | ||
# init: | ||
# - git config --global core.autocrlf input | ||
|
||
# Source Config | ||
clone_folder: c:\gopath\src\github.com\pact-foundation\pact-go | ||
|
||
# Build host | ||
|
||
environment: | ||
GOPATH: c:\gopath | ||
GOVERSION: 1.8 | ||
# PACT_INTEGRATED_TESTS: 0 | ||
PACT_BROKER_HOST: "https://test.pact.dius.com.au" | ||
PACT_BROKER_USERNAME: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M" | ||
PACT_BROKER_PASSWORD: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1" | ||
|
||
init: | ||
- git config --global core.autocrlf input | ||
|
||
# Build | ||
|
||
install: | ||
# Install the specific Go version. | ||
- rmdir c:\go /s /q | ||
- appveyor DownloadFile https://storage.googleapis.com/golang/go%GOVERSION%.windows-amd64.msi | ||
# Download the latest pact standalone | ||
- msiexec /i go%GOVERSION%.windows-amd64.msi /q | ||
- choco install bzr | ||
- set Path=c:\go\bin;c:\gopath\bin;C:\Program Files (x86)\Bazaar\;C:\Program Files\Mercurial\%Path% | ||
- go version | ||
- go env | ||
|
||
build: false | ||
deploy: false | ||
|
||
test_script: | ||
- go build -o /tmp/pact-go github.com/pact-foundation/pact-go | ||
- for /f "" %%G in ('go list github.com/pact-foundation/pact-go/... ^| find /i /v "/vendor/" ^| find /i /v "examples"') do ( go test -v %%G & IF ERRORLEVEL == 1 EXIT 1) | ||
version: "{build}" | ||
|
||
# fix lineendings in Windows | ||
# init: | ||
# - git config --global core.autocrlf input | ||
|
||
# Source Config | ||
clone_folder: c:\gopath\src\github.com\pact-foundation\pact-go | ||
|
||
# Build host | ||
|
||
|
||
environment: | ||
GOPATH: c:\gopath | ||
GOVERSION: 1.8 | ||
PACT_INTEGRATED_TESTS: 1 | ||
PACT_BROKER_HOST: "https://test.pact.dius.com.au" | ||
PACT_BROKER_USERNAME: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M" | ||
PACT_BROKER_PASSWORD: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1" | ||
|
||
init: | ||
- git config --global core.autocrlf input | ||
|
||
# Build | ||
|
||
install: | ||
# Install the specific Go version. | ||
- rmdir c:\go /s /q | ||
- appveyor DownloadFile https://storage.googleapis.com/golang/go%GOVERSION%.windows-amd64.msi | ||
# Download the latest pact standalone | ||
- msiexec /i go%GOVERSION%.windows-amd64.msi /q | ||
- choco install bzr | ||
- set Path=c:\go\bin;c:\gopath\bin;C:\Program Files (x86)\Bazaar\;C:\Program Files\Mercurial\%Path% | ||
- go version | ||
- go env | ||
|
||
build: false | ||
deploy: false | ||
|
||
test_script: | ||
- go build -o /tmp/pact-go github.com/pact-foundation/pact-go | ||
- c:\gopath\src\github.com\pact-foundation\pact-go\scripts\pact.ps1 |
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,97 +1,98 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/pact-foundation/pact-go/dsl" | ||
examples "github.com/pact-foundation/pact-go/examples/types" | ||
"github.com/pact-foundation/pact-go/types" | ||
"github.com/pact-foundation/pact-go/utils" | ||
) | ||
|
||
// The actual Provider test itself | ||
func TestPact_Provider(t *testing.T) { | ||
go startInstrumentedProvider() | ||
|
||
pact := createPact() | ||
|
||
// Verify the Provider with local Pact Files | ||
err := pact.VerifyProvider(types.VerifyRequest{ | ||
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port), | ||
PactURLs: []string{fmt.Sprintf("%s/billy-bobby.json", pactDir)}, | ||
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", port), | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal("Error:", err) | ||
} | ||
} | ||
|
||
// Starts the provider API with hooks for provider states. | ||
// This essentially mirrors the main.go file, with extra routes added. | ||
func startInstrumentedProvider() { | ||
router := gin.Default() | ||
router.POST("/users/login", UserLogin) | ||
router.POST("/setup", providerStateSetup) | ||
|
||
router.Run(fmt.Sprintf(":%d", port)) | ||
} | ||
|
||
// Set current provider state route. | ||
func providerStateSetup(c *gin.Context) { | ||
var state types.ProviderState | ||
if c.BindJSON(&state) == nil { | ||
// Setup database for different states | ||
if state.State == "User billy exists" { | ||
userRepository = billyExists | ||
} else if state.State == "User billy is unauthorized" { | ||
userRepository = billyUnauthorized | ||
} else { | ||
userRepository = billyDoesNotExist | ||
} | ||
} | ||
} | ||
|
||
// Configuration / Test Data | ||
var dir, _ = os.Getwd() | ||
var pactDir = fmt.Sprintf("%s/../../pacts", dir) | ||
var logDir = fmt.Sprintf("%s/log", dir) | ||
var port, _ = utils.GetFreePort() | ||
|
||
// Provider States data sets | ||
var billyExists = &examples.UserRepository{ | ||
Users: map[string]*examples.User{ | ||
"billy": &examples.User{ | ||
Name: "billy", | ||
Username: "billy", | ||
Password: "issilly", | ||
}, | ||
}, | ||
} | ||
|
||
var billyDoesNotExist = &examples.UserRepository{} | ||
|
||
var billyUnauthorized = &examples.UserRepository{ | ||
Users: map[string]*examples.User{ | ||
"billy": &examples.User{ | ||
Name: "billy", | ||
Username: "billy", | ||
Password: "issilly1", | ||
}, | ||
}, | ||
} | ||
|
||
// Setup the Pact client. | ||
func createPact() dsl.Pact { | ||
// Create Pact connecting to local Daemon | ||
return dsl.Pact{ | ||
Port: 6666, | ||
Consumer: "billy", | ||
Provider: "bobby", | ||
LogDir: logDir, | ||
PactDir: pactDir, | ||
} | ||
} | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/pact-foundation/pact-go/dsl" | ||
examples "github.com/pact-foundation/pact-go/examples/types" | ||
"github.com/pact-foundation/pact-go/types" | ||
"github.com/pact-foundation/pact-go/utils" | ||
) | ||
|
||
// The actual Provider test itself | ||
func TestPact_Provider(t *testing.T) { | ||
go startInstrumentedProvider() | ||
|
||
pact := createPact() | ||
|
||
// Verify the Provider with local Pact Files | ||
err := pact.VerifyProvider(types.VerifyRequest{ | ||
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port), | ||
PactURLs: []string{filepath.ToSlash(fmt.Sprintf("%s/billy-bobby.json", pactDir))}, | ||
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", port), | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal("Error:", err) | ||
} | ||
} | ||
|
||
// Starts the provider API with hooks for provider states. | ||
// This essentially mirrors the main.go file, with extra routes added. | ||
func startInstrumentedProvider() { | ||
router := gin.Default() | ||
router.POST("/users/login", UserLogin) | ||
router.POST("/setup", providerStateSetup) | ||
|
||
router.Run(fmt.Sprintf(":%d", port)) | ||
} | ||
|
||
// Set current provider state route. | ||
func providerStateSetup(c *gin.Context) { | ||
var state types.ProviderState | ||
if c.BindJSON(&state) == nil { | ||
// Setup database for different states | ||
if state.State == "User billy exists" { | ||
userRepository = billyExists | ||
} else if state.State == "User billy is unauthorized" { | ||
userRepository = billyUnauthorized | ||
} else { | ||
userRepository = billyDoesNotExist | ||
} | ||
} | ||
} | ||
|
||
// Configuration / Test Data | ||
var dir, _ = os.Getwd() | ||
var pactDir = fmt.Sprintf("%s/../../pacts", dir) | ||
var logDir = fmt.Sprintf("%s/log", dir) | ||
var port, _ = utils.GetFreePort() | ||
|
||
// Provider States data sets | ||
var billyExists = &examples.UserRepository{ | ||
Users: map[string]*examples.User{ | ||
"billy": &examples.User{ | ||
Name: "billy", | ||
Username: "billy", | ||
Password: "issilly", | ||
}, | ||
}, | ||
} | ||
|
||
var billyDoesNotExist = &examples.UserRepository{} | ||
|
||
var billyUnauthorized = &examples.UserRepository{ | ||
Users: map[string]*examples.User{ | ||
"billy": &examples.User{ | ||
Name: "billy", | ||
Username: "billy", | ||
Password: "issilly1", | ||
}, | ||
}, | ||
} | ||
|
||
// Setup the Pact client. | ||
func createPact() dsl.Pact { | ||
// Create Pact connecting to local Daemon | ||
return dsl.Pact{ | ||
Port: 6666, | ||
Consumer: "billy", | ||
Provider: "bobby", | ||
LogDir: logDir, | ||
PactDir: pactDir, | ||
} | ||
} |
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
Oops, something went wrong.