gotestyourself / gotestsum

'go test' runner with output optimized for humans, JUnit XML for CI integration, and a summary of the test results.
Apache License 2.0
2.08k stars 122 forks source link

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 closed 2 years ago

edouard-lopez commented 2 years ago

related: https://github.com/pact-foundation/pact-go/issues/212

Software versions

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 commented 2 years ago

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.

edouard-lopez commented 2 years ago

My bad, thanks.