From 8b8fba2965f38a934fa3690ec250f0403ae264c9 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Tue, 8 Aug 2017 19:49:06 +1000 Subject: [PATCH] feat(examples): run examples as part of CI --- dsl/pact_integration_test.go | 125 ++++++++++++++++++----------------- scripts/pact.ps1 | 19 +----- scripts/pact.sh | 38 ++++++++--- 3 files changed, 98 insertions(+), 84 deletions(-) diff --git a/dsl/pact_integration_test.go b/dsl/pact_integration_test.go index 4bddce588..e7a67e046 100644 --- a/dsl/pact_integration_test.go +++ b/dsl/pact_integration_test.go @@ -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 @@ -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, @@ -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), @@ -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) + } + } + */ } } diff --git a/scripts/pact.ps1 b/scripts/pact.ps1 index 48e49bad2..caa8a7c6f 100644 --- a/scripts/pact.ps1 +++ b/scripts/pact.ps1 @@ -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 @@ -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" diff --git a/scripts/pact.sh b/scripts/pact.sh index 02ec80a6d..155417bec 100755 --- a/scripts/pact.sh +++ b/scripts/pact.sh @@ -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" @@ -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 \ No newline at end of file +exit $exitCode \ No newline at end of file