Chore: Enable whitespace linter (#25903)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -57,7 +57,6 @@ func TestEvaluators(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(evaluator.Eval(null.FloatFromPtr(nil)), ShouldBeTrue)
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,11 +16,8 @@ import (
|
||||
)
|
||||
|
||||
func TestQueryCondition(t *testing.T) {
|
||||
|
||||
Convey("when evaluating query condition", t, func() {
|
||||
|
||||
queryConditionScenario("Given avg() and > 100", func(ctx *queryConditionTestContext) {
|
||||
|
||||
ctx.reducer = `{"type": "avg"}`
|
||||
ctx.evaluator = `{"type": "gt", "params": [100]}`
|
||||
|
||||
@@ -216,7 +213,6 @@ func (ctx *queryConditionTestContext) exec() (*alerting.ConditionResult, error)
|
||||
|
||||
func queryConditionScenario(desc string, fn queryConditionScenarioFunc) {
|
||||
Convey(desc, func() {
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDataSourceByIdQuery) error {
|
||||
query.Result = &models.DataSource{Id: 1, Type: "graphite"}
|
||||
return nil
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
func TestSimpleReducer(t *testing.T) {
|
||||
Convey("Test simple reducer by calculating", t, func() {
|
||||
|
||||
Convey("sum", func() {
|
||||
result := testReducer("sum", 1, 2, 3)
|
||||
So(result, ShouldEqual, float64(6))
|
||||
|
||||
@@ -49,7 +49,6 @@ func TestEngineProcessJob(t *testing.T) {
|
||||
job := &Job{running: true, Rule: &Rule{}}
|
||||
|
||||
Convey("Should trigger retry if needed", func() {
|
||||
|
||||
Convey("error + not last attempt -> retry", func() {
|
||||
engine.evalHandler = NewFakeEvalHandler(0)
|
||||
|
||||
@@ -94,7 +93,6 @@ func TestEngineProcessJob(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Should trigger as many retries as needed", func() {
|
||||
|
||||
Convey("never success -> max retries number", func() {
|
||||
expectedAttempts := setting.AlertingMaxAttempts
|
||||
evalHandler := NewFakeEvalHandler(0)
|
||||
|
||||
@@ -82,7 +82,6 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
|
||||
collapsedJSON, collapsed := panel.CheckGet("collapsed")
|
||||
// check if the panel is collapsed
|
||||
if collapsed && collapsedJSON.MustBool() {
|
||||
|
||||
// extract alerts from sub panels for collapsed panels
|
||||
alertSlice, err := e.getAlertFromPanels(panel, validateAlertFunc)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,9 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAlertRuleExtraction(t *testing.T) {
|
||||
|
||||
Convey("Parsing alert rules from dashboard json", t, func() {
|
||||
|
||||
RegisterCondition("query", func(model *simplejson.Json, index int) (Condition, error) {
|
||||
return &FakeCondition{}, nil
|
||||
})
|
||||
@@ -80,7 +78,6 @@ func TestAlertRuleExtraction(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Parsing and validating dashboard containing graphite alerts", func() {
|
||||
|
||||
dashJSON, err := simplejson.NewJson(json)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ func TestWhenAlertManagerShouldNotify(t *testing.T) {
|
||||
//nolint:goconst
|
||||
func TestAlertmanagerNotifier(t *testing.T) {
|
||||
Convey("Alertmanager notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -57,7 +57,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func newDingDingNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
|
||||
@@ -113,7 +112,6 @@ func (dd *DingDingNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
}
|
||||
|
||||
func (dd *DingDingNotifier) genBody(evalContext *alerting.EvalContext, messageURL string) ([]byte, error) {
|
||||
|
||||
q := url.Values{
|
||||
"pc_slide": {"false"},
|
||||
"url": {messageURL},
|
||||
|
||||
@@ -24,7 +24,6 @@ func TestDingDingNotifier(t *testing.T) {
|
||||
|
||||
_, err := newDingDingNotifier(model)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
})
|
||||
Convey("settings should trigger incident", func() {
|
||||
json := `{ "url": "https://www.google.com" }`
|
||||
|
||||
@@ -105,7 +105,6 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
fields := make([]map[string]interface{}, 0)
|
||||
|
||||
for _, evt := range evalContext.EvalMatches {
|
||||
|
||||
fields = append(fields, map[string]interface{}{
|
||||
"name": evt.Metric,
|
||||
"value": evt.Value.FullString(),
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestDiscordNotifier(t *testing.T) {
|
||||
Convey("Telegram notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestEmailNotifier(t *testing.T) {
|
||||
Convey("Email notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestGoogleChatNotifier(t *testing.T) {
|
||||
Convey("Google Hangouts Chat notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -64,7 +64,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
//nolint:goconst
|
||||
func TestHipChatNotifier(t *testing.T) {
|
||||
Convey("HipChat notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestKafkaNotifier(t *testing.T) {
|
||||
Convey("Kafka notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -22,7 +22,6 @@ func TestLineNotifier(t *testing.T) {
|
||||
|
||||
_, err := NewLINENotifier(model)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
})
|
||||
Convey("settings should trigger incident", func() {
|
||||
json := `
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
func TestOpsGenieNotifier(t *testing.T) {
|
||||
Convey("OpsGenie notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -134,7 +134,6 @@ type PagerdutyNotifier struct {
|
||||
|
||||
// buildEventPayload is responsible for building the event payload body for sending to Pagerduty v2 API
|
||||
func (pn *PagerdutyNotifier) buildEventPayload(evalContext *alerting.EvalContext) ([]byte, error) {
|
||||
|
||||
eventType := "trigger"
|
||||
if evalContext.Rule.State == models.AlertStateOK {
|
||||
eventType = "resolve"
|
||||
@@ -241,7 +240,6 @@ func (pn *PagerdutyNotifier) buildEventPayload(evalContext *alerting.EvalContext
|
||||
|
||||
// Notify sends an alert notification to PagerDuty
|
||||
func (pn *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
|
||||
if evalContext.Rule.State == models.AlertStateOK && !pn.AutoResolve {
|
||||
pn.log.Info("Not sending a trigger to Pagerduty", "state", evalContext.Rule.State, "auto resolve", pn.AutoResolve)
|
||||
return nil
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
func TestPushoverNotifier(t *testing.T) {
|
||||
Convey("Pushover notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
@@ -65,7 +64,6 @@ func TestPushoverNotifier(t *testing.T) {
|
||||
|
||||
func TestGenPushoverBody(t *testing.T) {
|
||||
Convey("Pushover body generation tests", t, func() {
|
||||
|
||||
Convey("Given common sounds", func() {
|
||||
sirenSound := "siren_sound_tst"
|
||||
successSound := "success_sound_tst"
|
||||
@@ -93,6 +91,5 @@ func TestGenPushoverBody(t *testing.T) {
|
||||
So(strings.Contains(pushoverBody.String(), successSound), ShouldBeTrue)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// NewSensuNotifier is the constructor for the Sensu Notifier.
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestSensuNotifier(t *testing.T) {
|
||||
Convey("Sensu notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestSlackNotifier(t *testing.T) {
|
||||
Convey("Slack notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -33,7 +33,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// NewTeamsNotifier is the constructor for Teams notifier.
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestTeamsNotifier(t *testing.T) {
|
||||
Convey("Teams notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -68,7 +68,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// TelegramNotifier is responsible for sending
|
||||
@@ -247,7 +246,6 @@ func generateImageCaption(evalContext *alerting.EvalContext, ruleURL string, met
|
||||
|
||||
if len(message) > captionLengthLimit {
|
||||
message = message[0:captionLengthLimit]
|
||||
|
||||
}
|
||||
|
||||
if len(ruleURL) > 0 {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
func TestTelegramNotifier(t *testing.T) {
|
||||
Convey("Telegram notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
@@ -68,7 +67,6 @@ func TestTelegramNotifier(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When generating a message", func() {
|
||||
|
||||
Convey("URL should be skipped if it's too long", func() {
|
||||
evalContext := alerting.NewEvalContext(context.Background(),
|
||||
&alerting.Rule{
|
||||
|
||||
@@ -98,7 +98,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// ThreemaNotifier is responsible for sending
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
func TestThreemaNotifier(t *testing.T) {
|
||||
Convey("Threema notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestVictoropsNotifier(t *testing.T) {
|
||||
Convey("Victorops notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -74,7 +74,6 @@ func init() {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// NewWebHookNotifier is the constructor for
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
func TestWebhookNotifier(t *testing.T) {
|
||||
Convey("Webhook notifier tests", t, func() {
|
||||
|
||||
Convey("Parsing alert notification from settings", func() {
|
||||
Convey("empty settings should return error", func() {
|
||||
json := `{ }`
|
||||
|
||||
@@ -71,7 +71,6 @@ func (handler *defaultResultHandler) handle(evalContext *EvalContext) error {
|
||||
|
||||
handler.log.Error("Failed to save state", "error", err)
|
||||
} else {
|
||||
|
||||
// StateChanges is used for de duping alert notifications
|
||||
// when two servers are raising. This makes sure that the server
|
||||
// with the last state change always sends a notification.
|
||||
|
||||
@@ -49,7 +49,6 @@ func TestAlertRuleFrequencyParsing(t *testing.T) {
|
||||
func TestAlertRuleModel(t *testing.T) {
|
||||
sqlstore.InitTestDB(t)
|
||||
Convey("Testing alert rule", t, func() {
|
||||
|
||||
RegisterCondition("test", func(model *simplejson.Json, index int) (Condition, error) {
|
||||
return &FakeCondition{}, nil
|
||||
})
|
||||
|
||||
@@ -25,7 +25,6 @@ func init() {
|
||||
}
|
||||
|
||||
func handleAlertTestCommand(cmd *AlertTestCommand) error {
|
||||
|
||||
dash := models.NewDashboardFromJson(cmd.Dashboard)
|
||||
|
||||
extractor := NewDashAlertExtractor(dash, cmd.OrgID, cmd.User)
|
||||
|
||||
@@ -38,7 +38,6 @@ func (s *UserAuthTokenService) Init() error {
|
||||
}
|
||||
|
||||
func (s *UserAuthTokenService) ActiveTokenCount(ctx context.Context) (int64, error) {
|
||||
|
||||
var count int64
|
||||
var err error
|
||||
err = s.SQLStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
@@ -119,9 +118,7 @@ func (s *UserAuthTokenService) LookupToken(ctx context.Context, unhashedToken st
|
||||
Get(&model)
|
||||
|
||||
return err
|
||||
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -373,7 +370,6 @@ func (s *UserAuthTokenService) GetUserToken(ctx context.Context, userId, userTok
|
||||
}
|
||||
|
||||
func (s *UserAuthTokenService) GetUserTokens(ctx context.Context, userId int64) ([]*models.UserToken, error) {
|
||||
|
||||
result := []*models.UserToken{}
|
||||
err := s.SQLStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
var tokens []*userAuthToken
|
||||
@@ -382,7 +378,6 @@ func (s *UserAuthTokenService) GetUserTokens(ctx context.Context, userId int64)
|
||||
s.createdAfterParam(),
|
||||
s.rotatedAfterParam()).
|
||||
Find(&tokens)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func TestUserAuthTokenCleanup(t *testing.T) {
|
||||
|
||||
Convey("Test user auth token cleanup", t, func() {
|
||||
ctx := createTestContext(t)
|
||||
ctx.tokenService.Cfg.LoginMaxInactiveLifetimeDays = 7
|
||||
|
||||
@@ -38,5 +38,4 @@ func TestCleanUpTmpFiles(t *testing.T) {
|
||||
So(service.shouldCleanupTempFile(weekAgo, now), ShouldBeFalse)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -277,7 +277,6 @@ func (dr *dashboardServiceImpl) SaveFolderForProvisionedDashboards(dto *SaveDash
|
||||
}
|
||||
|
||||
func (dr *dashboardServiceImpl) SaveDashboard(dto *SaveDashboardDTO, allowUiUpdate bool) (*models.Dashboard, error) {
|
||||
|
||||
cmd, err := dr.buildSaveDashboardCommand(dto, true, !allowUiUpdate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -224,7 +224,6 @@ func TestDashboardService(t *testing.T) {
|
||||
_, err := service.SaveProvisionedDashboard(dto, nil)
|
||||
So(err, ShouldBeNil)
|
||||
So(dto.Dashboard.Data.Get("refresh").MustString(), ShouldEqual, "5m")
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -532,7 +532,6 @@ func (server *Server) requestMemberOf(entry *ldap.Entry) ([]string, error) {
|
||||
|
||||
if len(groupSearchResult.Entries) > 0 {
|
||||
for _, group := range groupSearchResult.Entries {
|
||||
|
||||
memberOf = append(
|
||||
memberOf,
|
||||
getAttribute(groupIDAttribute, group),
|
||||
|
||||
@@ -241,5 +241,4 @@ func TestLDAPPrivateMethods(t *testing.T) {
|
||||
So(result, ShouldEqual, "cn=test,dc=grafana,dc=org")
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ func Test_syncOrgRoles_doesNotBreakWhenTryingToRemoveLastOrgAdmin(t *testing.T)
|
||||
bus.ClearBusHandlers()
|
||||
defer bus.ClearBusHandlers()
|
||||
bus.AddHandler("test", func(q *models.GetUserOrgListQuery) error {
|
||||
|
||||
q.Result = createUserOrgDTO()
|
||||
|
||||
return nil
|
||||
@@ -53,7 +52,6 @@ func Test_syncOrgRoles_whenTryingToRemoveLastOrgLogsError(t *testing.T) {
|
||||
bus.ClearBusHandlers()
|
||||
defer bus.ClearBusHandlers()
|
||||
bus.AddHandler("test", func(q *models.GetUserOrgListQuery) error {
|
||||
|
||||
q.Result = createUserOrgDTO()
|
||||
|
||||
return nil
|
||||
|
||||
@@ -70,14 +70,12 @@ func New(configs []*ldap.ServerConfig) IMultiLDAP {
|
||||
|
||||
// Ping dials each of the LDAP servers and returns their status. If the server is unavailable, it also returns the error.
|
||||
func (multiples *MultiLDAP) Ping() ([]*ServerStatus, error) {
|
||||
|
||||
if len(multiples.configs) == 0 {
|
||||
return nil, ErrNoLDAPServers
|
||||
}
|
||||
|
||||
serverStatuses := []*ServerStatus{}
|
||||
for _, config := range multiples.configs {
|
||||
|
||||
status := &ServerStatus{}
|
||||
|
||||
status.Host = config.Host
|
||||
@@ -104,7 +102,6 @@ func (multiples *MultiLDAP) Ping() ([]*ServerStatus, error) {
|
||||
func (multiples *MultiLDAP) Login(query *models.LoginUserQuery) (
|
||||
*models.ExternalUserInfo, error,
|
||||
) {
|
||||
|
||||
if len(multiples.configs) == 0 {
|
||||
return nil, ErrNoLDAPServers
|
||||
}
|
||||
@@ -125,12 +122,11 @@ func (multiples *MultiLDAP) Login(query *models.LoginUserQuery) (
|
||||
defer server.Close()
|
||||
|
||||
user, err := server.Login(query)
|
||||
// FIXME
|
||||
if user != nil {
|
||||
return user, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
if isSilentError(err) {
|
||||
logger.Debug(
|
||||
"unable to login with LDAP - skipping server",
|
||||
@@ -155,7 +151,6 @@ func (multiples *MultiLDAP) User(login string) (
|
||||
ldap.ServerConfig,
|
||||
error,
|
||||
) {
|
||||
|
||||
if len(multiples.configs) == 0 {
|
||||
return nil, ldap.ServerConfig{}, ErrNoLDAPServers
|
||||
}
|
||||
|
||||
@@ -469,7 +469,6 @@ type mockLDAP struct {
|
||||
|
||||
// Login test fn
|
||||
func (mock *mockLDAP) Login(*models.LoginUserQuery) (*models.ExternalUserInfo, error) {
|
||||
|
||||
mock.loginCalledTimes = mock.loginCalledTimes + 1
|
||||
return mock.loginReturn, mock.loginErrReturn
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestEmailCodes(t *testing.T) {
|
||||
|
||||
Convey("When generating code", t, func() {
|
||||
setting.EmailCodeValidMinutes = 120
|
||||
|
||||
@@ -34,7 +33,5 @@ func TestEmailCodes(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(isValid, ShouldBeFalse)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func TestNotifications(t *testing.T) {
|
||||
|
||||
Convey("Given the notifications service", t, func() {
|
||||
setting.StaticRootPath = "../../../public/"
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ var (
|
||||
|
||||
func TestDashboardsAsConfig(t *testing.T) {
|
||||
t.Run("Dashboards as configuration", func(t *testing.T) {
|
||||
|
||||
logger := log.New("test-logger")
|
||||
|
||||
t.Run("default values should be applied", func(t *testing.T) {
|
||||
|
||||
@@ -65,7 +65,6 @@ func NewDashboardFileReader(cfg *config, log log.Logger) (*FileReader, error) {
|
||||
|
||||
// pollChanges periodically runs startWalkingDisk based on interval specified in the config.
|
||||
func (fr *FileReader) pollChanges(ctx context.Context) {
|
||||
|
||||
ticker := time.NewTicker(time.Duration(int64(time.Second) * fr.Cfg.UpdateIntervalSeconds))
|
||||
for {
|
||||
select {
|
||||
|
||||
@@ -96,7 +96,6 @@ func TestDashboardFileReader(t *testing.T) {
|
||||
logger := log.New("test.logger")
|
||||
|
||||
Convey("Reading dashboards from disk", func() {
|
||||
|
||||
cfg := &config{
|
||||
Name: "Default",
|
||||
Type: "file",
|
||||
@@ -342,7 +341,6 @@ func TestDashboardFileReader(t *testing.T) {
|
||||
|
||||
So(len(fakeService.provisioned["Default"]), ShouldEqual, 1)
|
||||
So(fakeService.provisioned["Default"][0].ExternalId, ShouldEqual, absPath1)
|
||||
|
||||
})
|
||||
|
||||
Convey("Missing dashboard should be deleted if DisableDeletion = false", func() {
|
||||
|
||||
@@ -70,7 +70,6 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d
|
||||
|
||||
func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*notificationFromConfig) error {
|
||||
for _, notification := range notificationToMerge {
|
||||
|
||||
if notification.OrgID == 0 && notification.OrgName != "" {
|
||||
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
|
||||
if err := bus.Dispatch(getOrg); err != nil {
|
||||
|
||||
@@ -140,7 +140,6 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
|
||||
}
|
||||
|
||||
func validateNotifications(notifications []*notificationsAsConfig) error {
|
||||
|
||||
for i := range notifications {
|
||||
if notifications[i].Notifications == nil {
|
||||
continue
|
||||
|
||||
@@ -257,7 +257,6 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
nt := notificationsQuery.Result[0]
|
||||
So(nt.Name, ShouldEqual, "default-notification-create")
|
||||
So(nt.OrgId, ShouldEqual, existingOrg2.Result.Id)
|
||||
|
||||
})
|
||||
|
||||
Convey("Config doesn't contain required field", func() {
|
||||
|
||||
@@ -89,7 +89,6 @@ func (ps *provisioningServiceImpl) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
for {
|
||||
|
||||
// Wait for unlock. This is tied to new dashboardProvisioner to be instantiated before we start polling.
|
||||
ps.mutex.Lock()
|
||||
// Using background here because otherwise if root context was canceled the select later on would
|
||||
|
||||
@@ -37,7 +37,6 @@ func TestProvisioningServiceImpl(t *testing.T) {
|
||||
|
||||
assert.False(t, serviceTest.serviceRunning, "Service should not be running")
|
||||
assert.Equal(t, context.Canceled, serviceTest.serviceError, "Service should have returned canceled error")
|
||||
|
||||
})
|
||||
|
||||
t.Run("Failed reloading does not stop polling with old provisioned", func(t *testing.T) {
|
||||
|
||||
@@ -124,7 +124,6 @@ func TestValues(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("JSONValue", func() {
|
||||
|
||||
type Data struct {
|
||||
Val JSONValue `yaml:"val"`
|
||||
}
|
||||
@@ -237,7 +236,6 @@ func TestValues(t *testing.T) {
|
||||
"three": "$STRING",
|
||||
"four": "true",
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ func (qs *QuotaService) QuotaReached(c *models.ReqContext, target string) (bool,
|
||||
return true, nil
|
||||
}
|
||||
if target == "session" {
|
||||
|
||||
usedSessions, err := qs.AuthTokenService.ActiveTokenCount(c.Req.Context())
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@@ -218,7 +218,6 @@ func (rs *RenderingService) getURL(path string) string {
|
||||
|
||||
// &render=1 signals to the legacy redirect layer to
|
||||
return fmt.Sprintf("%s%s&render=1", rs.Cfg.RendererCallbackUrl, path)
|
||||
|
||||
}
|
||||
|
||||
protocol := setting.Protocol
|
||||
|
||||
@@ -217,7 +217,6 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
|
||||
} else {
|
||||
sql.WriteString(fmt.Sprintf(" AND (%s) = %d ", tagsSubQuery, len(tags)))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -279,7 +279,6 @@ func TestAnnotations(t *testing.T) {
|
||||
So(len(items), ShouldEqual, 0)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ func TestApiKeyDataAccess(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, query.Result)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
t.Run("Add non expiring key", func(t *testing.T) {
|
||||
|
||||
@@ -73,9 +73,7 @@ func GetDashboardAclInfoList(query *models.GetDashboardAclInfoListQuery) error {
|
||||
WHERE da.dashboard_id = -1`
|
||||
query.Result = make([]*models.DashboardAclInfoDTO, 0)
|
||||
err = x.SQL(sql).Find(&query.Result)
|
||||
|
||||
} else {
|
||||
|
||||
rawSQL := `
|
||||
-- get permissions for the dashboard and its parent folder
|
||||
SELECT
|
||||
|
||||
@@ -129,7 +129,6 @@ func TestIntegratedDashboardService(t *testing.T) {
|
||||
// Given user has no permission to save
|
||||
|
||||
permissionScenario("Given user has no permission to save", false, func(sc *dashboardPermissionScenarioContext) {
|
||||
|
||||
Convey("When creating a new dashboard in the General folder", func() {
|
||||
cmd := models.SaveDashboardCommand{
|
||||
OrgId: testOrgId,
|
||||
@@ -370,7 +369,6 @@ func TestIntegratedDashboardService(t *testing.T) {
|
||||
// Given user has permission to save
|
||||
|
||||
permissionScenario("Given user has permission to save", true, func(sc *dashboardPermissionScenarioContext) {
|
||||
|
||||
Convey("and overwrite flag is set to false", func() {
|
||||
shouldOverwrite := false
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ func DeleteExpiredSnapshots(cmd *models.DeleteExpiredSnapshotsCommand) error {
|
||||
|
||||
func CreateDashboardSnapshot(cmd *models.CreateDashboardSnapshotCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
// never
|
||||
var expires = time.Now().Add(time.Hour * 24 * 365 * 50)
|
||||
if cmd.Expires > 0 {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
)
|
||||
|
||||
func TestDashboardSnapshotDBAccess(t *testing.T) {
|
||||
|
||||
Convey("Testing DashboardSnapshot data access", t, func() {
|
||||
InitTestDB(t)
|
||||
|
||||
|
||||
@@ -205,7 +205,6 @@ func UpdateDataSource(cmd *models.UpdateDataSourceCommand) error {
|
||||
// updates to datasources using the datasource.yaml file without knowing exactly what version
|
||||
// a datasource have in the db.
|
||||
updateSession = sess.Where("id=? and org_id=? and version < ?", ds.Id, ds.OrgId, ds.Version)
|
||||
|
||||
} else {
|
||||
updateSession = sess.Where("id=? and org_id=?", ds.Id, ds.OrgId)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
func addAlertMigrations(mg *Migrator) {
|
||||
|
||||
alertV1 := Table{
|
||||
Name: "alert",
|
||||
Columns: []*Column{
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
)
|
||||
|
||||
func addAnnotationMig(mg *Migrator) {
|
||||
|
||||
table := Table{
|
||||
Name: "annotation",
|
||||
Columns: []*Column{
|
||||
|
||||
@@ -219,5 +219,4 @@ func addDashboardMigration(mg *Migrator) {
|
||||
Cols: []string{"title"},
|
||||
Type: IndexType,
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package migrations
|
||||
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
|
||||
func addAppSettingsMigration(mg *Migrator) {
|
||||
|
||||
pluginSettingTable := Table{
|
||||
Name: "plugin_setting",
|
||||
Columns: []*Column{
|
||||
|
||||
@@ -3,7 +3,6 @@ package migrations
|
||||
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
|
||||
func addPreferencesMigrations(mg *Migrator) {
|
||||
|
||||
mg.AddMigration("drop preferences table v2", NewDropTableMigration("preferences"))
|
||||
|
||||
preferencesV2 := Table{
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
func addQuotaMigration(mg *Migrator) {
|
||||
|
||||
var quotaV1 = Table{
|
||||
Name: "quota",
|
||||
Columns: []*Column{
|
||||
|
||||
@@ -3,7 +3,6 @@ package migrations
|
||||
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
|
||||
func addTagMigration(mg *Migrator) {
|
||||
|
||||
tagTable := Table{
|
||||
Name: "tag",
|
||||
Columns: []*Column{
|
||||
|
||||
@@ -91,7 +91,6 @@ func isOrgNameTaken(name string, existingId int64, sess *DBSession) (bool, error
|
||||
|
||||
func CreateOrg(cmd *models.CreateOrgCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
if isNameTaken, err := isOrgNameTaken(cmd.Name, 0, sess); err != nil {
|
||||
return err
|
||||
} else if isNameTaken {
|
||||
@@ -131,7 +130,6 @@ func CreateOrg(cmd *models.CreateOrgCommand) error {
|
||||
|
||||
func UpdateOrg(cmd *models.UpdateOrgCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
if isNameTaken, err := isOrgNameTaken(cmd.Name, cmd.OrgId, sess); err != nil {
|
||||
return err
|
||||
} else if isNameTaken {
|
||||
|
||||
@@ -114,7 +114,6 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(orgUsersQuery.Result[1].Role, ShouldEqual, models.ROLE_ADMIN)
|
||||
|
||||
})
|
||||
|
||||
Convey("Can get logged in user projection", func() {
|
||||
@@ -282,7 +281,6 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
So(permQuery.Result[0].OrgId, ShouldEqual, ac3.OrgId)
|
||||
So(permQuery.Result[0].UserId, ShouldEqual, ac3.Id)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestPlaylistDataAccess(t *testing.T) {
|
||||
|
||||
Convey("Testing Playlist data access", t, func() {
|
||||
InitTestDB(t)
|
||||
|
||||
|
||||
@@ -107,9 +107,7 @@ func UpdatePluginSetting(cmd *models.UpdatePluginSettingCmd) error {
|
||||
|
||||
func UpdatePluginSettingVersion(cmd *models.UpdatePluginSettingVersionCmd) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
_, err := sess.Exec("UPDATE plugin_setting SET plugin_version=? WHERE org_id=? AND plugin_id=?", cmd.PluginVersion, cmd.OrgId, cmd.PluginId)
|
||||
return err
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +80,6 @@ func GetPreferences(query *models.GetPreferencesQuery) error {
|
||||
|
||||
func SavePreferences(cmd *models.SavePreferencesCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
var prefs models.Preferences
|
||||
exists, err := sess.Where("org_id=? AND user_id=? AND team_id=?", cmd.OrgId, cmd.UserId, cmd.TeamId).Get(&prefs)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
func TestQuotaCommandsAndQueries(t *testing.T) {
|
||||
|
||||
Convey("Testing Quota commands & queries", t, func() {
|
||||
InitTestDB(t)
|
||||
userId := int64(1)
|
||||
@@ -101,7 +100,6 @@ func TestQuotaCommandsAndQueries(t *testing.T) {
|
||||
}
|
||||
So(res.Limit, ShouldEqual, limit)
|
||||
So(res.Used, ShouldEqual, used)
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,7 +13,6 @@ func init() {
|
||||
}
|
||||
|
||||
func sqlRandomWalk(m1 string, m2 string, intWalker int64, floatWalker float64, sess *DBSession) error {
|
||||
|
||||
timeWalker := time.Now().UTC().Add(time.Hour * -200)
|
||||
now := time.Now().UTC()
|
||||
step := time.Minute
|
||||
|
||||
@@ -29,7 +29,6 @@ func (sb *SqlBuilder) AddParams(params ...interface{}) {
|
||||
}
|
||||
|
||||
func (sb *SqlBuilder) writeDashboardPermissionFilter(user *models.SignedInUser, permission models.PermissionType) {
|
||||
|
||||
if user.OrgRole == models.ROLE_ADMIN {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ func StarDashboard(cmd *models.StarDashboardCommand) error {
|
||||
}
|
||||
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
entity := models.Star{
|
||||
UserId: cmd.UserId,
|
||||
DashboardId: cmd.DashboardId,
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestUserStarsDataAccess(t *testing.T) {
|
||||
|
||||
Convey("Testing User Stars Data Access", t, func() {
|
||||
InitTestDB(t)
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ func getTeamSelectSqlBase() string {
|
||||
|
||||
func CreateTeam(cmd *models.CreateTeamCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
if isNameTaken, err := isTeamNameTaken(cmd.OrgId, cmd.Name, 0, sess); err != nil {
|
||||
return err
|
||||
} else if isNameTaken {
|
||||
@@ -73,7 +72,6 @@ func CreateTeam(cmd *models.CreateTeamCommand) error {
|
||||
|
||||
func UpdateTeam(cmd *models.UpdateTeamCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
if isNameTaken, err := isTeamNameTaken(cmd.OrgId, cmd.Name, cmd.Id, sess); err != nil {
|
||||
return err
|
||||
} else if isNameTaken {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func TestTeamCommandsAndQueries(t *testing.T) {
|
||||
|
||||
Convey("Testing Team commands & queries", t, func() {
|
||||
InitTestDB(t)
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ func UpdateTempUserStatus(cmd *models.UpdateTempUserStatusCommand) error {
|
||||
|
||||
func CreateTempUser(cmd *models.CreateTempUserCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
// create user
|
||||
user := &models.TempUser{
|
||||
Email: cmd.Email,
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestTempUserCommandsAndQueries(t *testing.T) {
|
||||
|
||||
Convey("Testing Temp User commands & queries", t, func() {
|
||||
InitTestDB(t)
|
||||
|
||||
|
||||
@@ -213,7 +213,6 @@ func GetUserByEmail(query *models.GetUserByEmailQuery) error {
|
||||
|
||||
func UpdateUser(cmd *models.UpdateUserCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
user := models.User{
|
||||
Name: cmd.Name,
|
||||
Email: cmd.Email,
|
||||
@@ -240,7 +239,6 @@ func UpdateUser(cmd *models.UpdateUserCommand) error {
|
||||
|
||||
func ChangeUserPassword(cmd *models.ChangeUserPasswordCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
user := models.User{
|
||||
Password: cmd.NewPassword,
|
||||
Updated: time.Now(),
|
||||
@@ -614,7 +612,6 @@ func UpdateUserPermissions(cmd *models.UpdateUserPermissionsCommand) error {
|
||||
|
||||
func SetUserHelpFlag(cmd *models.SetUserHelpFlagCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
|
||||
user := models.User{
|
||||
Id: cmd.UserId,
|
||||
HelpFlags1: cmd.HelpFlags1,
|
||||
|
||||
@@ -167,7 +167,6 @@ func TestUserAuth(t *testing.T) {
|
||||
So(getAuthQuery.Result.OAuthAccessToken, ShouldEqual, token.AccessToken)
|
||||
So(getAuthQuery.Result.OAuthRefreshToken, ShouldEqual, token.RefreshToken)
|
||||
So(getAuthQuery.Result.OAuthTokenType, ShouldEqual, token.TokenType)
|
||||
|
||||
})
|
||||
|
||||
Convey("Always return the most recently used auth_module", func() {
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
)
|
||||
|
||||
func TestUserDataAccess(t *testing.T) {
|
||||
|
||||
Convey("Testing DB", t, func() {
|
||||
ss := InitTestDB(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user