-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 #2788
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello, I used your example (and added missing parts): package sandbox
import (
"context"
"fmt"
"net/http"
"os"
"testing"
"github.com/pact-foundation/pact-go/v2/sugar"
"github.com/stretchr/testify/require"
)
type Product struct {
ID int
Name string
Brand string
Price float64
}
type B2b struct{}
func New() (B2b, error) {
return B2b{}, nil
}
func (b B2b) Product(ctx context.Context, i int) (Product, error) {
return Product{}, nil
}
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 a 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
}
// instantiate 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
}
// instantiate 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)
})
} When I try to run the test, I have a compilation error: $ go test -v .
# github.com/pact-foundation/pact-go/v2/internal/native
/usr/bin/ld: cannot find -lpact_ffi: No such file or directory
collect2: error: ld returned 1 exit status
FAIL github.com/golangci/sandbox [build failed]
FAIL
Golangci-lint requires that the code compile. Note: |
related: pact-foundation/pact-go#212
if ! type pact-go > /dev/null; then \
go install github.com/pact-foundation/pact-go/[email protected]; \
pact-go -l DEBUG install; \
if test ! -x /usr/local/lib/libpact_ffi.so; then \
chmod +x --quiet /usr/local/lib/libpact_ffi.so \
|| sudo chmod +x /usr/local/lib/libpact_ffi.so; \
fi \
fi |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
So the issue is that the package relies on CGo - does this project not support packages with native integrations? |
@mefellows I am also facing the same issue. I wanted to exclude auto-generated pb files from code analysis.
config file:
|
Welcome
Description of the problem
Version of golangci-lint
Configuration file
Go environment
Verbose output of running
Code example or link to a public repository
File importing and using
sugar
The text was updated successfully, but these errors were encountered: