Adds golangci-lint
This commit is contained in:
parent
3335cfe795
commit
1747612b86
9 changed files with 22 additions and 14 deletions
|
@ -9,11 +9,12 @@ check-generate:
|
||||||
script:
|
script:
|
||||||
- nix-shell --run "make generate && git diff --quiet"
|
- nix-shell --run "make generate && git diff --quiet"
|
||||||
|
|
||||||
check-fmt:
|
check-lint:
|
||||||
stage: format
|
stage: format
|
||||||
image: nixos/nix:latest
|
image: nixos/nix:latest
|
||||||
script:
|
script:
|
||||||
- nix-shell --run "make fmt && git diff --quiet"
|
- nix-shell --run "make fmt && git diff --quiet"
|
||||||
|
- nix-shell --run "make lint"
|
||||||
|
|
||||||
check-gomod:
|
check-gomod:
|
||||||
stage: format
|
stage: format
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -11,6 +11,9 @@ test-watch:
|
||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
|
lint:
|
||||||
|
golangci-lint run ./...
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go run ./cmd/birthdaybot -config example-config.yml
|
go run ./cmd/birthdaybot -config example-config.yml
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package model
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
@ -141,7 +141,7 @@ func (tnc *TelegramNotificationsConfig) IsValid() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadConfig(path string) (*Config, error) {
|
func ReadConfig(path string) (*Config, error) {
|
||||||
fileBytes, err := ioutil.ReadFile(path)
|
fileBytes, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ import (
|
||||||
|
|
||||||
func TestReadConfig(t *testing.T) {
|
func TestReadConfig(t *testing.T) {
|
||||||
t.Run("should correctly read a configuration file", func(t *testing.T) {
|
t.Run("should correctly read a configuration file", func(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "birthdaybot-")
|
f, err := os.CreateTemp("", "birthdaybot-")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ func TestReadConfig(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should fail if the file doesn't exist", func(t *testing.T) {
|
t.Run("should fail if the file doesn't exist", func(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "birthdaybot-")
|
f, err := os.CreateTemp("", "birthdaybot-")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
f.Close()
|
f.Close()
|
||||||
os.Remove(f.Name())
|
os.Remove(f.Name())
|
||||||
|
|
|
@ -2,7 +2,7 @@ package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
func TestParseCsv(t *testing.T) {
|
func TestParseCsv(t *testing.T) {
|
||||||
t.Run("should correctly parse a valid CSV file", func(t *testing.T) {
|
t.Run("should correctly parse a valid CSV file", func(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "birthdaybot-")
|
f, err := os.CreateTemp("", "birthdaybot-")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, werr := io.WriteString(f, "John Doe , john@doe.com, 1234, 17/04/2192\nJane Doe,jane@doe.com,4321,15/01/2020\n")
|
_, werr := io.WriteString(f, "John Doe , john@doe.com, 1234, 17/04/2192\nJane Doe,jane@doe.com,4321,15/01/2020\n")
|
||||||
|
|
|
@ -2,7 +2,6 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ type TestHelper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfig(t *testing.T) *model.Config {
|
func testConfig(t *testing.T) *model.Config {
|
||||||
f, err := ioutil.TempFile("", "birthdaybot-")
|
f, err := os.CreateTemp("", "birthdaybot-")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, f.Close())
|
require.NoError(t, f.Close())
|
||||||
require.NoError(t, os.Remove(f.Name()))
|
require.NoError(t, os.Remove(f.Name()))
|
||||||
|
@ -72,7 +71,7 @@ func SetupTestHelper(t *testing.T, opts ...Option) *TestHelper {
|
||||||
th.srv, err = New(serverOpts...)
|
th.srv, err = New(serverOpts...)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
th.srv.Start()
|
require.NoError(t, th.srv.Start())
|
||||||
|
|
||||||
client, err := client.New(client.WithURL(fmt.Sprintf("http://127.0.0.1:%d", th.srv.WebServer.Port())))
|
client, err := client.New(client.WithURL(fmt.Sprintf("http://127.0.0.1:%d", th.srv.WebServer.Port())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -82,6 +81,6 @@ func SetupTestHelper(t *testing.T, opts ...Option) *TestHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (th *TestHelper) TearDown() {
|
func (th *TestHelper) TearDown() {
|
||||||
th.srv.Stop()
|
require.NoError(th.t, th.srv.Stop())
|
||||||
th.ctrl.Finish()
|
th.ctrl.Finish()
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,5 +81,8 @@ func (ws *WebServer) JSON(w http.ResponseWriter, statusCode int, data any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(statusCode)
|
w.WriteHeader(statusCode)
|
||||||
w.Write(b)
|
if _, err := w.Write(b); err != nil {
|
||||||
|
ws.logger.Error("cannot write to response writer", "error", err)
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,9 @@ func (w *SimpleWorker) notifyDay(year, month, day int) {
|
||||||
|
|
||||||
for _, b := range birthdays {
|
for _, b := range birthdays {
|
||||||
w.logger.Info("notifying for birthday", "name", b.Name)
|
w.logger.Info("notifying for birthday", "name", b.Name)
|
||||||
w.server.Notify(b)
|
if err := w.server.Notify(b); err != nil {
|
||||||
|
w.logger.Error("error notifying for birthday", "name", b.Name, "error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ pkgs.mkShell {
|
||||||
gnumake
|
gnumake
|
||||||
modd
|
modd
|
||||||
mockgen
|
mockgen
|
||||||
|
golangci-lint
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
Loading…
Reference in a new issue