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

can't run linter goanalysis_metalinter: inspect: failed to load package sugar: could not load export data: no export data for #248

Closed
edouard-lopez opened this issue Apr 28, 2022 · 2 comments

Comments

@edouard-lopez
Copy link

related: pact-foundation/pact-go#212

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/golangci-lint@v1.45
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 b2b

import (
"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)
})

}

@dnephin
Copy link
Member

dnephin commented Apr 28, 2022

I think you meant to open this issue on https://github.com/golangci/golangci-lint/. It doesn't look related to gotestsum. I'm going to close the issue, but if gotestsum is involved in some way, please do comment and let me know.

@dnephin dnephin closed this as completed Apr 28, 2022
@edouard-lopez
Copy link
Author

My bad, thanks.

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

2 participants