Closed
Description
Software versions
- OS: e.g. Ubuntu 20.04.4 LTS
- Consumer Pact library: github.com/pact-foundation/pact-go/v2 v2.0.0-beta.10.0.20220204231251-6ec7402f4709
- Provider Pact library:
-
- Golang Version:
go version go1.18.1 linux/amd64
- Golang environment: ⬇
go env
❯ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/edouard/.cache/go-build" GOENV="/home/edouard/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/edouard/go/pkg/mod" GONOPROXY="git.manomano.tech" GONOSUMDB="git.manomano.tech" GOOS="linux" GOPATH="/home/edouard/go" GOPRIVATE="git.manomano.tech" GOPROXY="https://proxy.golang.org,direct" GOROOT="/snap/go/9605" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/snap/go/9605/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18.1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/edouard/projects/contract-testing/pact-consumer-example-for-go/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build240394958=/tmp/go-build -gno-record-gcc-switches"
Expected behaviour
Should lint file correctly
Actual behaviour
❯ make lint
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run --skip-dirs cmd/pactgoconsumerexample_tester
ERRO Running error: 1 error occurred:
* can't run linter goanalysis_metalinter: inspect: failed to load package sugar: could not load export data: no export data for "github.com/pact-foundation/pact-go/v2/sugar"
make: *** [Makefile:85: lint] Error 3
Steps to reproduce
Below is the file importing sugar
internal/b2b/b2b_contract_test.go
package b2bimport (
"context"
"fmt"
"net/http"
"os"
"testing""github.com/pact-foundation/pact-go/v2/sugar" "github.com/stretchr/testify/require"
)
func TestClientProduct(t *testing.T) {
mockProvider, err := sugar.NewV2Pact(sugar.MockHTTPProviderConfig{ Consumer: "ms.pact-consumer-example-for-go.b2b", Provider: "ms.pact-provider-example-for-go", PactDir: "../../contracts", }) require.NoError(t, err) t.Run("the product 1 exists", func(t *testing.T) { // Setup my expected interactions mockProvider.AddInteraction(). Given("A product with id 1 exists"). UponReceiving("a request Product 1"). WithRequest(http.MethodGet, sugar.S("/api/v1/product/1")). WillRespondWith(http.StatusOK). WithJSONBody(sugar.Map{ "id": sugar.Integer(1), "name": sugar.S("foo 2"), "brand": sugar.S("bar 2"), "price_excl_tax": sugar.Decimal(20.125), }). WithHeader("Content-Type", sugar.Term("application/json; charset=utf-8", `application/json`)) // Wrap my test in an callback function test := func(config sugar.MockServerConfig) error { var product Product var err error var myService B2b // set up the configuration for the driver baseURL := fmt.Sprintf("http://%s:%d", config.Host, config.Port) if err = os.Setenv("PACTGOCONSUMEREXAMPLE_PACTGOPROVIDEREXAMPLE_URL", baseURL); err != nil { return err } // instanciate the service if myService, err = New(); err != nil { return err } product, err = myService.Product(context.Background(), 1) require.NoError(t, err) require.Equal(t, 1, product.ID) require.Equal(t, "foo 2", product.Name) require.Equal(t, "bar 2", product.Brand) require.Equal(t, 20.125, product.Price) return nil } // Execute the test and check the expectation err := mockProvider.ExecuteTest(t, test) require.NoError(t, err) }) t.Run("the product 2 doesn't exists", func(t *testing.T) { // Setup my expected interactions mockProvider.AddInteraction(). Given("A product with id 2 does not exist"). UponReceiving("a request Product 2"). WithRequest(http.MethodGet, sugar.S("/api/v1/product/2")). WillRespondWith(http.StatusNotFound). WithHeader("Content-Type", sugar.Term("application/json; charset=utf-8", `application/json`)) // Wrap my test in an callback function test := func(config sugar.MockServerConfig) error { var product Product var err error var myService B2b // set up the configuration for the driver baseURL := fmt.Sprintf("http://%s:%d", config.Host, config.Port) if err = os.Setenv("PACTGOCONSUMEREXAMPLE_PACTGOPROVIDEREXAMPLE_URL", baseURL); err != nil { return err } // instanciate the service if myService, err = New(); err != nil { return err } product, err = myService.Product(context.Background(), 2) require.Error(t, err) require.Equal(t, Product{}, product) return nil } // Execute the test and check the expectation err := mockProvider.ExecuteTest(t, test) require.NoError(t, err) })
}
Relevent log files
Please ensure you set logging to DEBUG
and attach any relevant log files here (or link from a gist).
Metadata
Metadata
Assignees
Labels
No labels