Skip to content

Commit

Permalink
Merge 3c277e3 into d4975b4
Browse files Browse the repository at this point in the history
  • Loading branch information
litleleprikon committed Oct 2, 2019
2 parents d4975b4 + 3c277e3 commit d5a5ff0
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 53 deletions.
41 changes: 41 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
linters-settings:
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
gocyclo:
min-complexity: 20
# min-complexity: 15
maligned:
suggest-new: true

linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
# - errcheck
# - goconst
- gocyclo
- gosimple
- govet
- ineffassign
- maligned
- misspell
- staticcheck
- structcheck
- typecheck
# - unconvert
- unused
- varcheck

run:
deadline: 5m
skip-dirs:
- vendor
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ install:
- go get -v golang.org/x/tools/cmd/cover
- go get -v github.com/mattn/goveralls
before_script:
- make test
- make lint
- make test
- goveralls -coverprofile=coverage.txt -service=travis-ci || true
script:
- if [[ ! -z "$TRAVIS_TAG" ]]; then make packages; fi
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ prepare:

.PHONY: lint
lint: prepare
go get -u github.com/alecthomas/gometalinter
GO111MODULE=off gometalinter --install
GO111MODULE=off gometalinter ./... --aggregate --vendor --skip mock --disable=errcheck --disable=gocyclo --disable=gosec --deadline=5m
GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.18.0
GOGC=30 golangci-lint run

.PHONY: test
test: prepare
Expand Down
2 changes: 1 addition & 1 deletion database/redis/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestContacts(t *testing.T) {
So(err, ShouldBeNil)
})

Convey("Check it for existence in user2 contacts and now existance in user1 contacts", func() {
Convey("Check it for existence in user2 contacts and now existence in user1 contacts", func() {
actual, err := dataBase.GetContact(contact3.ID)
So(err, ShouldBeNil)
So(actual, ShouldResemble, contact3)
Expand Down
5 changes: 3 additions & 2 deletions database/redis/trigger_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package redis

import (
"github.com/gofrs/uuid"
"testing"
"time"

"github.com/gofrs/uuid"

"github.com/op/go-logging"
. "github.com/smartystreets/goconvey/convey"

Expand Down Expand Up @@ -50,7 +51,7 @@ func TestTriggerStoring(t *testing.T) {
Convey("Test save-get-remove", func() {
trigger := &triggers[0]

//Check for not existing not writen trigger
//Check for not existing not written trigger
actual, err := dataBase.GetTrigger(trigger.ID)
So(err, ShouldResemble, database.ErrNil)
So(actual, ShouldResemble, moira.Trigger{})
Expand Down
10 changes: 5 additions & 5 deletions plotting/fonts/ttftogofile/ttf2gofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ func usage() {
// reade file to byte array
func fileBytes(filePath string) ([]byte, error) {
var err error
if f, err := os.Open(filePath); err == nil {
defer f.Close()
return ioutil.ReadAll(f)
f, err := os.Open(filePath)
if err != nil {
return nil, err
}

return nil, err
defer f.Close()
return ioutil.ReadAll(f)
}

// write to variable go file
Expand Down
78 changes: 40 additions & 38 deletions plotting/plot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/gotokatsuya/ipare"
"github.com/gotokatsuya/ipare/util"
"github.com/moira-alert/moira"
"github.com/moira-alert/moira/metric_source"
metricSource "github.com/moira-alert/moira/metric_source"
. "github.com/smartystreets/goconvey/convey"
)

Expand All @@ -37,11 +37,11 @@ var (

// plotsHashDistancesTestCase is a single plot test case
type plotsHashDistancesTestCase struct {
useHumanizedValues bool
stateOk bool
name string
plotTheme string
useHumanizedValues bool
triggerType string
stateOk bool
warnValue interface{}
errorValue interface{}
expected int
Expand Down Expand Up @@ -554,43 +554,45 @@ func generateRandomTestMetricsData(numTotal int, numEmpty int) []*metricSource.M
func TestGetRenderable(t *testing.T) {
Convey("Test plots hash distances", t, func() {
for _, testCase := range plotsHashDistancesTestCases {
trigger := moira.Trigger{
Name: testCase.getTriggerName(),
TriggerType: testCase.triggerType,
}
if testCase.errorValue != nil {
errorValue := testCase.errorValue.(float64)
if !testCase.useHumanizedValues {
errorValue = errorValue * plotTestOuterPointMultiplier
Convey(testCase.name, func() {
trigger := moira.Trigger{
Name: testCase.getTriggerName(),
TriggerType: testCase.triggerType,
}
if testCase.errorValue != nil {
errorValue := testCase.errorValue.(float64)
if !testCase.useHumanizedValues {
errorValue = errorValue * plotTestOuterPointMultiplier
}
trigger.ErrorValue = &errorValue
}
if testCase.warnValue != nil {
warnValue := testCase.warnValue.(float64)
if !testCase.useHumanizedValues {
warnValue = warnValue * plotTestOuterPointMultiplier
}
trigger.WarnValue = &warnValue
}
metricsData := generateTestMetricsData(testCase.useHumanizedValues)
pathToOriginal, err := testCase.getFilePath(true)
if err != nil {
t.Fatal(err)
}
pathToRendered, err := testCase.getFilePath(false)
if err != nil {
t.Fatal(err)
}
err = renderTestMetricsDataToPNG(trigger, testCase.plotTheme, metricsData, pathToRendered)
if err != nil {
t.Fatal(err)
}
trigger.ErrorValue = &errorValue
}
if testCase.warnValue != nil {
warnValue := testCase.warnValue.(float64)
if !testCase.useHumanizedValues {
warnValue = warnValue * plotTestOuterPointMultiplier
hashDistance, err := calculateHashDistance(pathToOriginal, pathToRendered)
if err != nil {
t.Fatal(err)
}
trigger.WarnValue = &warnValue
}
metricsData := generateTestMetricsData(testCase.useHumanizedValues)
pathToOriginal, err := testCase.getFilePath(true)
if err != nil {
t.Fatal(err)
}
pathToRendered, err := testCase.getFilePath(false)
if err != nil {
t.Fatal(err)
}
err = renderTestMetricsDataToPNG(trigger, testCase.plotTheme, metricsData, pathToRendered)
if err != nil {
t.Fatal(err)
}
hashDistance, err := calculateHashDistance(pathToOriginal, pathToRendered)
if err != nil {
t.Fatal(err)
}
os.Remove(pathToRendered)
So(*hashDistance, ShouldBeLessThanOrEqualTo, testCase.expected)
os.Remove(pathToRendered)
So(*hashDistance, ShouldBeLessThanOrEqualTo, testCase.expected)
})
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion senders/telegram/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (sender *Sender) getChat(username string) (*telebot.Chat, error) {
}
chat, err := sender.bot.ChatByID(uid)
if err != nil {
return nil, fmt.Errorf("can't find recepient %s: %s", uid, err.Error())
return nil, fmt.Errorf("can't find recipient %s: %s", uid, err.Error())
}
return chat, nil
}
Expand Down
5 changes: 3 additions & 2 deletions senders/victorops/api/alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ func TestCreateAlert(t *testing.T) {
// Send response to be tested
}))
defer server.Close()
client := NewClient(server.URL, server.Client())
err := client.CreateAlert("key", CreateAlertRequest{MessageType: Critical})
// TODO(e.sharifullin): Investigate why new client is created
newClient := NewClient(server.URL, server.Client())
err := newClient.CreateAlert("key", CreateAlertRequest{MessageType: Critical})
So(err, ShouldResemble, fmt.Errorf("victorops API request resulted in error with status %v: %v", http.StatusInternalServerError, `{"error":"test error"}`))
})
Convey("200 OK", func() {
Expand Down

0 comments on commit d5a5ff0

Please sign in to comment.