Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
omer.hanci committed Mar 4, 2024
1 parent e4c27fb commit 82807e0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"github.com/labstack/gommon/log"
"os"

"github.com/labstack/gommon/log"

"github.com/spf13/cobra"
)

Expand Down
1 change: 1 addition & 0 deletions cmd/upsert_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/Trendyol/es-alert-cli/internal"
"github.com/labstack/gommon/log"

Expand Down
3 changes: 2 additions & 1 deletion cmd/upsert_alert_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"testing"
)

func TestGetFlagVariables_ValidFlags(t *testing.T) {
Expand Down
16 changes: 11 additions & 5 deletions internal/monitor_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"fmt"

"github.com/Trendyol/es-alert-cli/pkg/client"
"github.com/Trendyol/es-alert-cli/pkg/errs"
"github.com/Trendyol/es-alert-cli/pkg/model"
Expand Down Expand Up @@ -87,7 +88,8 @@ func (m MonitorService) Upsert(filename string, deleteUntracked bool) ([]model.U
}

func findModifiedMonitors(intersectedMonitors mapset.Set, localMonitors map[string]model.Monitor,
remoteMonitors map[string]model.Monitor) mapset.Set {
remoteMonitors map[string]model.Monitor,
) mapset.Set {
modifiedMonitors := mapset.NewSet()
for intersectedMonitorName := range intersectedMonitors.Iterator().C {
if isMonitorChanged(localMonitors[intersectedMonitorName.(string)],
Expand All @@ -99,19 +101,22 @@ func findModifiedMonitors(intersectedMonitors mapset.Set, localMonitors map[stri
}

func (m MonitorService) updateMonitors(modifiedMonitors mapset.Set, localMonitors map[string]model.Monitor,
remoteMonitors map[string]model.Monitor) []model.UpdateMonitorResponse {
remoteMonitors map[string]model.Monitor,
) []model.UpdateMonitorResponse {
monitorsToBeUpdated := prepareForUpdate(modifiedMonitors, localMonitors, remoteMonitors)
return m.client.UpdateMonitors(monitorsToBeUpdated)
}

func (m MonitorService) createMonitors(newMonitors mapset.Set, localMonitors map[string]model.Monitor,
destinations map[string]model.Destination) []model.UpdateMonitorResponse {
destinations map[string]model.Destination,
) []model.UpdateMonitorResponse {
monitorsToBeCreated := prepareForCreate(newMonitors, localMonitors, destinations)
return m.client.CreateMonitors(monitorsToBeCreated)
}

func prepareForCreate(monitorSet mapset.Set, localMonitors map[string]model.Monitor,
destinations map[string]model.Destination) map[string]model.Monitor {
destinations map[string]model.Destination,
) map[string]model.Monitor {
preparedMonitors := make(map[string]model.Monitor)
for m := range monitorSet.Iterator().C {
monitorName := m.(string)
Expand All @@ -132,7 +137,8 @@ func prepareForCreate(monitorSet mapset.Set, localMonitors map[string]model.Moni
}

func prepareForUpdate(monitorsToBeUpdated mapset.Set, localMonitors map[string]model.Monitor,
remoteMonitors map[string]model.Monitor) map[string]model.Monitor {
remoteMonitors map[string]model.Monitor,
) map[string]model.Monitor {
preparedMonitors := make(map[string]model.Monitor)

for m := range monitorsToBeUpdated.Iterator().C {
Expand Down
6 changes: 2 additions & 4 deletions internal/monitor_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package internal

import (
"errors"
"testing"

clientMock "github.com/Trendyol/es-alert-cli/mocks/github.com/Trendyol/es-alert-cli/pkg/client"
readerMock "github.com/Trendyol/es-alert-cli/mocks/github.com/Trendyol/es-alert-cli/pkg/reader"
"github.com/Trendyol/es-alert-cli/pkg/model"
mapset "github.com/deckarep/golang-set"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
)

func Test_Different_Monitor_Should_Return_Changed(t *testing.T) {
Expand Down Expand Up @@ -133,7 +134,6 @@ func TestUpsert_ShouldUpdateMonitor(t *testing.T) {
resp, err := mockMonitorService.Upsert("filename", false)
assert.NoError(t, err)
assert.Equal(t, resp[0].ID, "monitor1")

}

func TestUpsert_ShouldCreateMonitor(t *testing.T) {
Expand Down Expand Up @@ -199,7 +199,6 @@ func TestUpsert_ShouldCreateMonitor(t *testing.T) {
resp, err := mockMonitorService.Upsert("filename", false)
assert.NoError(t, err)
assert.Equal(t, resp[0].ID, "monitor1")

}

func TestUpsert_ShouldReturnErrorWhenFetchDestinationsReturnError(t *testing.T) {
Expand All @@ -226,7 +225,6 @@ func TestUpsert_ShouldReturnErrorWhenFetchDestinationsReturnError(t *testing.T)
resp, err := mockMonitorService.Upsert("filename", false)
assert.Equal(t, err.Error(), "err while reading destinations: fetchDestinationError\n")
assert.Equal(t, len(resp), 0)

}

func TestUpsert_ShouldReturnErrorIfFetchMonitorReturnsError(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/model/destination.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package model

type CustomWebhook struct {
Path string `json:"path,omitempty" yaml:",omitempty"`
HeaderParams map[string]string `json:"header_params,omitempty" yaml:",omitempty"`
QueryParams map[string]string `json:"query_params,omitempty" yaml:",omitempty"`
Path string `json:"path,omitempty" yaml:",omitempty"`
Password string `json:"password,omitempty" yaml:",omitempty"`
Port int `json:"port,omitempty" yaml:",omitempty"`
Scheme string `json:"scheme,omitempty" yaml:",omitempty"`
QueryParams map[string]string `json:"query_params,omitempty" yaml:",omitempty"`
Host string `json:"host,omitempty" yaml:",omitempty"`
URL string `json:"url,omitempty" yaml:",omitempty"`
Username string `json:"username,omitempty" yaml:",omitempty"`
Port int `json:"port,omitempty" yaml:",omitempty"`
}

type ElasticFetchResponse struct {
Expand Down Expand Up @@ -38,8 +38,8 @@ type Slack struct {

type UpdateMonitorResponse struct {
ID string `json:"_id"`
Monitor Monitor `json:"monitor"`
Version int `json:"_version"`
SeqNo int `json:"_seq_no"`
PrimaryTerm int `json:"_primary_term"`
Monitor Monitor `json:"monitor"`
}
16 changes: 8 additions & 8 deletions pkg/model/local.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package model

type Monitor struct {
Schedule Schedule `yaml:"schedule" json:"schedule"`
ID string `yaml:"-" json:"-"`
Type string `yaml:"type" json:"type"`
Name string `yaml:"name" json:"name"`
Enabled bool `yaml:"enabled" json:"enabled"`
Schedule Schedule `yaml:"schedule" json:"schedule"`
Inputs []Input `yaml:"inputs" json:"inputs"`
Triggers []Trigger `yaml:"triggers" json:"triggers"`
Enabled bool `yaml:"enabled" json:"enabled"`
}

type Schedule struct {
Period Period `yaml:"period" json:"period"`
}

type Period struct {
Interval int `yaml:"interval" json:"interval"`
Unit string `yaml:"unit" json:"unit"`
Interval int `yaml:"interval" json:"interval"`
}

type Input struct {
Expand All @@ -37,10 +37,10 @@ type InnerQuery struct {
}

type BoolParam struct {
AdjustPureNegative bool `yaml:"adjust_pure_negative" json:"adjust_pure_negative"`
Boost float64 `yaml:"boost" json:"boost"`
Must []MustParam `yaml:"must" json:"must"`
MustNot []MustParam `yaml:"must_not" json:"must_not"`
Boost float64 `yaml:"boost" json:"boost"`
AdjustPureNegative bool `yaml:"adjust_pure_negative" json:"adjust_pure_negative"`
}

type MustParam struct {
Expand All @@ -50,12 +50,12 @@ type MustParam struct {

type RangeParam struct {
Field string `yaml:"field" json:"field"`
Boost int `yaml:"boost" json:"boost"`
From string `yaml:"from" json:"from"`
IncludeLower bool `yaml:"include_lower" json:"include_lower"`
IncludeUpper bool `yaml:"include_upper" json:"includeUpper"`
TimeZone string `yaml:"time_zone" json:"timeZone"`
To string `yaml:"to" json:"to"`
Boost int `yaml:"boost" json:"boost"`
IncludeLower bool `yaml:"include_lower" json:"include_lower"`
IncludeUpper bool `yaml:"include_upper" json:"includeUpper"`
}

type Trigger struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/reader/read_local.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package reader

import (
"github.com/labstack/gommon/log"
"io"
"os"

"github.com/labstack/gommon/log"

"github.com/Trendyol/es-alert-cli/pkg/model"
mapset "github.com/deckarep/golang-set"
"gopkg.in/yaml.v3"
Expand Down

0 comments on commit 82807e0

Please sign in to comment.