Skip to content

Commit

Permalink
Linter issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
gaydin committed Dec 27, 2024
1 parent 210bc17 commit 2711697
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 52 deletions.
23 changes: 16 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
service:
golangci-lint-version: v1.55.1

run:
tests: false
skip-dirs:

issues:
exclude-files:
- ".*easyjson\\.go$"
exclude-dirs:
- allure
- mocks
skip-files:
- ".*easyjson\\.go$"

output:
print-issued-lines: false

Expand All @@ -32,6 +32,14 @@ linters-settings:
# Should be enabled after fixing underscore package names.
- name: var-naming
disabled: true
gci:
sections:
- standard
- default
- prefix(github.com/lamoda/gonkey)
skip-generated: true
custom-order: false
no-lex-order: false

linters:
enable:
Expand All @@ -58,4 +66,5 @@ linters:
- unconvert
- unparam
- unused
- gas
- gosec
- gci
6 changes: 3 additions & 3 deletions checker/addons/openapi2_compliance/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"encoding/json"
"strings"

"github.com/lamoda/gonkey/checker"
"github.com/lamoda/gonkey/models"

"github.com/go-openapi/errors"
"github.com/go-openapi/loads"
"github.com/go-openapi/spec"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"

"github.com/lamoda/gonkey/checker"
"github.com/lamoda/gonkey/models"
)

type ResponseSchemaChecker struct {
Expand Down
6 changes: 3 additions & 3 deletions checker/response_db/response_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"fmt"
"strings"

"github.com/fatih/color"
"github.com/kylelemons/godebug/pretty"

"github.com/lamoda/gonkey/checker"
"github.com/lamoda/gonkey/compare"
"github.com/lamoda/gonkey/models"

"github.com/fatih/color"
"github.com/kylelemons/godebug/pretty"
)

type ResponseDbChecker struct {
Expand Down
4 changes: 2 additions & 2 deletions checker/response_header/response_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"sort"
"testing"

"github.com/stretchr/testify/assert"

"github.com/lamoda/gonkey/models"
"github.com/lamoda/gonkey/testloader/yaml_file"

"github.com/stretchr/testify/assert"
)

func TestCheckShouldMatchSubset(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions examples/mock-based-on-request/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
urlpkg "net/url"
Expand Down Expand Up @@ -45,7 +44,7 @@ func Do(w http.ResponseWriter, r *http.Request) {
if res.StatusCode != http.StatusOK {
return 0, fmt.Errorf("backend response status code %d", res.StatusCode)
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
_ = res.Body.Close()
if err != nil {
return 0, fmt.Errorf("cannot read response body %w", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/mock-field-json-str/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand All @@ -20,7 +20,7 @@ func initServer() {
}

func ProxyRequest(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
log.Print(err)
w.Write([]byte("{\"status\": \"error\"}"))
Expand Down
4 changes: 2 additions & 2 deletions examples/traffic-lights-demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -54,7 +54,7 @@ func initServer() {
lights.mutex.Lock()
defer lights.mutex.Unlock()

request, err := ioutil.ReadAll(r.Body)
request, err := io.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/with-cases-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
)
Expand Down Expand Up @@ -34,7 +34,7 @@ func Do(w http.ResponseWriter, r *http.Request) {
return
}

jsonRequest, _ := ioutil.ReadAll(r.Body)
jsonRequest, _ := io.ReadAll(r.Body)
request := buildRequest(jsonRequest)

if request.Name == "a" {
Expand Down
2 changes: 1 addition & 1 deletion fixtures/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (f *LoaderPostgres) buildInsertQuery(ctx *loadContext, t tableName, rows ta
fieldPresence := make(map[string]bool)
for _, row := range rows {
for name := range row {
if len(name) > 0 && name[0] == '$' {
if name != "" && name[0] == '$' {
continue
}
if _, ok := fieldPresence[name]; !ok {
Expand Down
3 changes: 2 additions & 1 deletion fixtures/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package redis
import (
"context"

"github.com/lamoda/gonkey/fixtures/redis/parser"
"github.com/redis/go-redis/v9"

"github.com/lamoda/gonkey/fixtures/redis/parser"
)

type Loader struct {
Expand Down
21 changes: 11 additions & 10 deletions mocks/request_constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"reflect"
"regexp"
"sort"
"strings"

"github.com/tidwall/gjson"

"github.com/lamoda/gonkey/compare"
"github.com/lamoda/gonkey/xmlparsing"
"github.com/tidwall/gjson"
)

type verifier interface {
Expand Down Expand Up @@ -47,12 +48,12 @@ func newBodyMatchesXMLConstraint(expected string, params compare.Params) (verifi
}

func (c *bodyMatchesXMLConstraint) Verify(r *http.Request) []error {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return []error{err}
}
// write body for future reusing
r.Body = ioutil.NopCloser(bytes.NewReader(body))
r.Body = io.NopCloser(bytes.NewReader(body))
if len(body) == 0 {
return []error{errors.New("request is empty")}
}
Expand Down Expand Up @@ -84,12 +85,12 @@ func newBodyMatchesJSONConstraint(expected string, params compare.Params) (verif
}

func (c *bodyMatchesJSONConstraint) Verify(r *http.Request) []error {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return []error{err}
}
// write body for future reusing
r.Body = ioutil.NopCloser(bytes.NewReader(body))
r.Body = io.NopCloser(bytes.NewReader(body))
if len(body) == 0 {
return []error{errors.New("request is empty")}
}
Expand Down Expand Up @@ -122,13 +123,13 @@ func newBodyJSONFieldMatchesJSONConstraint(path, expected string, params compare
}

func (c *bodyJSONFieldMatchesJSONConstraint) Verify(r *http.Request) []error {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return []error{err}
}

// write body for future reusing
r.Body = ioutil.NopCloser(bytes.NewReader(body))
r.Body = io.NopCloser(bytes.NewReader(body))

value := gjson.Get(string(body), c.path)
if !value.Exists() {
Expand Down Expand Up @@ -338,13 +339,13 @@ func newBodyMatchesTextConstraint(body, re string) (verifier, error) {
}

func (c *bodyMatchesTextConstraint) Verify(r *http.Request) []error {
ioBody, err := ioutil.ReadAll(r.Body)
ioBody, err := io.ReadAll(r.Body)
if err != nil {
return []error{err}
}

// write body for future reusing
r.Body = ioutil.NopCloser(bytes.NewReader(ioBody))
r.Body = io.NopCloser(bytes.NewReader(ioBody))

body := string(ioBody)

Expand Down
7 changes: 4 additions & 3 deletions output/allure_report/allure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/xml"
"errors"
"io/ioutil"
"os"
"path/filepath"
"time"

"github.com/google/uuid"

"github.com/lamoda/gonkey/output/allure_report/beans"
)

Expand Down Expand Up @@ -119,7 +120,7 @@ func getBufferInfo(buf bytes.Buffer, typ string) (string, string) {

func writeBuffer(pathDir string, buf bytes.Buffer, ext string) (string, error) {
fileName := uuid.New().String() + `-attachment.` + ext
err := ioutil.WriteFile(filepath.Join(pathDir, fileName), buf.Bytes(), 0o644)
err := os.WriteFile(filepath.Join(pathDir, fileName), buf.Bytes(), 0o644)

return fileName, err
}
Expand All @@ -129,7 +130,7 @@ func writeSuite(pathDir string, suite *beans.Suite) error {
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(pathDir, uuid.New().String()+`-testsuite.xml`), b, 0o644)
err = os.WriteFile(filepath.Join(pathDir, uuid.New().String()+`-testsuite.xml`), b, 0o644)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions output/console_colored/console_colored.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"text/template"

"github.com/fatih/color"

"github.com/lamoda/gonkey/models"
)

Expand Down
3 changes: 1 addition & 2 deletions runner/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -181,7 +180,7 @@ func request(test models.TestInterface, b *bytes.Buffer, host string) (*http.Req
func actualRequestBody(req *http.Request) string {
if req.Body != nil {
reqBodyStream, _ := req.GetBody()
reqBody, _ := ioutil.ReadAll(reqBodyStream)
reqBody, _ := io.ReadAll(reqBodyStream)

return string(reqBody)
}
Expand Down
4 changes: 2 additions & 2 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package runner
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -170,7 +170,7 @@ func (r *Runner) executeTest(v models.TestInterface) (*models.Result, error) {
return nil, err
}

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)

_ = resp.Body.Close()

Expand Down
4 changes: 2 additions & 2 deletions runner/runner_upload_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package runner

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"path/filepath"
Expand Down Expand Up @@ -58,7 +58,7 @@ func formFile(t *testing.T, r *http.Request, field string) (string, string) {

defer func() { _ = file.Close() }()

contents, err := ioutil.ReadAll(file)
contents, err := io.ReadAll(file)
require.NoError(t, err)

return header.Filename, string(contents)
Expand Down
4 changes: 2 additions & 2 deletions testloader/yaml_file/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strings"
"text/template"

"github.com/lamoda/gonkey/models"

"gopkg.in/yaml.v2"

"github.com/lamoda/gonkey/models"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions testloader/yaml_file/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package yaml_file

import (
"fmt"
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -55,7 +54,7 @@ var testsYAMLData = `
`

func TestParseTestsWithCases(t *testing.T) {
tmpfile, err := ioutil.TempFile("../..", "tmpfile_")
tmpfile, err := os.CreateTemp("../..", "tmpfile_")
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 2711697

Please sign in to comment.