Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A fixed PORT should be honored for all tests in a test suite #475

Open
biggogibbo opened this issue Dec 27, 2024 · 0 comments
Open

A fixed PORT should be honored for all tests in a test suite #475

biggogibbo opened this issue Dec 27, 2024 · 0 comments

Comments

@biggogibbo
Copy link

biggogibbo commented Dec 27, 2024

Expected behaviour

If I create a consumer PACT with a fixed port, then this port should be used for all tests in the test suite, not just one

Actual behaviour

Only the first test of the test suite gets the fixed port, after that all other tests will get a randomised port

Steps to reproduce

Firstly I need to use a fixed port as I am testing a dockerised service that is prebuilt and I cannot dynamically change the port.

Using the PACT workshop as an example - https://github.com/pact-foundation/pact-workshop-go/blob/master/consumer/client/client_pact_test.go

I modified this test and fix the port to be 9999 and in the ExecuteTest method I use 9999 as the port rather than config.Port

//go:build integration

package client

import (
    "fmt"
    "net/url"
    "os"
    "strconv"
    "testing"

    "github.com/pact-foundation/pact-go/v2/consumer"
    "github.com/pact-foundation/pact-go/v2/log"
    "github.com/pact-foundation/pact-go/v2/matchers"
    "github.com/pact-foundation/pact-workshop-go/model"
    "github.com/stretchr/testify/assert"
)

var Like = matchers.Like
var EachLike = matchers.EachLike
var Term = matchers.Term
var Regex = matchers.Regex
var HexValue = matchers.HexValue
var Identifier = matchers.Identifier
var IPAddress = matchers.IPAddress
var IPv6Address = matchers.IPv6Address
var Timestamp = matchers.Timestamp
var Date = matchers.Date
var Time = matchers.Time
var UUID = matchers.UUID
var ArrayMinLike = matchers.ArrayMinLike

type S = matchers.S
type Map = matchers.MapMatcher

var u *url.URL
var client *Client`

func TestClientPact_GetUser(t *testing.T) {

    log.SetLogLevel("INFO")
    mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
        Consumer: os.Getenv("CONSUMER_NAME"),
        Provider: os.Getenv("PROVIDER_NAME"),
        LogDir:   os.Getenv("LOG_DIR"),
        PactDir:  os.Getenv("PACT_DIR"),
        Port:     9999,  // attempting to fix the port to 9999
    })
    assert.NoError(t, err)

    t.Run("the user exists", func(t *testing.T) {
        id := 10
        err = mockProvider.
            AddInteraction().
            Given("User sally exists").
            UponReceiving("A request to login with user 'sally'").
            WithRequestPathMatcher("GET", Regex("/user/"+strconv.Itoa(id), "/user/[0-9]+"), func(b *consumer.V2RequestBuilder) {
                b.Header("Authorization", Like("Bearer 2019-01-01"))
            }).
            WillRespondWith(200, func(b *consumer.V2ResponseBuilder) {
                b.BodyMatch(model.User{}).
                    Header("Content-Type", Term("application/json", `application\/json`)).
                    Header("X-Api-Correlation-Id", Like("100"))
            }).
            ExecuteTest(t, func(config consumer.MockServerConfig) error {
                // Act: test our API client behaves correctly

                // Get the Pact mock server URL
                u, _ = url.Parse("http://" + config.Host + ":" + strconv.Itoa(9999)) // hardcoded Port to 9999

                // Initialise the API client and point it at the Pact mock server
                client = &Client{
                    BaseURL: u,
                }

                // // Execute the API client
                user, err := client.WithToken("2019-01-01").GetUser(id)

                // // Assert basic fact
                if user.ID != id {
                    return fmt.Errorf("wanted user with ID %d but got %d", id, user.ID)
                }

                return err
            })

        assert.NoError(t, err)

    })

    t.Run("the user does not exist", func(t *testing.T) {
        id := 10
        err = mockProvider.
            AddInteraction().
            Given("User sally does not exist").
            UponReceiving("A request to login with user 'sally'").
            WithRequestPathMatcher("GET", Regex("/user/"+strconv.Itoa(id), "/user/[0-9]+"), func(b *consumer.V2RequestBuilder) {
                b.Header("Authorization", Like("Bearer 2019-01-01"))
            }).
            WillRespondWith(404, func(b *consumer.V2ResponseBuilder) {
                b.Header("Content-Type", Term("application/json", `application\/json`)).
                    Header("X-Api-Correlation-Id", Like("100"))
            }).
            ExecuteTest(t, func(config consumer.MockServerConfig) error {
                // Act: test our API client behaves correctly

                // Get the Pact mock server URL
                u, _ = url.Parse("http://" + config.Host + ":" + strconv.Itoa(9999)) // hardcoded Port to 9999

                // Initialise the API client and point it at the Pact mock server
                client = &Client{
                    BaseURL: u,
                }

                // // Execute the API client
                _, err := client.WithToken("2019-01-01").GetUser(id)
                assert.Equal(t, ErrNotFound, err)
                return nil
            })
        assert.NoError(t, err)

    })
    t.Run("not authenticated", func(t *testing.T) {
        id := 10
        err = mockProvider.
            AddInteraction().
            Given("User is not authenticated").
            UponReceiving("A request to login with user 'sally'").
            WithRequestPathMatcher("GET", Regex("/user/"+strconv.Itoa(id), "/user/[0-9]+")).
            WillRespondWith(401, func(b *consumer.V2ResponseBuilder) {
                b.Header("Content-Type", Term("application/json", `application\/json`)).
                    Header("X-Api-Correlation-Id", Like("100"))
            }).
            ExecuteTest(t, func(config consumer.MockServerConfig) error {
                // Act: test our API client behaves correctly

                // Get the Pact mock server URL
                u, _ = url.Parse("http://" + config.Host + ":" + strconv.Itoa(9999)) // hardcoded Port to 9999

                // Initialise the API client and point it at the Pact mock server
                client = &Client{
                    BaseURL: u,
                }

                // // Execute the API client
                _, err := client.WithToken("").GetUser(id)
                assert.Equal(t, ErrUnauthorized, err)
                return nil
            })

    })

}

The first test passes, but all other tests fail due to the server being started on randomised ports. If I run each test independently, then they all work fine.
When I run in Debug then I can see the config.Port is set to 9999 for the first test, but the second test the config.Port is a random port.
I believe the error is due to the reset() function in this code - https://github.com/pact-foundation/pact-go/blob/master/consumer/http.go
The reset function is run in between tests and currently it will resets the config.Port to 0 (see line 182 as of Dec 27 2024), so any test suite with more than one test will end up having a randomised port.
There is a work around, which is a bit messy and that is to define the mock provider for each test
eg

func TestClientPact_GetUser(t *testing.T) {

    log.SetLogLevel("INFO")
    // WE CANT USE A SINGLE DEFINITION HERE, EACH TEST NEEDS ITS OWN TO ENSURE THE PORT IS FIXED 
    //mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
    //    Consumer: os.Getenv("CONSUMER_NAME"),
    //    Provider: os.Getenv("PROVIDER_NAME"),
    //    LogDir:   os.Getenv("LOG_DIR"),
    //    PactDir:  os.Getenv("PACT_DIR"),
    //    Port:     9999,
    //})
    //assert.NoError(t, err)

    t.Run("the user exists", func(t *testing.T) {
        id := 10
        // TEST SPECIFIC mockProvider
        mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
            Consumer: "TEST-CONSUMER",
            Provider: "TEST-PROVIDER",
            LogDir:   os.Getenv("LOG_DIR"),
            PactDir:  os.Getenv("PACT_DIR"),
            Port:     9999,
        })
        assert.NoError(t, err)
        err = mockProvider.
            AddInteraction().
            Given("User sally exists").
            UponReceiving("A request to login with user 'sally'").
            WithRequestPathMatcher("GET", Regex("/user/"+strconv.Itoa(id), "/user/[0-9]+"), func(b *consumer.V2RequestBuilder) {
                b.Header("Authorization", Like("Bearer 2019-01-01"))
            }).
            WillRespondWith(200, func(b *consumer.V2ResponseBuilder) {
                b.BodyMatch(model.User{}).
                    Header("Content-Type", Term("application/json", `application\/json`)).
                    Header("X-Api-Correlation-Id", Like("100"))
            }).
            ExecuteTest(t, func(config consumer.MockServerConfig) error {
                // Act: test our API client behaves correctly

                // Get the Pact mock server URL
                u, _ = url.Parse("http://" + config.Host + ":" + strconv.Itoa(9999))

                // Initialise the API client and point it at the Pact mock server
                client = &Client{
                    BaseURL: u,
                }

                // // Execute the API client
                user, err := client.WithToken("2019-01-01").GetUser(id)

                // // Assert basic fact
                if user.ID != id {
                    return fmt.Errorf("wanted user with ID %d but got %d", id, user.ID)
                }

                return err
            })

        assert.NoError(t, err)

    })

    t.Run("the user does not exist", func(t *testing.T) {
        id := 10
        // TEST SPECIFIC mockProvider
        mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
            Consumer: "TEST-CONSUMER",
            Provider: "TEST-PROVIDER",
            LogDir:   os.Getenv("LOG_DIR"),
            PactDir:  os.Getenv("PACT_DIR"),
            Port:     9999,
        })
        assert.NoError(t, err)
        err = mockProvider.
            AddInteraction().
            Given("User sally does not exist").
            UponReceiving("A request to login with user 'sally'").
            WithRequestPathMatcher("GET", Regex("/user/"+strconv.Itoa(id), "/user/[0-9]+"), func(b *consumer.V2RequestBuilder) {
                b.Header("Authorization", Like("Bearer 2019-01-01"))
            }).
            WillRespondWith(404, func(b *consumer.V2ResponseBuilder) {
                b.Header("Content-Type", Term("application/json", `application\/json`)).
                    Header("X-Api-Correlation-Id", Like("100"))
            }).
            ExecuteTest(t, func(config consumer.MockServerConfig) error {
                // Act: test our API client behaves correctly

                // Get the Pact mock server URL
                u, _ = url.Parse("http://" + config.Host + ":" + strconv.Itoa(9999))

                // Initialise the API client and point it at the Pact mock server
                client = &Client{
                    BaseURL: u,
                }

                // // Execute the API client
                _, err := client.WithToken("2019-01-01").GetUser(id)
                assert.Equal(t, ErrNotFound, err)
                return nil
            })
        assert.NoError(t, err)

    })
    t.Run("not authenticated", func(t *testing.T) {
        id := 10
        // TEST SPECIFIC mockProvider
        mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
            Consumer: "TEST-CONSUMER",
            Provider: "TEST-PROVIDER",
            LogDir:   os.Getenv("LOG_DIR"),
            PactDir:  os.Getenv("PACT_DIR"),
            Port:     9999,
        })
        assert.NoError(t, err)
        err = mockProvider.
            AddInteraction().
            Given("User is not authenticated").
            UponReceiving("A request to login with user 'sally'").
            WithRequestPathMatcher("GET", Regex("/user/"+strconv.Itoa(id), "/user/[0-9]+")).
            WillRespondWith(401, func(b *consumer.V2ResponseBuilder) {
                b.Header("Content-Type", Term("application/json", `application\/json`)).
                    Header("X-Api-Correlation-Id", Like("100"))
            }).
            ExecuteTest(t, func(config consumer.MockServerConfig) error {
                // Act: test our API client behaves correctly

                // Get the Pact mock server URL
                u, _ = url.Parse("http://" + config.Host + ":" + strconv.Itoa(9999))

                // Initialise the API client and point it at the Pact mock server
                client = &Client{
                    BaseURL: u,
                }

                // // Execute the API client
                _, err := client.WithToken("").GetUser(id)
                assert.Equal(t, ErrUnauthorized, err)
                return nil
            })

    })

}

`

Relevent log files

GOROOT=/opt/homebrew/opt/go/libexec #gosetup
GOPATH=/Users/blah/go #gosetup
/opt/homebrew/opt/go/libexec/bin/go test -c -tags integration -o /Users/blah/Library/Caches/JetBrains/IntelliJIdea2024.3/tmp/GoLand/___TestClientPact_GetUser_in_github_com_pact_foundation_pact_workshop_go_consumer_client.test github.com/pact-foundation/pact-workshop-go/consumer/client #gosetup
/opt/homebrew/opt/go/libexec/bin/go tool test2json -t /Users/blah/Library/Caches/JetBrains/IntelliJIdea2024.3/tmp/GoLand/___TestClientPact_GetUser_in_github_com_pact_foundation_pact_workshop_go_consumer_client.test -test.v=test2json -test.paniconexit0 -test.run ^\QTestClientPact_GetUser\E$ #gosetup
=== RUN TestClientPact_GetUser
2024/12/27 11:58:26 [DEBUG] pact setup
2024/12/27 11:58:26 [DEBUG] initialising native interface
2024/12/27 11:58:26 [DEBUG] initialised native log level to DEBUG (4)
2024/12/27 11:58:26 [DEBUG] initialised native log to log to stdout
2024/12/27 11:58:26 [DEBUG] log_to_stdout res 0
=== RUN TestClientPact_GetUser/the_user_exists
2024/12/27 11:58:26 [DEBUG] pact add V2 interaction
2024-12-27T11:58:26.263370Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.263703Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.263713Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("Bearer 2019-01-01")
2024-12-27T11:58:26.264059Z DEBUG ThreadId(01) pact_models::content_types: Detecting content type from contents: '{"firstName":{"specification":"2.0.0","pact:matcher:type":"type","value":"Sally"},"id":{"specification":"2.0.0","pact:matcher:type":"type","value":10},"lastName":{"specification":"2.0.0","pact:matcher:type":"type","value":"McSmiley Face😀😍"},"type":{"pact:matcher:type":"regex","value":"admin","regex":"^(admin|user|guest)$"},"username":{"specification":"2.0.0","pact:matcher:type":"type","value":"sally"}}'
2024-12-27T11:58:26.266169Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $
2024-12-27T11:58:26.266183Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Configuring a normal object
2024-12-27T11:58:26.266240Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.firstName
2024-12-27T11:58:26.266245Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-12-27T11:58:26.266264Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.id
2024-12-27T11:58:26.266266Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-12-27T11:58:26.266270Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.lastName
2024-12-27T11:58:26.266271Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-12-27T11:58:26.266274Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.type
2024-12-27T11:58:26.266275Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-12-27T11:58:26.266279Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: Path = $.username
2024-12-27T11:58:26.266280Z DEBUG ThreadId(01) pact_ffi::mock_server::bodies: detected pact:matcher:type, will configure a matcher
2024-12-27T11:58:26.266390Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.266396Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("application/json")
2024-12-27T11:58:26.266410Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.266414Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("100")
2024/12/27 11:58:26 [DEBUG] pact verify
2024/12/27 11:58:26 [DEBUG] mock server starting on address: 127.0.0.1:9999
2024-12-27T11:58:26.266775Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/transport/http
core/transport/https
2024-12-27T11:58:26.266809Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/content-generator/binary
core/content-generator/json
core/content-matcher/json
core/content-matcher/multipart-form-data
core/content-matcher/text
core/content-matcher/xml
2024-12-27T11:58:26.266834Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/matcher/v1-equality
core/matcher/v2-max-type
core/matcher/v2-min-type
core/matcher/v2-minmax-type
core/matcher/v2-regex
core/matcher/v2-type
core/matcher/v3-content-type
core/matcher/v3-date
core/matcher/v3-datetime
core/matcher/v3-decimal-type
core/matcher/v3-includes
core/matcher/v3-integer-type
core/matcher/v3-null
core/matcher/v3-number-type
core/matcher/v3-time
core/matcher/v4-array-contains
core/matcher/v4-equals-ignore-order
core/matcher/v4-max-equals-ignore-order
core/matcher/v4-min-equals-ignore-order
core/matcher/v4-minmax-equals-ignore-order
core/matcher/v4-not-empty
core/matcher/v4-semver
2024-12-27T11:58:26.267097Z DEBUG ThreadId(01) pact_mock_server::mock_server: Started mock server on 127.0.0.1:9999
2024/12/27 11:58:26 [DEBUG] mock server running on port: 9999
2024-12-27T11:58:26.267830Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 5 headers
2024-12-27T11:58:26.267835Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is empty
2024-12-27T11:58:26.267875Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Creating pact request from hyper request
2024-12-27T11:58:26.267881Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Extracting query from uri /user/10
2024-12-27T11:58:26.267895Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request GET /user/10
2024-12-27T11:58:26.267898Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server:
----------------------------------------------------------------------------------------
method: GET
path: /user/10
query: None
headers: Some({"authorization": ["Bearer 2019-01-01"], "accept": ["application/json"], "accept-encoding": ["gzip"], "user-agent": ["Admin Service"], "host": ["127.0.0.1:9999"]})
body: Empty
----------------------------------------------------------------------------------------

2024-12-27T11:58:26.267946Z DEBUG tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /user/10, query: None, headers: Some({"Authorization": ["Bearer 2019-01-01"]}), body: Missing )
2024-12-27T11:58:26.267951Z DEBUG tokio-runtime-worker pact_matching: body: ''
2024-12-27T11:58:26.267952Z DEBUG tokio-runtime-worker pact_matching: matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {DocPath { path_tokens: [Root], expr: "$" }: RuleList { rules: [Regex("/user/[0-9]+")], rule_logic: And, cascaded: false }} }, HEADER: MatchingRuleCategory { name: HEADER, rules: {DocPath { path_tokens: [Root, Field("Authorization")], expr: "$.Authorization" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }
2024-12-27T11:58:26.267990Z DEBUG tokio-runtime-worker pact_matching: generators: Generators { categories: {} }
2024-12-27T11:58:26.268108Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '/user/10' to '/user/10' ==> true cascaded=false matcher=Regex("/user/[0-9]+")
2024-12-27T11:58:26.268243Z DEBUG tokio-runtime-worker pact_matching: expected content type = '/', actual content type = '/'
2024-12-27T11:58:26.268269Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }'
2024-12-27T11:58:26.268282Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing 'Bearer 2019-01-01' to 'Bearer 2019-01-01' ==> true cascaded=false matcher=Type
2024-12-27T11:58:26.268287Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: []
2024-12-27T11:58:26.268310Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Test context = {"mockServer": Object {"port": Number(9999), "url": String("http://127.0.0.1:9999")}}
2024-12-27T11:58:26.268319Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response
2024-12-27T11:58:26.268321Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server:
----------------------------------------------------------------------------------------
status: 200
headers: Some({"X-Api-Correlation-Id": ["100"], "Content-Type": ["application/json"]})
body: Present(98 bytes, application/json)
----------------------------------------------------------------------------------------

2024-12-27T11:58:26.268349Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 477 bytes
2024/12/27 11:58:26 [DEBUG] mock server determining mismatches: 9999
2024/12/27 11:58:26 [DEBUG] mock server mismatches: 0
2024-12-27T11:58:26.268572Z DEBUG ThreadId(01) pact_ffi::plugins: pact_ffi::plugins::pactffi_cleanup_plugins FFI function invoked
2024/12/27 11:58:26 [DEBUG] write pact file
2024/12/27 11:58:26 [DEBUG] writing pact file for mock server on port: 9999 , dir: /Users/blah/SANDPIT/pact-workshop-go/consumer/client/pacts
2024-12-27T11:58:26.268590Z INFO ThreadId(01) pact_mock_server::mock_server: Writing pact out to '/Users/blah/SANDPIT/pact-workshop-go/consumer/client/pacts/-.json'
2024-12-27T11:58:26.268612Z DEBUG ThreadId(01) pact_models::pact: Merging pact with file "/Users/blah/SANDPIT/pact-workshop-go/consumer/client/pacts/-.json"
2024-12-27T11:58:26.269333Z WARN ThreadId(01) pact_models::pact: Note: Existing pact is an older specification version (V2), and will be upgraded
2024/12/27 11:58:26 [DEBUG] mock server cleaning up port: 9999
2024-12-27T11:58:26.269997Z DEBUG ThreadId(01) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2024-12-27T11:58:26.270002Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 3ec7a789-79ee-4266-9497-e7e7db99aae4 - MockServerMetrics { requests: 1, requests_by_path: {"/user/10": 1} }
2024-12-27T11:58:26.270006Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server 3ec7a789-79ee-4266-9497-e7e7db99aae4 shutdown - MockServerMetrics { requests: 1, requests_by_path: {"/user/10": 1} }
2024-12-27T11:58:26.270010Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown
2024-12-27T11:58:26.270055Z DEBUG ThreadId(01) pact_ffi::plugins: pact_ffi::plugins::pactffi_cleanup_plugins FFI function invoked
2024/12/27 11:58:26 [DEBUG] pact setup
2024/12/27 11:58:26 [DEBUG] initialising native interface
2024/12/27 11:58:26 [DEBUG] initialised native log level to DEBUG (4)
2024/12/27 11:58:26 [DEBUG] initialised native log to log to stdout
2024/12/27 11:58:26 [DEBUG] log_to_stdout res -1
2024/12/27 11:58:26 [ERROR] failed to log to stdout: can't set logger (applying the logger failed, perhaps because one is applied already).
--- PASS: TestClientPact_GetUser/the_user_exists (0.01s)
=== RUN TestClientPact_GetUser/the_user_does_not_exist
2024/12/27 11:58:26 [DEBUG] pact add V2 interaction
2024-12-27T11:58:26.270135Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270145Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270148Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("Bearer 2019-01-01")
2024-12-27T11:58:26.270157Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270160Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("application/json")
2024-12-27T11:58:26.270164Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270167Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("100")
2024/12/27 11:58:26 [DEBUG] pact verify
2024/12/27 11:58:26 [DEBUG] mock server starting on address: 127.0.0.1:0
2024-12-27T11:58:26.270220Z DEBUG ThreadId(01) pact_mock_server::mock_server: Started mock server on 127.0.0.1:60790
2024/12/27 11:58:26 [DEBUG] mock server running on port: 60790
client_pact_test.go:117:
Error Trace: /Users/blah/SANDPIT/pact-workshop-go/consumer/client/client_pact_test.go:117
/Users/blah/go/pkg/mod/github.com/pact-foundation/pact-go/[email protected]/consumer/http.go:152
/Users/blah/go/pkg/mod/github.com/pact-foundation/pact-go/[email protected]/consumer/http_v2.go:307
/Users/blah/SANDPIT/pact-workshop-go/consumer/client/client_pact_test.go:104
Error: Not equal:
expected: &errors.errorString{s:"not found"}
actual : &errors.errorString{s:"api unavailable"}

    	            	Diff:
    	            	--- Expected
    	            	+++ Actual
    	            	@@ -1,3 +1,3 @@
    	            	 (*errors.errorString)({
    	            	- s: (string) (len=9) "not found"
    	            	+ s: (string) (len=15) "api unavailable"
    	            	 })
    	Test:       	TestClientPact_GetUser/the_user_does_not_exist

2024/12/27 11:58:26 [DEBUG] mock server determining mismatches: 60790
2024/12/27 11:58:26 [DEBUG] mock server mismatches: 1

client_pact_test.go:104:
Pact Verification Failed for: TestClientPact_GetUser/the_user_does_not_exist

	Diff:

2024/12/27 11:58:26 [INFO] pact validation failed, errors:
expected: GET /user/10 (Expected request that was not received)

2024/12/27 11:58:26 [DEBUG] mock server cleaning up port: 60790
2024-12-27T11:58:26.270695Z DEBUG ThreadId(01) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2024-12-27T11:58:26.270698Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID d0acbf0d-1a08-45d0-b8fe-eb0722493f21 - MockServerMetrics { requests: 0, requests_by_path: {} }
2024-12-27T11:58:26.270701Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server d0acbf0d-1a08-45d0-b8fe-eb0722493f21 shutdown - MockServerMetrics { requests: 0, requests_by_path: {} }
2024-12-27T11:58:26.270705Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown
2024-12-27T11:58:26.270724Z DEBUG ThreadId(01) pact_ffi::plugins: pact_ffi::plugins::pactffi_cleanup_plugins FFI function invoked
2024/12/27 11:58:26 [DEBUG] pact setup
2024/12/27 11:58:26 [DEBUG] initialising native interface
2024/12/27 11:58:26 [DEBUG] initialised native log level to DEBUG (4)
2024/12/27 11:58:26 [DEBUG] initialised native log to log to stdout
2024/12/27 11:58:26 [DEBUG] log_to_stdout res -1
2024/12/27 11:58:26 [ERROR] failed to log to stdout: can't set logger (applying the logger failed, perhaps because one is applied already).
client_pact_test.go:120:
Error Trace: /Users/blah/SANDPIT/pact-workshop-go/consumer/client/client_pact_test.go:120
Error: Received unexpected error:
pact validation failed: false [{Request:{Method:GET Path:/user/10 Query: Headers:map[] Body:} Mismatches:[] Type:missing-request}]
Test: TestClientPact_GetUser/the_user_does_not_exist
--- FAIL: TestClientPact_GetUser/the_user_does_not_exist (0.00s)

Expected :GET /user/10 (Expected request that was not received)
Actual :&errors.errorString{s:"api unavailable"}

=== RUN TestClientPact_GetUser/not_authenticated
2024/12/27 11:58:26 [DEBUG] pact add V2 interaction
2024-12-27T11:58:26.270793Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270802Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270806Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("application/json")
2024-12-27T11:58:26.270810Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure any matchers
2024-12-27T11:58:26.270813Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: parsed header value: Left("100")
2024/12/27 11:58:26 [DEBUG] pact verify
2024/12/27 11:58:26 [DEBUG] mock server starting on address: 127.0.0.1:0
2024-12-27T11:58:26.270846Z DEBUG ThreadId(01) pact_mock_server::mock_server: Started mock server on 127.0.0.1:60792
2024/12/27 11:58:26 [DEBUG] mock server running on port: 60792
client_pact_test.go:147:
Error Trace: /Users/blah/SANDPIT/pact-workshop-go/consumer/client/client_pact_test.go:147
/Users/blah/go/pkg/mod/github.com/pact-foundation/pact-go/[email protected]/consumer/http.go:152
/Users/blah/go/pkg/mod/github.com/pact-foundation/pact-go/[email protected]/consumer/http_v2.go:307
/Users/blah/SANDPIT/pact-workshop-go/consumer/client/client_pact_test.go:134
Error: Not equal:
expected: &errors.errorString{s:"unauthorized"}
actual : &errors.errorString{s:"api unavailable"}

    	            	Diff:
    	            	--- Expected
    	            	+++ Actual
    	            	@@ -1,3 +1,3 @@
    	            	 (*errors.errorString)({
    	            	- s: (string) (len=12) "unauthorized"
    	            	+ s: (string) (len=15) "api unavailable"
    	            	 })
    	Test:       	TestClientPact_GetUser/not_authenticated

2024/12/27 11:58:26 [DEBUG] mock server determining mismatches: 60792
2024/12/27 11:58:26 [DEBUG] mock server mismatches: 1

client_pact_test.go:134:
Pact Verification Failed for: TestClientPact_GetUser/not_authenticated

	Diff:

2024/12/27 11:58:26 [INFO] pact validation failed, errors:
expected: GET /user/10 (Expected request that was not received)

2024/12/27 11:58:26 [DEBUG] mock server cleaning up port: 60792
2024-12-27T11:58:26.271077Z DEBUG ThreadId(03) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2024-12-27T11:58:26.271080Z DEBUG ThreadId(03) pact_mock_server::server_manager: Shutting down mock server with ID fadc2aa6-a7bf-49f4-865d-dd68f8571f9f - MockServerMetrics { requests: 0, requests_by_path: {} }
2024-12-27T11:58:26.271082Z DEBUG ThreadId(03) pact_mock_server::mock_server: Mock server fadc2aa6-a7bf-49f4-865d-dd68f8571f9f shutdown - MockServerMetrics { requests: 0, requests_by_path: {} }
2024-12-27T11:58:26.271087Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown
2024-12-27T11:58:26.271107Z DEBUG ThreadId(03) pact_ffi::plugins: pact_ffi::plugins::pactffi_cleanup_plugins FFI function invoked
2024/12/27 11:58:26 [DEBUG] pact setup
2024/12/27 11:58:26 [DEBUG] initialising native interface
2024/12/27 11:58:26 [DEBUG] initialised native log level to DEBUG (4)
2024/12/27 11:58:26 [DEBUG] initialised native log to log to stdout
2024/12/27 11:58:26 [DEBUG] log_to_stdout res -1
2024/12/27 11:58:26 [ERROR] failed to log to stdout: can't set logger (applying the logger failed, perhaps because one is applied already).
--- FAIL: TestClientPact_GetUser/not_authenticated (0.00s)

Expected :GET /user/10 (Expected request that was not received)
Actual :&errors.errorString{s:"api unavailable"}

--- FAIL: TestClientPact_GetUser (0.01s)

FAIL

Process finished with the exit code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant