Skip to content

pact-go v2.0.x requires CGO #321

@StephanHCB

Description

@StephanHCB

We tried updating our pact-go contract tests to v2.0.1, and saw that pact-go now apparently requires a C compiler to run.

Is there any chance this could be avoided? There are lots of systems and containerized build environments that do not have or want a C compiler.

We tried setting CGO_ENABLED=0, but since no pure go alternative is provided in the code, this did not help either.

Software versions

  • OS: Windows 10 (also happens on our Linux build containers based on the official golang image)
  • Consumer Pact library: Pact go v2.0.1
  • Provider Pact library: Pact go v2.0.1
  • Golang Version: go1.20 windows/amd64 (also on linux)
  • Golang environment: (irrelevant)

Expected behaviour

A simple consumer test that makes a single HTTP get request works.

Actual behaviour

go compile fails

# github.com/pact-foundation/pact-go/v2/consumer
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:82:31: undefined: native.MockServer
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:114:24: undefined: native.NewHTTPPact
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:117:48: undefined: native.SPECIFICATION_VERSION_V2
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:119:48: undefined: native.SPECIFICATION_VERSION_V3
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:121:48: undefined: native.SPECIFICATION_VERSION_V4
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:123:9: undefined: native.Init
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http.go:316:16: undefined: native.GetTLSConfig
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\interaction.go:16:35: undefined: mockserver.Interaction
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http_v4.go:461:65: undefined: native.INTERACTION_PART_REQUEST
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http_v4.go:542:65: undefined: native.INTERACTION_PART_RESPONSE
..\golang\gopath\pkg\mod\github.com\pact-foundation\pact-go\v2@v2.0.1\consumer\http_v4.go:542:65: too many errors

Steps to reproduce

Any http request consumer test will do this. Simple example:

package sample

import (
	"fmt"
	"net/http"
	"testing"

	"github.com/go-http-utils/headers"
	"github.com/pact-foundation/pact-go/v2/consumer"
	"github.com/pact-foundation/pact-go/v2/matchers"
)

func TestSampleConsumer(t *testing.T) {
	pact, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{
		Consumer: "sample",
		Provider: "sample-provider",
		Host:     "localhost",
	})
	if err != nil {
		t.FailNow()
	}

	var test = func(serverConfig consumer.MockServerConfig) error {
		requestUrl := fmt.Sprintf("http://localhost:%d/hello", serverConfig.Port)
		req, err := http.NewRequest(http.MethodGet, requestUrl, nil)
		if err != nil {
			return err
		}
		_, err = http.DefaultClient.Do(req)
		return err
	}

	err = pact.
		AddInteraction().
		Given("this test compiles").
		UponReceiving("A request for a greeting").
		WithCompleteRequest(consumer.Request{
			Method: http.MethodGet,
			Path:   matchers.String("/hello"),
		}).
		WithCompleteResponse(consumer.Response{
			Status:  200,
			Headers: matchers.MapMatcher{headers.ContentType: matchers.String("application/json")},
			Body: map[string]interface{}{
				"greeting": "hello",
			},
		}).
		ExecuteTest(t, test)
	if err != nil {
		t.FailNow()
	}
}

Relevent log files

No log file, the test fails to compile. Compile output see above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions