mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Enable whitespace linter (#25903)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
42295898b8
commit
41d432b5ae
@ -826,7 +826,7 @@ jobs:
|
||||
command: |
|
||||
# To save memory, run in two batches
|
||||
golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.toml -E deadcode -E depguard -E dogsled \
|
||||
-E errcheck -E goconst -E golint -E gosec -E gosimple -E govet -E scopelint ./pkg/...
|
||||
-E errcheck -E goconst -E golint -E gosec -E gosimple -E govet -E scopelint -E whitespace ./pkg/...
|
||||
golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.toml -E ineffassign \
|
||||
-E rowserrcheck -E staticcheck -E structcheck -E typecheck -E unconvert -E unused -E varcheck ./pkg/...
|
||||
./scripts/go/bin/revive -formatter stylish -config ./scripts/go/configs/revive.toml ./pkg/...
|
||||
|
@ -39,7 +39,6 @@ func AdminGetSettings(c *models.ReqContext) {
|
||||
}
|
||||
|
||||
func AdminGetStats(c *models.ReqContext) {
|
||||
|
||||
statsQuery := models.GetAdminStatsQuery{}
|
||||
|
||||
if err := bus.Dispatch(&statsQuery); err != nil {
|
||||
|
@ -21,7 +21,6 @@ const (
|
||||
func TestAdminApiEndpoint(t *testing.T) {
|
||||
role := models.ROLE_ADMIN
|
||||
Convey("Given a server admin attempts to remove themself as an admin", t, func() {
|
||||
|
||||
updateCmd := dtos.AdminUpdateUserPermissionsForm{
|
||||
IsGrafanaAdmin: false,
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
func TestAlertingApiEndpoint(t *testing.T) {
|
||||
Convey("Given an alert in a dashboard with an acl", t, func() {
|
||||
|
||||
singleAlert := &models.Alert{Id: 1, DashboardId: 1, Name: "singlealert"}
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetAlertByIdQuery) error {
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func GetAnnotations(c *models.ReqContext) Response {
|
||||
|
||||
query := &annotations.ItemQuery{
|
||||
From: c.QueryInt64("from"),
|
||||
To: c.QueryInt64("to"),
|
||||
|
@ -112,7 +112,6 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
|
||||
// authed api
|
||||
r.Group("/api", func(apiRoute routing.RouteRegister) {
|
||||
|
||||
// user (signed in)
|
||||
apiRoute.Group("/user", func(userRoute routing.RouteRegister) {
|
||||
userRoute.Get("/", Wrap(GetSignedInUser))
|
||||
@ -383,7 +382,6 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
|
||||
// error test
|
||||
r.Get("/metrics/error", Wrap(GenerateError))
|
||||
|
||||
}, reqSignedIn)
|
||||
|
||||
// admin api
|
||||
|
@ -31,7 +31,6 @@ type NormalResponse struct {
|
||||
}
|
||||
|
||||
func Wrap(action interface{}) macaron.Handler {
|
||||
|
||||
return func(c *models.ReqContext) {
|
||||
var res Response
|
||||
val, err := c.Invoke(action)
|
||||
@ -48,7 +47,6 @@ func Wrap(action interface{}) macaron.Handler {
|
||||
func (r *NormalResponse) WriteTo(ctx *models.ReqContext) {
|
||||
if r.err != nil {
|
||||
ctx.Logger.Error(r.errMessage, "error", r.err, "remote_addr", ctx.RemoteAddr())
|
||||
|
||||
}
|
||||
|
||||
header := ctx.Resp.Header()
|
||||
|
@ -458,7 +458,6 @@ func GetDashboardVersion(c *models.ReqContext) Response {
|
||||
|
||||
// POST /api/dashboards/calculate-diff performs diffs on two dashboards
|
||||
func CalculateDashboardDiff(c *models.ReqContext, apiOptions dtos.CalculateDiffOptions) Response {
|
||||
|
||||
guardianBase := guardian.New(apiOptions.Base.DashboardId, c.OrgId, c.SignedInUser)
|
||||
if canSave, err := guardianBase.CanSave(); err != nil || !canSave {
|
||||
return dashboardGuardianResponse(err)
|
||||
|
@ -716,7 +716,6 @@ func TestDashboardApiEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Post dashboard response tests", t, func() {
|
||||
|
||||
// This tests that a valid request returns correct response
|
||||
|
||||
Convey("Given a correct request for creating a dashboard", func() {
|
||||
@ -953,7 +952,6 @@ func TestDashboardApiEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Given provisioned dashboard", t, func() {
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardsBySlugQuery) error {
|
||||
query.Result = []*models.Dashboard{{}}
|
||||
return nil
|
||||
@ -1062,7 +1060,6 @@ func GetDashboardShouldReturn200(sc *scenarioContext) dtos.DashboardFullWithMeta
|
||||
}
|
||||
|
||||
func CallGetDashboard(sc *scenarioContext, hs *HTTPServer) {
|
||||
|
||||
sc.handlerFunc = hs.GetDashboard
|
||||
sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec()
|
||||
}
|
||||
|
@ -225,7 +225,6 @@ func fillWithSecureJSONData(cmd *models.UpdateDataSourceCommand) error {
|
||||
|
||||
secureJSONData := ds.SecureJsonData.Decrypt()
|
||||
for k, v := range secureJSONData {
|
||||
|
||||
if _, ok := cmd.SecureJsonData[k]; !ok {
|
||||
cmd.SecureJsonData[k] = v
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ const (
|
||||
func TestDataSourcesProxy(t *testing.T) {
|
||||
Convey("Given a user is logged in", t, func() {
|
||||
loggedInUserScenario("When calling GET on", "/api/datasources/", func(sc *scenarioContext) {
|
||||
|
||||
// Stubs the database query
|
||||
bus.AddHandler("test", func(query *models.GetDataSourcesQuery) error {
|
||||
So(query.OrgId, ShouldEqual, TestOrgID)
|
||||
|
@ -93,7 +93,6 @@ func (c *connection) handleMessage(message []byte) {
|
||||
case "unsubscribe":
|
||||
c.hub.subChannel <- &streamSubscription{name: streamName, conn: c, remove: true}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *connection) write(mt int, payload []byte) error {
|
||||
|
@ -88,7 +88,6 @@ func NewStream(name string) *Stream {
|
||||
}
|
||||
|
||||
func (s *Stream) Push(packet *models.StreamPacket) {
|
||||
|
||||
messageBytes, _ := simplejson.NewFromAny(packet).Encode()
|
||||
|
||||
for _, sub := range s.subscribers {
|
||||
|
@ -30,7 +30,6 @@ import (
|
||||
)
|
||||
|
||||
func TestDSRouteRule(t *testing.T) {
|
||||
|
||||
Convey("DataSourceProxy", t, func() {
|
||||
Convey("Plugin with routes", func() {
|
||||
plugin := &plugins.DataSourcePlugin{
|
||||
|
@ -60,7 +60,6 @@ func NewApiPluginProxy(ctx *models.ReqContext, proxyPath string, route *plugins.
|
||||
targetURL, _ := url.Parse(route.URL)
|
||||
|
||||
director := func(req *http.Request) {
|
||||
|
||||
req.URL.Scheme = targetURL.Scheme
|
||||
req.URL.Host = targetURL.Host
|
||||
req.Host = targetURL.Host
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
)
|
||||
|
||||
func TestPluginProxy(t *testing.T) {
|
||||
|
||||
Convey("When getting proxy headers", t, func() {
|
||||
route := &plugins.AppPluginRoute{
|
||||
Headers: []plugins.AppPluginRouteHeader{
|
||||
@ -129,7 +128,6 @@ func TestPluginProxy(t *testing.T) {
|
||||
So(route.URL, ShouldEqual, "{{.JsonData.dynamicUrl}}")
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// getPluginProxiedRequest is a helper for easier setup of tests based on global config and ReqContext.
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
// POST /api/preferences/set-home-dash
|
||||
func SetHomeDashboard(c *models.ReqContext, cmd models.SavePreferencesCommand) Response {
|
||||
|
||||
cmd.UserId = c.UserId
|
||||
cmd.OrgId = c.OrgId
|
||||
|
||||
|
@ -72,10 +72,8 @@ type routeRegister struct {
|
||||
}
|
||||
|
||||
func (rr *routeRegister) Insert(pattern string, fn func(RouteRegister), handlers ...macaron.Handler) {
|
||||
|
||||
//loop over all groups at current level
|
||||
for _, g := range rr.groups {
|
||||
|
||||
// apply routes if the prefix matches the pattern
|
||||
if g.prefix == pattern {
|
||||
g.Group("", fn)
|
||||
|
@ -108,7 +108,6 @@ func TestRouteGroupedRegister(t *testing.T) {
|
||||
user.Group("/admin", func(admin RouteRegister) {
|
||||
admin.Delete("", emptyHandler("3"))
|
||||
admin.Get("/all", emptyHandler("3"), emptyHandler("4"), emptyHandler("5"))
|
||||
|
||||
}, emptyHandler("3"))
|
||||
})
|
||||
|
||||
@ -235,7 +234,6 @@ func TestNamedMiddlewareRouteRegister(t *testing.T) {
|
||||
user.Group("/admin", func(admin RouteRegister) {
|
||||
admin.Delete("", emptyHandler("3"))
|
||||
admin.Get("/all", emptyHandler("3"), emptyHandler("4"), emptyHandler("5"))
|
||||
|
||||
}, emptyHandler("3"))
|
||||
})
|
||||
|
||||
|
@ -24,7 +24,6 @@ func StarDashboard(c *models.ReqContext) Response {
|
||||
}
|
||||
|
||||
func UnstarDashboard(c *models.ReqContext) Response {
|
||||
|
||||
cmd := models.UnstarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
|
||||
|
||||
if cmd.DashboardId <= 0 {
|
||||
|
@ -21,7 +21,6 @@ func (cmd Command) listRemoteCommand(c utils.CommandLine) error {
|
||||
logger.Infof("id: %v version: %s\n", plugin.Id, ver.Version)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestApiKeyGen(t *testing.T) {
|
||||
|
||||
Convey("When generating new api key", t, func() {
|
||||
result, err := New(12, "Cool key")
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -162,7 +162,6 @@ func (b *BasicDiff) Basic(lines []*JSONLine) []*BasicBlock {
|
||||
// know there's a change somewhere in the JSON tree, but we
|
||||
// don't know exactly where, so we go deeper.
|
||||
} else {
|
||||
|
||||
// if the change is anything but unchanged, continue processing
|
||||
//
|
||||
// we keep "narrowing" the key as we go deeper, in order to
|
||||
|
@ -240,7 +240,6 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
|
||||
positionStr := position.String()
|
||||
if len(matchedDeltas) > 0 {
|
||||
for _, matchedDelta := range matchedDeltas {
|
||||
|
||||
switch matchedDelta := matchedDelta.(type) {
|
||||
case *diff.Object:
|
||||
switch value.(type) {
|
||||
@ -314,7 +313,6 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
|
||||
default:
|
||||
return errors.New("Unknown Delta type detected")
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
f.printRecursive(positionStr, value, ChangeUnchanged)
|
||||
|
@ -61,7 +61,6 @@ func TestDiff(t *testing.T) {
|
||||
)
|
||||
|
||||
Convey("Testing dashboard diffs", t, func() {
|
||||
|
||||
// Compute the diff between the two JSON objects
|
||||
baseData, err := simplejson.NewJson([]byte(leftJSON))
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -27,7 +27,6 @@ var (
|
||||
)
|
||||
|
||||
func NewImageUploader() (ImageUploader, error) {
|
||||
|
||||
switch setting.ImageUploadProvider {
|
||||
case "s3":
|
||||
s3sec, err := setting.Raw.GetSection("external_image_storage.s3")
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestUploadToWebdav(t *testing.T) {
|
||||
|
||||
// Can be tested with this docker container: https://hub.docker.com/r/morrisjobke/webdav/
|
||||
SkipConvey("[Integration test] for external_image_store.webdav", t, func() {
|
||||
webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "")
|
||||
|
@ -12,7 +12,6 @@ type TestEvent struct {
|
||||
}
|
||||
|
||||
func TestEventCreation(t *testing.T) {
|
||||
|
||||
Convey("Event to wire event", t, func() {
|
||||
e := TestEvent{
|
||||
Timestamp: time.Unix(1231421123, 223),
|
||||
@ -22,5 +21,4 @@ func TestEventCreation(t *testing.T) {
|
||||
So(e.Timestamp.Unix(), ShouldEqual, wire.Timestamp.Unix())
|
||||
So(wire.EventType, ShouldEqual, "TestEvent")
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ func (w *FileLogWriter) WriteLine(line string) error {
|
||||
}
|
||||
|
||||
func TestLogFile(t *testing.T) {
|
||||
|
||||
Convey("When logging to file", t, func() {
|
||||
fileLogWrite := NewFileWriter()
|
||||
So(fileLogWrite, ShouldNotBeNil)
|
||||
|
@ -264,7 +264,6 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) error {
|
||||
|
||||
func LogFilterHandler(maxLevel log15.Lvl, filters map[string]log15.Lvl, h log15.Handler) log15.Handler {
|
||||
return log15.FilterHandler(func(r *log15.Record) (pass bool) {
|
||||
|
||||
if len(filters) > 0 {
|
||||
for i := 0; i < len(r.Ctx); i += 2 {
|
||||
key, ok := r.Ctx[i].(string)
|
||||
|
@ -571,7 +571,6 @@ func initMetricVars() {
|
||||
StatsTotalDashboardVersions,
|
||||
StatsTotalAnnotations,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func newCounterVecStartingAtZero(opts prometheus.CounterOpts, labels []string, labelValues ...string) *prometheus.CounterVec {
|
||||
|
@ -130,7 +130,6 @@ func (dc *databaseCache) Delete(key string) error {
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// CacheData is the struct representing the table in the database
|
||||
|
@ -95,6 +95,5 @@ func Test_parseRedisConnStr(t *testing.T) {
|
||||
}
|
||||
assert.NoError(t, err, reason)
|
||||
assert.EqualValues(t, testCase.OutputOptions, options, reason)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ func TestMetrics(t *testing.T) {
|
||||
|
||||
var getSystemStatsQuery *models.GetSystemStatsQuery
|
||||
uss.Bus.AddHandler(func(query *models.GetSystemStatsQuery) error {
|
||||
|
||||
query.Result = &models.SystemStats{
|
||||
Dashboards: 1,
|
||||
Datasources: 2,
|
||||
@ -273,7 +272,6 @@ func TestMetrics(t *testing.T) {
|
||||
So(metrics.Get("stats.auth_enabled.oauth_grafana_com.count").MustInt(), ShouldEqual, 1)
|
||||
|
||||
So(metrics.Get("stats.packaging.deb.count").MustInt(), ShouldEqual, 1)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -77,7 +77,6 @@ func DisableExternalUser(username string) error {
|
||||
|
||||
userInfo := userQuery.Result
|
||||
if !userInfo.IsDisabled {
|
||||
|
||||
ldapLogger.Debug(
|
||||
"Disabling external user",
|
||||
"user",
|
||||
|
@ -251,7 +251,6 @@ func TestSocialAzureAD_UserInfo(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
token := &oauth2.Token{}
|
||||
|
@ -114,7 +114,6 @@ func (s *SocialGithub) FetchTeamMemberships(client *http.Client) ([]GithubTeam,
|
||||
teams := make([]GithubTeam, 0)
|
||||
|
||||
for hasMore {
|
||||
|
||||
response, err := HttpGet(client, url)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error getting team memberships: %s", err)
|
||||
@ -136,7 +135,6 @@ func (s *SocialGithub) FetchTeamMemberships(client *http.Client) ([]GithubTeam,
|
||||
}
|
||||
|
||||
func (s *SocialGithub) HasMoreRecords(headers http.Header) (string, bool) {
|
||||
|
||||
value, exists := headers["Link"]
|
||||
if !exists {
|
||||
return "", false
|
||||
@ -152,7 +150,6 @@ func (s *SocialGithub) HasMoreRecords(headers http.Header) (string, bool) {
|
||||
url := matches[1]
|
||||
|
||||
return url, true
|
||||
|
||||
}
|
||||
|
||||
func (s *SocialGithub) FetchOrganizations(client *http.Client, organizationsUrl string) ([]string, error) {
|
||||
@ -181,7 +178,6 @@ func (s *SocialGithub) FetchOrganizations(client *http.Client, organizationsUrl
|
||||
}
|
||||
|
||||
func (s *SocialGithub) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error) {
|
||||
|
||||
var data struct {
|
||||
Id int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
|
@ -90,7 +90,6 @@ func (s *SocialGitlab) GetGroupsPage(client *http.Client, url string) ([]string,
|
||||
}
|
||||
|
||||
func (s *SocialGitlab) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error) {
|
||||
|
||||
var data struct {
|
||||
Id int
|
||||
Username string
|
||||
|
@ -102,7 +102,6 @@ func New(options *Options) *AuthProxy {
|
||||
|
||||
// IsEnabled checks if the proxy auth is enabled
|
||||
func (auth *AuthProxy) IsEnabled() bool {
|
||||
|
||||
// Bail if the setting is not enabled
|
||||
return auth.enabled
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestMiddlewareAuth(t *testing.T) {
|
||||
|
||||
Convey("Given the grafana middleware", t, func() {
|
||||
reqSignIn := Auth(&AuthOptions{ReqSignedIn: true})
|
||||
|
||||
|
@ -80,5 +80,4 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ func TestMiddleWareSecurityHeaders(t *testing.T) {
|
||||
setting.ERR_TEMPLATE_NAME = errorTemplate
|
||||
|
||||
Convey("Given the grafana middleware", t, func() {
|
||||
|
||||
middlewareScenario(t, "middleware should get correct x-xss-protection header", func(sc *scenarioContext) {
|
||||
setting.XSSProtectionHeader = true
|
||||
sc.fakeReq("GET", "/api/").exec()
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func TestOrgRedirectMiddleware(t *testing.T) {
|
||||
|
||||
Convey("Can redirect to correct org", t, func() {
|
||||
middlewareScenario(t, "when setting a correct org for the user", func(sc *scenarioContext) {
|
||||
sc.withTokenSessionCookie("token")
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
)
|
||||
|
||||
func TestMiddlewareQuota(t *testing.T) {
|
||||
|
||||
Convey("Given the grafana quota middleware", t, func() {
|
||||
setting.AnonymousEnabled = false
|
||||
setting.Quota = setting.QuotaSettings{
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestDashboardAclModel(t *testing.T) {
|
||||
|
||||
Convey("When printing a PermissionType", t, func() {
|
||||
view := PERMISSION_VIEW
|
||||
printed := fmt.Sprint(view)
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestDashboardModel(t *testing.T) {
|
||||
|
||||
Convey("Generate full dashboard url", t, func() {
|
||||
setting.AppUrl = "http://grafana.local/"
|
||||
fullUrl := GetFullDashboardUrl("uid", "my-dashboard")
|
||||
|
@ -113,7 +113,6 @@ type DashTemplateEvaluator struct {
|
||||
}
|
||||
|
||||
func (this *DashTemplateEvaluator) findInput(varName string, varType string) *ImportDashboardInput {
|
||||
|
||||
for _, input := range this.inputs {
|
||||
if varType == input.Type && (input.Name == varName || input.Name == "*") {
|
||||
return &input
|
||||
@ -146,7 +145,6 @@ func (this *DashTemplateEvaluator) Eval() (*simplejson.Json, error) {
|
||||
}
|
||||
|
||||
func (this *DashTemplateEvaluator) evalValue(source *simplejson.Json) interface{} {
|
||||
|
||||
sourceValue := source.Interface()
|
||||
|
||||
switch v := sourceValue.(type) {
|
||||
|
@ -80,7 +80,6 @@ func TestDashboardImport(t *testing.T) {
|
||||
inputs := res.Get("__inputs")
|
||||
So(inputs.Interface(), ShouldBeNil)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -65,5 +65,4 @@ func TestPluginDashboards(t *testing.T) {
|
||||
So(dashboards[1].ImportedRevision, ShouldEqual, 0)
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
|
||||
}
|
||||
|
||||
func (fp *FrontendPluginBase) handleModuleDefaults() {
|
||||
|
||||
if isExternalPlugin(fp.PluginDir) {
|
||||
fp.Module = path.Join("plugins", fp.Id, "module")
|
||||
fp.BaseUrl = path.Join("public/plugins", fp.Id)
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func TestFrontendPlugin(t *testing.T) {
|
||||
|
||||
Convey("When setting paths based on App on Windows", t, func() {
|
||||
setting.StaticRootPath = "c:\\grafana\\public"
|
||||
|
||||
|
@ -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 {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user