Skip to content

Commit

Permalink
feat(examples): run examples as part of CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Aug 14, 2017
1 parent 18dfef7 commit 8b8fba2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 84 deletions.
125 changes: 65 additions & 60 deletions dsl/pact_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ var dir, _ = os.Getwd()
var pactDir = fmt.Sprintf("%s/../pacts", dir)
var logDir = fmt.Sprintf("%s/../log", dir)

var name = "Jean-Marie de La Beaujardière😀😍"
// var name = "Jean-Marie de La Beaujardière😀😍"
var name = "billy"

// var name = "boring names"

func TestPact_Integration(t *testing.T) {
func TestPactIntegration_Consumer(t *testing.T) {
// Enable when running E2E/integration tests before a release
if os.Getenv("PACT_INTEGRATED_TESTS") != "" {

// Setup Provider API for verification (later...)
providerPort, _ := utils.GetFreePort()
go setupProviderAPI(providerPort)
pactDaemonPort := 6666

// Create Pact connecting to local Daemon
Expand Down Expand Up @@ -135,14 +131,21 @@ func TestPact_Integration(t *testing.T) {
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
})
}
}

func TestPactIntegration_Provider(t *testing.T) {
// Enable when running E2E/integration tests before a release
if os.Getenv("PACT_INTEGRATED_TESTS") != "" {

// Setup Provider API for verification (later...)
providerPort, _ := utils.GetFreePort()
go setupProviderAPI(providerPort)
pactDaemonPort := 6666

// Wait for Provider to come up
waitForPortInTest(providerPort, t)

if err != nil {
t.Fatalf("Error: %v", err)
}

// Verify the Provider - local Pact Files
providerPact := Pact{
Port: pactDaemonPort,
Expand All @@ -152,7 +155,7 @@ func TestPact_Integration(t *testing.T) {
LogDir: logDir,
PactDir: pactDir,
}
err = providerPact.VerifyProvider(types.VerifyRequest{
err := providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
PactURLs: []string{filepath.ToSlash(fmt.Sprintf("%s/billy-bobby.json", pactDir))},
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
Expand All @@ -163,54 +166,56 @@ func TestPact_Integration(t *testing.T) {
if err != nil {
t.Fatal("Error:", err)
}

// Verify the Provider - Specific Published Pacts
err = providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
PactURLs: []string{fmt.Sprintf("%s/pacts/provider/bobby/consumer/billy/latest/sit4", brokerHost)},
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
Verbose: true,
})

if err != nil {
t.Fatal("Error:", err)
}

// Verify the Provider - Latest Published Pacts for any known consumers
err = providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
BrokerURL: brokerHost,
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
Verbose: true,
})

if err != nil {
t.Fatal("Error:", err)
}

// Verify the Provider - Tag-based Published Pacts for any known consumers
err = providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
BrokerURL: brokerHost,
Tags: []string{"latest", "sit4"},
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
})

if err != nil {
t.Fatal("Error:", err)
}
/*
// Verify the Provider - Specific Published Pacts
err = providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
PactURLs: []string{fmt.Sprintf("%s/pacts/provider/bobby/consumer/billy/latest/sit4", brokerHost)},
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
Verbose: true,
})
if err != nil {
t.Fatal("Error:", err)
}
// Verify the Provider - Latest Published Pacts for any known consumers
err = providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
BrokerURL: brokerHost,
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
Verbose: true,
})
if err != nil {
t.Fatal("Error:", err)
}
// Verify the Provider - Tag-based Published Pacts for any known consumers
err = providerPact.VerifyProvider(types.VerifyRequest{
ProviderBaseURL: fmt.Sprintf("http://localhost:%d", providerPort),
ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d/setup", providerPort),
BrokerURL: brokerHost,
Tags: []string{"latest", "sit4"},
BrokerUsername: os.Getenv("PACT_BROKER_USERNAME"),
BrokerPassword: os.Getenv("PACT_BROKER_PASSWORD"),
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
})
if err != nil {
t.Fatal("Error:", err)
}
}
*/
}
}

Expand Down
19 changes: 3 additions & 16 deletions scripts/pact.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,8 @@ Write-Verbose " Starting pact daemon in background"
Start-Process -FilePath "$pactDir\pact-go.exe" -ArgumentList "daemon -v -l DEBUG" -RedirectStandardOutput "pacte-2e.log" -RedirectStandardError "pact-e2e-error.log"
$env:PACT_INTEGRATED_TESTS=1
cd "$env:GOPATH\src\github.com\pact-foundation\pact-go\dsl"
go test -v -run TestPact_Integration
if ($LastExitCode -ne 0) {
Write-Verbose " ERROR: Test failed, logging failure"
$exitCode=1
}
Write-Verbose "Stop Pact..."
Stop-Process -Name ruby
Stop-Process -Name pact-go

Write-Verbose "--> Testing E2E (SECOND TIME)"
Write-Verbose " Starting pact daemon in background"
Start-Process -FilePath "$pactDir\pact-go.exe" -ArgumentList "daemon -v -l DEBUG" -RedirectStandardOutput "pact.log" -RedirectStandardError "pact-error.log"
$env:PACT_INTEGRATED_TESTS=1
cd "$env:GOPATH\src\github.com\pact-foundation\pact-go\dsl"
go test -v -run TestPact_Integration
go test -v -run TestPactIntegration_Consumer
go test -v -run TestPactIntegration_Provider
if ($LastExitCode -ne 0) {
Write-Verbose " ERROR: Test failed, logging failure"
$exitCode=1
Expand All @@ -88,7 +75,7 @@ Stop-Process -Name pact-go
Write-Verbose "--> Testing examples"
Write-Verbose " Starting pact daemon in background"
Start-Process -FilePath "$pactDir\pact-go.exe" -ArgumentList "daemon -v -l DEBUG" -RedirectStandardOutput "pact-examples.log" -RedirectStandardError "pact-examples-error.log"
$examples=@("github.com/pact-foundation/pact-go/examples/consumer/goconsumer", "github.com/pact-foundation/pact-go/examples/go-kit/provider", "github.com/pact-foundation/pact-go/examples/mux/provider")
$examples=@("github.com/pact-foundation/pact-go/examples/consumer/goconsumer", "github.com/pact-foundation/pact-go/examples/go-kit/provider", "github.com/pact-foundation/pact-go/examples/mux/provider", "github.com/pact-foundation/pact-go/examples/gin/provider")
foreach ($example in $examples) {
Write-Verbose " Installing dependencies for example: $example"
cd "$env:GOPATH\src\$example"
Expand Down
38 changes: 30 additions & 8 deletions scripts/pact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ LIBDIR=$(dirname "$0")

trap shutdown INT
CUR_DIR=$(pwd)
exitCode=0

function shutdown() {
step "Shutting down stub server"
log "Finding Pact daemon PID"
Expand Down Expand Up @@ -46,30 +48,50 @@ if [ ! -f "dist/pact-go" ]; then
exit 1
fi

cd ..
log "Done"
log "Done!"
fi

step "Starting Daemon"
mkdir -p ./logs
./dist/pact-go daemon -v -l DEBUG > logs/daemon.log 2>&1 &

step "Running integration tests"
step "Running E2E regression tests"
export PACT_INTEGRATED_TESTS=1
export PACT_BROKER_HOST="https://test.pact.dius.com.au"
export PACT_BROKER_USERNAME="dXfltyFMgNOFZAxr8io9wJ37iUpY42M"
export PACT_BROKER_PASSWORD="O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"
cd dsl
go test -v -run TestPact_Integration
SCRIPT_STATUS=$?
cd "${GOPATH}/src/github.com/pact-foundation/pact-go/dsl"
go test -v -run TestPactIntegration_Consumer
go test -v -run TestPactIntegration_Provider
if [ $? -ne 0 ]; then
log "ERROR: Test failed, logging failure"
exitCode=1
fi

step "Running example projects"
examples=("github.com/pact-foundation/pact-go/examples/consumer/goconsumer" "github.com/pact-foundation/pact-go/examples/go-kit/provider" "github.com/pact-foundation/pact-go/examples/mux/provider" "github.com/pact-foundation/pact-go/examples/gin/provider")

for example in "${examples[@]}"
do
log "Installing dependencies for example: $example"
cd "${GOPATH}/src/${example}"
go get ./...

log "Running tests for $example"
go test -v .
if [ $? -ne 0 ]; then
log "ERROR: Test failed, logging failure"
exitCode=1
fi
done
cd ..

shutdown

if [ "${SCRIPT_STATUS}" = "0" ]; then
if [ "${exitCode}" = "0" ]; then
step "Integration testing succeeded!"
else
step "Integration testing failed, see stack trace above"
fi

exit $SCRIPT_STATUS
exit $exitCode

0 comments on commit 8b8fba2

Please sign in to comment.