Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmv committed Sep 9, 2024
1 parent 92c4ad6 commit db866e6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,6 @@ issues:
- gosec
- noctx
- wrapcheck
- gochecknoglobals
- testpackage
- lll
10 changes: 5 additions & 5 deletions internal/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
)

func ReturnError(err error) error {
return &ErrorMsg{ErrMsg: err.Error()}
return &MsgError{Msg: err.Error()}
}

type ErrorMsg struct {
ErrMsg string `json:"errMsg"`
type MsgError struct {
Msg string `json:"errMsg"`
}

func (e *ErrorMsg) Error() string {
return e.ErrMsg
func (e *MsgError) Error() string {
return e.Msg
}

var ErrPageNotFound = errors.New("page not found")
Expand Down
2 changes: 1 addition & 1 deletion internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type PatchIncidentData struct {
func (a *App) PatchIncidentHandler(c *gin.Context) {
var incID IncidentID
if err := c.ShouldBindUri(&incID); err != nil {
c.AbortWithError(http.StatusBadRequest, err)
c.AbortWithError(http.StatusBadRequest, err) //nolint:nolintlint,errcheck
}

var incData PatchIncidentData
Expand Down
9 changes: 5 additions & 4 deletions internal/app/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stackmon/otc-status-dashboard/internal/db"
)
Expand All @@ -24,14 +25,14 @@ func TestGetIncidentsHandler(t *testing.T) {
str := "2024-09-01T11:45:26.371Z"

testTime, err := time.Parse(time.RFC3339, str)
assert.NoError(t, err)
require.NoError(t, err)

prepareDB(t, testTime)

var response = `{"data":[{"id":1,"title":"Incident title","impact":0,"components":[150],"start_date":"%s","system":false,"updates":[{"id":1,"status":"resolved","text":"Issue solved.","timestamp":"%s"}]}]}`

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/v1/incidents", nil)
req, _ := http.NewRequest(http.MethodGet, "/v1/incidents", nil)
testApp.router.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
Expand All @@ -42,7 +43,7 @@ func TestGetIncidentsHandler(t *testing.T) {
func TestReturn404Handler(t *testing.T) {
initTests(t)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/anyendpoint", nil)
req, _ := http.NewRequest(http.MethodGet, "/anyendpoint", nil)
testApp.router.ServeHTTP(w, req)

assert.Equal(t, 404, w.Code)
Expand Down Expand Up @@ -99,7 +100,7 @@ func initTests(t *testing.T) {
r.NoRoute(Return404)

d, m, err := db.NewWithMock()
assert.NoError(t, err)
require.NoError(t, err)

testApp = &App{router: r, Log: nil, conf: nil, DB: d, srv: nil}
testApp.InitRoutes()
Expand Down
6 changes: 2 additions & 4 deletions internal/app/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func (a *App) ValidateComponentsMW() gin.HandlerFunc {
return func(c *gin.Context) {

type Components struct {
Components []int `json:"components"`
}
Expand All @@ -29,16 +28,15 @@ func (a *App) ValidateComponentsMW() gin.HandlerFunc {
err := a.IsPresentComponent(components.Components)
if err != nil {
if errors.Is(err, ErrComponentIsNotPresent) {
c.AbortWithError(http.StatusBadRequest, err)
c.AbortWithError(http.StatusBadRequest, err) //nolint:nolintlint,errcheck
}
c.AbortWithError(http.StatusInternalServerError, err)
c.AbortWithError(http.StatusInternalServerError, err) //nolint:nolintlint,errcheck
}
c.Next()
}
}

func (a *App) IsPresentComponent(components []int) error {

dbComps, err := a.DB.GetComponentsAsMap()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (db *DB) ModifyIncident(inc *Incident) error {

r := db.g.Updates(inc)

if components != nil {

if components != nil { //nolint:revive,staticcheck,nolintlint
// TODO: update components here
}

if r.Error != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/db/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

func NewWithMock() (*DB, sqlmock.Sqlmock, error) {
mockDb, mock, _ := sqlmock.New()
mockDB, mock, _ := sqlmock.New()
dialector := postgres.New(postgres.Config{
Conn: mockDb,
Conn: mockDB,
DriverName: "postgres",
})

Expand Down

0 comments on commit db866e6

Please sign in to comment.