Skip to content

Commit

Permalink
fix(golangci-lint): fix errors as raised by linter
Browse files Browse the repository at this point in the history
Linked to #320
  • Loading branch information
boreyuk committed Jul 19, 2023
1 parent 7d9ed69 commit 1c98c51
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 98 deletions.
2 changes: 1 addition & 1 deletion consumer/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (p *httpMockProvider) ExecuteTest(t *testing.T, integrationTest func(MockSe
func (p *httpMockProvider) reset() {
p.mockserver.CleanupMockServer(p.config.Port)
p.config.Port = 0
p.configure()
_ = p.configure()
}

// TODO: improve / pretty print this to make it really easy to understand the problems
Expand Down
4 changes: 2 additions & 2 deletions consumer/http_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (i *V4InteractionWithPluginRequestBuilder) Headers(headers matchers.Headers

// PluginContents configures a plugin. This may be called once per plugin registered.
func (i *V4InteractionWithPluginRequestBuilder) PluginContents(contentType string, contents string) *V4InteractionWithPluginRequestBuilder {
i.interaction.interaction.WithPluginInteractionContents(native.INTERACTION_PART_REQUEST, contentType, contents)
_ = i.interaction.interaction.WithPluginInteractionContents(native.INTERACTION_PART_REQUEST, contentType, contents)

return i
}
Expand Down Expand Up @@ -539,7 +539,7 @@ func (i *V4InteractionWithPluginResponseBuilder) Headers(headers matchers.Header

// PluginContents configures a plugin. This may be called once per plugin registered.
func (i *V4InteractionWithPluginResponseBuilder) PluginContents(contentType string, contents string) *V4InteractionWithPluginResponseBuilder {
i.interaction.interaction.WithPluginInteractionContents(native.INTERACTION_PART_RESPONSE, contentType, contents)
_ = i.interaction.interaction.WithPluginInteractionContents(native.INTERACTION_PART_RESPONSE, contentType, contents)

return i
}
Expand Down
2 changes: 1 addition & 1 deletion installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewInstaller(opts ...installerConfig) (*Installer, error) {
i := &Installer{downloader: &defaultDownloader{}, fs: afero.NewOsFs(), hasher: &defaultHasher{}, config: &configuration{}}

for _, opt := range opts {
opt(i)
_ = opt(i)
}

if _, ok := supportedOSes[runtime.GOOS]; !ok {
Expand Down
4 changes: 2 additions & 2 deletions installer/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestInstallerCheckInstallation(t *testing.T) {

for pkg := range packages {
dst, _ := i.getLibDstForPackage(pkg)
mockFs.Create(dst)
_, _ = mockFs.Create(dst)
}

err := i.CheckInstallation()
Expand All @@ -158,7 +158,7 @@ func TestInstallerCheckPackageInstall(t *testing.T) {
callFunc: func() {
for pkg := range packages {
dst, _ := i.getLibDstForPackage(pkg)
mockFs.Create(dst)
_, _ = mockFs.Create(dst)
}
},
},
Expand Down
3 changes: 2 additions & 1 deletion internal/native/message_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ func (m *MessageServer) MockServerMismatchedRequests(port int) []MismatchedReque
return []MismatchedRequest{}
}

json.Unmarshal([]byte(C.GoString(mismatches)), &res)
// TODO: return no requests if error on unmarshal ?
_ = json.Unmarshal([]byte(C.GoString(mismatches)), &res)

return res
}
Expand Down
47 changes: 21 additions & 26 deletions internal/native/message_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func TestGetAsyncMessageContentsAsBytes(t *testing.T) {
var v struct {
Some string `json:"some"`
}
json.Unmarshal(bytes, &v)
err = json.Unmarshal(bytes, &v)
assert.NoError(t, err)
assert.Equal(t, "json", v.Some)
}

Expand Down Expand Up @@ -181,15 +182,17 @@ func TestGetSyncMessageContentsAsBytes(t *testing.T) {
var v struct {
Some string `json:"some"`
}
json.Unmarshal(bytes[0], &v)
err = json.Unmarshal(bytes[0], &v)
assert.NoError(t, err)
assert.Equal(t, "response", v.Some)
}

func TestGetPluginSyncMessageContentsAsBytes(t *testing.T) {
m := NewMessageServer("test-message-consumer", "test-message-provider")

// Protobuf plugin test
m.UsingPlugin("protobuf", "0.3.0")
err := m.UsingPlugin("protobuf", "0.3.0")
assert.NoError(t, err)

i := m.NewSyncMessageInteraction("grpc interaction")

Expand All @@ -214,26 +217,29 @@ func TestGetPluginSyncMessageContentsAsBytes(t *testing.T) {
}
}`

i.
err = i.
Given("plugin state").
// For gRPC interactions we prpvide the config once for both the request and response parts
WithPluginInteractionContents(INTERACTION_PART_REQUEST, "application/protobuf", grpcInteraction)
assert.NoError(t, err)

bytes, err := i.GetMessageRequestContents()
assert.NoError(t, err)
assert.NotNil(t, bytes)

// Should be able to convert request body back into a protobuf
p := &InitPluginRequest{}
proto.Unmarshal(bytes, p)
err = proto.Unmarshal(bytes, p)
assert.NoError(t, err)
assert.Equal(t, "0.0.0", p.Version)

// Should be able to convert response into a protobuf
response, err := i.GetMessageResponseContents()
assert.NoError(t, err)
assert.NotNil(t, bytes)
r := &InitPluginResponse{}
proto.Unmarshal(response[0], r)
err = proto.Unmarshal(response[0], r)
assert.NoError(t, err)
assert.Equal(t, "test", r.Catalogue[0].Key)

}
Expand All @@ -242,7 +248,7 @@ func TestGetPluginAsyncMessageContentsAsBytes(t *testing.T) {
m := NewMessageServer("test-message-consumer", "test-message-provider")

// Protobuf plugin test
m.UsingPlugin("protobuf", "0.3.0")
_ = m.UsingPlugin("protobuf", "0.3.0")

i := m.NewAsyncMessageInteraction("grpc interaction")

Expand All @@ -257,44 +263,32 @@ func TestGetPluginAsyncMessageContentsAsBytes(t *testing.T) {
"version": "matching(semver, '0.0.0')"
}`

i.
err := i.
Given("plugin state").
// For gRPC interactions we prpvide the config once for both the request and response parts
WithPluginInteractionContents(INTERACTION_PART_REQUEST, "application/protobuf", protobufInteraction)
assert.NoError(t, err)

bytes, err := i.GetMessageRequestContents()
assert.NoError(t, err)
assert.NotNil(t, bytes)

// Should be able to convert body back into a protobuf
p := &InitPluginRequest{}
proto.Unmarshal(bytes, p)
err = proto.Unmarshal(bytes, p)
assert.NoError(t, err)
assert.Equal(t, "0.0.0", p.Version)
}

type binaryMessage struct {
ProviderStates []map[string]interface{} `json:"providerStates"`
Description string `json:"description"`
Metadata map[string]string `json:"metadata"`
Contents string `json:"contents"` // base 64 encoded
// Contents []byte `json:"contents"`
}
type jsonMessage struct {
ProviderStates []map[string]interface{} `json:"providerStates"`
Description string `json:"description"`
Metadata map[string]string `json:"metadata"`
Contents interface{} `json:"contents"`
}

func TestGrpcPluginInteraction(t *testing.T) {
tmpPactFolder, err := ioutil.TempDir("", "pact-go")
assert.NoError(t, err)
log.SetLogLevel("TRACE")
_ = log.SetLogLevel("TRACE")

m := NewMessageServer("test-message-consumer", "test-message-provider")

// Protobuf plugin test
m.UsingPlugin("protobuf", "0.3.0")
_ = m.UsingPlugin("protobuf", "0.3.0")

i := m.NewSyncMessageInteraction("grpc interaction")

Expand All @@ -319,10 +313,11 @@ func TestGrpcPluginInteraction(t *testing.T) {
}
}`

i.
err = i.
Given("plugin state").
// For gRPC interactions we prpvide the config once for both the request and response parts
WithPluginInteractionContents(INTERACTION_PART_REQUEST, "application/protobuf", grpcInteraction)
assert.NoError(t, err)

// Start the gRPC mock server
port, err := m.StartTransport("grpc", "127.0.0.1", 0, make(map[string][]interface{}))
Expand Down
6 changes: 3 additions & 3 deletions internal/native/mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ func Init(logLevel string) {

if os.Getenv("PACT_LOG_PATH") != "" {
log.Println("[DEBUG] initialised native log to log to file:", os.Getenv("PACT_LOG_PATH"))
logToFile(os.Getenv("PACT_LOG_PATH"), l)
_ = logToFile(os.Getenv("PACT_LOG_PATH"), l)
} else {
log.Println("[DEBUG] initialised native log to log to stdout")
logToStdout(l)
_ = logToStdout(l)
}
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ func (m *MockServer) MockServerMismatchedRequests(port int) []MismatchedRequest
return []MismatchedRequest{}
}

json.Unmarshal([]byte(C.GoString(mismatches)), &res)
_ = json.Unmarshal([]byte(C.GoString(mismatches)), &res)

return res
}
Expand Down
9 changes: 5 additions & 4 deletions internal/native/mock_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ func TestHandleBasedHTTPTests(t *testing.T) {
func TestPluginInteraction(t *testing.T) {
tmpPactFolder, err := ioutil.TempDir("", "pact-go")
assert.NoError(t, err)
log.SetLogLevel("trace")
_ = log.SetLogLevel("trace")

m := NewHTTPPact("test-plugin-consumer", "test-plugin-provider")

// Protobuf plugin test
m.UsingPlugin("protobuf", "0.0.3")
_ = m.UsingPlugin("protobuf", "0.0.3")
m.WithSpecificationVersion(SPECIFICATION_VERSION_V4)

i := m.NewInteraction("some plugin interaction")
Expand All @@ -188,11 +188,12 @@ func TestPluginInteraction(t *testing.T) {
"version": "matching(semver, '0.0.0')"
}`

i.UponReceiving("some interaction").
err = i.UponReceiving("some interaction").
Given("plugin state").
WithRequest("GET", "/protobuf").
WithStatus(200).
WithPluginInteractionContents(INTERACTION_PART_RESPONSE, "application/protobuf", protobufInteraction)
assert.NoError(t, err)

port, err := m.Start("0.0.0.0:0", false)
assert.NoError(t, err)
Expand All @@ -205,7 +206,7 @@ func TestPluginInteraction(t *testing.T) {
assert.NoError(t, err)

initPluginRequest := &InitPluginRequest{}
proto.Unmarshal(bytes, initPluginRequest)
err = proto.Unmarshal(bytes, initPluginRequest)
assert.NoError(t, err)

assert.Equal(t, "pact-go-driver", initPluginRequest.Implementation)
Expand Down
8 changes: 0 additions & 8 deletions matchers/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ func (m like) GetValue() interface{} {
func (m like) isMatcher() {
}

func (m like) string() string {
return fmt.Sprintf("%s", m.Value)
}

type term struct {
Value string `json:"value"`
Type string `json:"pact:matcher:type"`
Expand All @@ -76,10 +72,6 @@ func (m term) GetValue() interface{} {
func (m term) isMatcher() {
}

func (m term) string() string {
return string(m.Value)
}

func (m term) MarshalJSON() ([]byte, error) {
type marshaler term

Expand Down
6 changes: 3 additions & 3 deletions matchers/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,16 @@ func formatJSON(object interface{}) interface{} {
var out bytes.Buffer
switch content := object.(type) {
case string:
json.Indent(&out, []byte(content), "", "\t")
_ = json.Indent(&out, []byte(content), "", "\t")
default:
jsonString, err := json.Marshal(object)
if err != nil {
log.Println("[ERROR] unable to marshal json:", err)
}
json.Indent(&out, []byte(jsonString), "", "\t")
_ = json.Indent(&out, []byte(jsonString), "", "\t")
}

return string(out.Bytes())
return out.String()
}

// Instrument the StructMatcher type to be able to assert the
Expand Down
4 changes: 2 additions & 2 deletions message/v4/asynchronous_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type UnconfiguredAsynchronousMessageBuilder struct {

// AddMessage creates a new asynchronous consumer expectation
func (m *UnconfiguredAsynchronousMessageBuilder) UsingPlugin(config PluginConfig) *AsynchronousMessageWithPlugin {
m.rootBuilder.pact.messageserver.UsingPlugin(config.Plugin, config.Version)
_ = m.rootBuilder.pact.messageserver.UsingPlugin(config.Plugin, config.Version)

return &AsynchronousMessageWithPlugin{
rootBuilder: m.rootBuilder,
Expand All @@ -74,7 +74,7 @@ type AsynchronousMessageWithPlugin struct {
}

func (s *AsynchronousMessageWithPlugin) WithContents(contents string, contentType string) *AsynchronousMessageWithPluginContents {
s.rootBuilder.messageHandle.WithPluginInteractionContents(native.INTERACTION_PART_REQUEST, contentType, contents)
_ = s.rootBuilder.messageHandle.WithPluginInteractionContents(native.INTERACTION_PART_REQUEST, contentType, contents)

return &AsynchronousMessageWithPluginContents{
rootBuilder: s.rootBuilder,
Expand Down
2 changes: 1 addition & 1 deletion message/v4/asynchronous_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAsyncTypeSystem(t *testing.T) {
Provider: "asyncprovider",
PactDir: "/tmp/",
})
log.SetLogLevel("TRACE")
_ = log.SetLogLevel("TRACE")

type foo struct {
Foo string `json:"foo"`
Expand Down
8 changes: 3 additions & 5 deletions message/v4/synchronous_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ type SynchronousMessage struct {

// SynchronousMessageBuilder is a representation of a single, bidirectional message
type SynchronousMessageBuilder struct {
messageHandle *native.Message
pact *SynchronousPact
}

// Given specifies a provider state
Expand Down Expand Up @@ -65,7 +63,7 @@ type UnconfiguredSynchronousMessageBuilder struct {

// UsingPlugin enables a plugin for use in the current test case
func (m *UnconfiguredSynchronousMessageBuilder) UsingPlugin(config PluginConfig) *SynchronousMessageWithPlugin {
m.pact.mockserver.UsingPlugin(config.Plugin, config.Version)
_ = m.pact.mockserver.UsingPlugin(config.Plugin, config.Version)

return &SynchronousMessageWithPlugin{
pact: m.pact,
Expand All @@ -75,7 +73,7 @@ func (m *UnconfiguredSynchronousMessageBuilder) UsingPlugin(config PluginConfig)

// UsingPlugin enables a plugin for use in the current test case
func (m *SynchronousMessageWithPlugin) UsingPlugin(config PluginConfig) *SynchronousMessageWithPlugin {
m.pact.mockserver.UsingPlugin(config.Plugin, config.Version)
_ = m.pact.mockserver.UsingPlugin(config.Plugin, config.Version)

return m
}
Expand Down Expand Up @@ -185,7 +183,7 @@ type SynchronousMessageWithPlugin struct {
}

func (s *SynchronousMessageWithPlugin) WithContents(contents string, contentType string) *SynchronousMessageWithPluginContents {
s.messageHandle.WithPluginInteractionContents(native.INTERACTION_PART_REQUEST, contentType, contents)
_ = s.messageHandle.WithPluginInteractionContents(native.INTERACTION_PART_REQUEST, contentType, contents)

return &SynchronousMessageWithPluginContents{
pact: s.pact,
Expand Down
6 changes: 3 additions & 3 deletions message/v4/synchronous_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestSyncTypeSystem(t *testing.T) {
Provider: "provider",
PactDir: "/tmp/",
})
log.SetLogLevel("TRACE")
_ = log.SetLogLevel("TRACE")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/../../internal/native/pact_plugin.proto", dir)
Expand All @@ -40,7 +40,7 @@ func TestSyncTypeSystem(t *testing.T) {
}`

// Sync - no plugin
p.AddSynchronousMessage("some description").
_ = p.AddSynchronousMessage("some description").
Given("some state").
WithRequest(func(r *SynchronousMessageWithRequestBuilder) {
r.WithJSONContent(map[string]string{"foo": "bar"})
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestSyncTypeSystem(t *testing.T) {
Provider: "provider",
PactDir: "/tmp/",
})
p.AddSynchronousMessage("some description").
_ = p.AddSynchronousMessage("some description").
Given("some state").
UsingPlugin(PluginConfig{
Plugin: "csv",
Expand Down
Loading

0 comments on commit 1c98c51

Please sign in to comment.