mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Merge pull request #882 from prymitive/gofmt
feat(ci): test code formatting on Travis
This commit is contained in:
19
.travis.yml
19
.travis.yml
@@ -63,12 +63,31 @@ jobs:
|
||||
- travis_retry make mock-assets
|
||||
script: make lint-go
|
||||
|
||||
- stage: Lint
|
||||
<<: *DEFAULTS_GO
|
||||
env:
|
||||
- DESC="Check Go code formatting"
|
||||
- GO111MODULE=on
|
||||
before_script:
|
||||
- travis_retry make mock-assets
|
||||
script:
|
||||
- make format-go
|
||||
- git diff --exit-code
|
||||
|
||||
- stage: Lint
|
||||
<<: *DEFAULTS_JS
|
||||
env:
|
||||
- DESC="Lint JavaScript code"
|
||||
script: make lint-js
|
||||
|
||||
- stage: Lint
|
||||
<<: *DEFAULTS_JS
|
||||
env:
|
||||
- DESC="Check JavaScript code formatting"
|
||||
script:
|
||||
- make format-js
|
||||
- git diff --exit-code
|
||||
|
||||
- stage: Lint
|
||||
<<: *DEFAULTS_JS
|
||||
env:
|
||||
|
||||
6
Makefile
6
Makefile
@@ -131,8 +131,12 @@ test-js: .build/deps-build-node.ok
|
||||
.PHONY: test
|
||||
test: lint test-go test-js
|
||||
|
||||
.PHONY: format-go
|
||||
format-go: .build/deps-build-go.ok
|
||||
gofmt -l -s -w .
|
||||
|
||||
.PHONY: format-js
|
||||
format-js:
|
||||
format-js: .build/deps-build-node.ok
|
||||
cd ui && ./node_modules/.bin/prettier --write 'src/**/*.js'
|
||||
|
||||
.PHONY: show-version
|
||||
|
||||
96
api_test.go
96
api_test.go
@@ -32,7 +32,7 @@ var groupTests = []groupTest{
|
||||
"alertname": "Memory_Usage_Too_High",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Memory usage exceeding threshold"},
|
||||
@@ -45,7 +45,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -69,14 +69,14 @@ var groupTests = []groupTest{
|
||||
"cluster": "prod",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 0, 0, 1, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Memory usage exceeding threshold"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -105,11 +105,11 @@ var groupTests = []groupTest{
|
||||
"cluster": "staging",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -123,10 +123,10 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -140,10 +140,10 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -172,11 +172,11 @@ var groupTests = []groupTest{
|
||||
"cluster": "dev",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 1, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -190,11 +190,11 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 59, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -208,11 +208,11 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 12, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -240,7 +240,7 @@ var groupTests = []groupTest{
|
||||
"alertname": "Host_Down",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 1, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
@@ -252,7 +252,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -261,7 +261,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 1, 0, 1, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -271,7 +271,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -280,7 +280,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 1, 0, 1, 0, 1, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -290,7 +290,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -299,7 +299,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 1, 0, 0, 59, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -309,7 +309,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -318,7 +318,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -328,7 +328,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -337,7 +337,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 1, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -347,7 +347,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateSuppressed,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -356,7 +356,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 20, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -366,7 +366,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateSuppressed,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -375,7 +375,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 21, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Labels: map[string]string{
|
||||
@@ -385,7 +385,7 @@ var groupTests = []groupTest{
|
||||
},
|
||||
State: models.AlertStateSuppressed,
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -409,14 +409,14 @@ var groupTests = []groupTest{
|
||||
"cluster": "staging",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 0, 19, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Less than 10% disk space is free"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -446,13 +446,13 @@ var groupTests = []groupTest{
|
||||
"cluster": "prod",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 12, 0, 19, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -466,10 +466,10 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateActive,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -497,14 +497,14 @@ var groupTests = []groupTest{
|
||||
"alertname": "HTTP_Probe_Failed",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 14, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "help", Value: "Example help annotation"},
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -516,11 +516,11 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-name",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 14, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -547,14 +547,14 @@ var groupTests = []groupTest{
|
||||
"alertname": "Free_Disk_Space_Too_Low",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 15, 0, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "alert", Value: "Less than 10% disk space is free"},
|
||||
models.Annotation{Visible: true, Name: "dashboard", Value: "http://localhost/dashboard.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -585,14 +585,14 @@ var groupTests = []groupTest{
|
||||
"cluster": "dev",
|
||||
},
|
||||
alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 20, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{Visible: true, Name: "help", Value: "Example help annotation"},
|
||||
models.Annotation{Visible: true, Name: "url", Value: "http://localhost/example.html", IsLink: true},
|
||||
},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateSuppressed,
|
||||
Source: "localhost/prometheus",
|
||||
@@ -605,11 +605,11 @@ var groupTests = []groupTest{
|
||||
State: models.AlertStateSuppressed,
|
||||
Receiver: "by-cluster-service",
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
StartsAt: time.Date(2019, time.January, 10, 19, 0, 0, 0, time.UTC),
|
||||
Annotations: models.Annotations{},
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
Source: "localhost/prometheus",
|
||||
|
||||
@@ -300,7 +300,7 @@ func (am *Alertmanager) pullAlerts(version string) error {
|
||||
}
|
||||
|
||||
alert.Alertmanager = []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: am.Name,
|
||||
Cluster: am.ClusterID(),
|
||||
State: alert.State,
|
||||
|
||||
@@ -246,7 +246,7 @@ func (config *configSchema) Read() {
|
||||
if len(config.Alertmanager.Servers) == 0 && v.GetString("alertmanager.uri") != "" {
|
||||
log.Info("Using simple config with a single Alertmanager server")
|
||||
config.Alertmanager.Servers = []alertmanagerConfig{
|
||||
alertmanagerConfig{
|
||||
{
|
||||
Name: v.GetString("alertmanager.name"),
|
||||
URI: v.GetString("alertmanager.uri"),
|
||||
Timeout: v.GetDuration("alertmanager.timeout"),
|
||||
|
||||
@@ -204,23 +204,23 @@ type urlSecretTest struct {
|
||||
}
|
||||
|
||||
var urlSecretTests = []urlSecretTest{
|
||||
urlSecretTest{
|
||||
{
|
||||
raw: "http://localhost",
|
||||
sanitized: "http://localhost",
|
||||
},
|
||||
urlSecretTest{
|
||||
{
|
||||
raw: "http://alertmanager.example.com/path",
|
||||
sanitized: "http://alertmanager.example.com/path",
|
||||
},
|
||||
urlSecretTest{
|
||||
{
|
||||
raw: "http://user@alertmanager.example.com/path",
|
||||
sanitized: "http://user@alertmanager.example.com/path",
|
||||
},
|
||||
urlSecretTest{
|
||||
{
|
||||
raw: "https://user:password@alertmanager.example.com/path",
|
||||
sanitized: "https://user:xxx@alertmanager.example.com/path",
|
||||
},
|
||||
urlSecretTest{
|
||||
{
|
||||
raw: "file://localhost",
|
||||
sanitized: "file://localhost",
|
||||
},
|
||||
|
||||
@@ -30,7 +30,7 @@ var acTests = []acTest{
|
||||
},
|
||||
{
|
||||
Alerts: []models.Alert{
|
||||
models.Alert{
|
||||
{
|
||||
State: models.AlertStateActive,
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
@@ -42,7 +42,7 @@ var acTests = []acTest{
|
||||
{Name: "am2"},
|
||||
},
|
||||
},
|
||||
models.Alert{
|
||||
{
|
||||
State: models.AlertStateSuppressed,
|
||||
Labels: map[string]string{
|
||||
"foo": "bar baz",
|
||||
@@ -54,7 +54,7 @@ var acTests = []acTest{
|
||||
{
|
||||
Name: "am2",
|
||||
Silences: map[string]*models.Silence{
|
||||
"1234567890": &models.Silence{
|
||||
"1234567890": {
|
||||
ID: "1234567890",
|
||||
CreatedBy: "me@example.com",
|
||||
JiraID: "JIRA-1",
|
||||
|
||||
@@ -21,194 +21,194 @@ type filterTest struct {
|
||||
}
|
||||
|
||||
var tests = []filterTest{
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=active",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state!=active",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=suppressed",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state!=suppressed",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=xx",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=:xx",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state==xx",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=~true",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=~false",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=suppressed",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", InhibitedBy: []string{"999"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state=suppressed",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "active"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@state!=suppressed",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", InhibitedBy: []string{"999"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "active"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "active", SilencedBy: []string{"abcdef"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "unprocessed"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "unprocessed", SilencedBy: []string{"abcdef"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"abcdef"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id!=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"abcdef"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id!=abcdef",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id=~cde",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"abcdef"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_id!~abc",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"zwd"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira=1",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira=2",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira!=3",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "x"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira!=4",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "4"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira!=5",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira=~abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "xxabcxx"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira=~abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "xxx"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira=~",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "xxx"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira~=",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", JiraID: "xxx"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_jira~=1",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
@@ -216,56 +216,56 @@ var tests = []filterTest{
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author=john",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "john"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author=john",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "bob"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author!=john",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "bob"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author!=john",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", CreatedBy: "john"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author!=john",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author=~",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author===x",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silence_author=!!xxx",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
@@ -273,147 +273,147 @@ var tests = []filterTest{
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age<1h",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age>1h",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Hour * -2)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age<-1h",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age>-1h",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Hour * -2)},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age=1h",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age=~1h",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age>",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age<",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age>a",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@age<10v",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{StartsAt: time.Now().Add(time.Minute * -55)},
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node!=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node!=vps1",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps2"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node=~vps",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node!~vps",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node!~abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node!~",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node=",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "node===",
|
||||
IsValid: false,
|
||||
Alert: models.Alert{Labels: map[string]string{"node": "vps1"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"key": "abc"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"key": "XXXabcx"}},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{Labels: map[string]string{"abc": "xxxab"}},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{
|
||||
@@ -423,7 +423,7 @@ var tests = []filterTest{
|
||||
},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{
|
||||
@@ -433,7 +433,7 @@ var tests = []filterTest{
|
||||
},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{
|
||||
@@ -443,105 +443,105 @@ var tests = []filterTest{
|
||||
},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", Comment: "abc"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", Comment: "abcxxx"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", Comment: "ABCD"},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{State: "suppressed", SilencedBy: []string{"1"}},
|
||||
Silence: models.Silence{ID: "1", Comment: "xzc"},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "^abb[****].*****",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silenced=true",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silenced!=false",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@silenced=~false",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@inhibited=true",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@inhibited!=false",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@inhibited=~false",
|
||||
IsValid: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@alertmanager=test",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@alertmanager=abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@alertmanager=~tes",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@alertmanager=~000",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@alertmanager!=tes",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@alertmanager!~abc",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@receiver=by-name",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{
|
||||
@@ -549,7 +549,7 @@ var tests = []filterTest{
|
||||
},
|
||||
IsMatch: true,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@receiver=by-name",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{
|
||||
@@ -557,7 +557,7 @@ var tests = []filterTest{
|
||||
},
|
||||
IsMatch: false,
|
||||
},
|
||||
filterTest{
|
||||
{
|
||||
Expression: "@receiver=~name",
|
||||
IsValid: true,
|
||||
Alert: models.Alert{
|
||||
@@ -577,7 +577,7 @@ func TestFilters(t *testing.T) {
|
||||
for _, ft := range tests {
|
||||
alert := models.Alert(ft.Alert)
|
||||
alert.Alertmanager = []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: am.Name,
|
||||
Silences: map[string]*models.Silence{},
|
||||
SilencedBy: []string{},
|
||||
@@ -626,41 +626,41 @@ type limitFilterTest struct {
|
||||
}
|
||||
|
||||
var limitTests = []limitFilterTest{
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit=3",
|
||||
IsValid: true,
|
||||
IsMatch: []bool{true, true, true},
|
||||
Hits: 0,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit=1",
|
||||
IsValid: true,
|
||||
IsMatch: []bool{true, false, false},
|
||||
Hits: 2,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit=5",
|
||||
IsValid: true,
|
||||
IsMatch: []bool{true, true, true, true, true, false, false, false},
|
||||
Hits: 3,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit=0",
|
||||
IsValid: false,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit=abc",
|
||||
IsValid: false,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit==0",
|
||||
IsValid: false,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit>0",
|
||||
IsValid: false,
|
||||
},
|
||||
limitFilterTest{
|
||||
{
|
||||
Expression: "@limit<0",
|
||||
IsValid: false,
|
||||
},
|
||||
|
||||
@@ -15,14 +15,14 @@ type matchTest struct {
|
||||
func TestEqualMatcher(t *testing.T) {
|
||||
now := time.Now()
|
||||
tests := []matchTest{
|
||||
matchTest{"a", "a", true, true},
|
||||
matchTest{"abc", "abc", true, true},
|
||||
matchTest{123, 123, true, true},
|
||||
matchTest{now, now, true, true},
|
||||
matchTest{"1", 1, true, false},
|
||||
matchTest{"a", "ab", true, false},
|
||||
matchTest{12, 13, true, false},
|
||||
matchTest{time.Now(), time.Now(), true, false},
|
||||
{"a", "a", true, true},
|
||||
{"abc", "abc", true, true},
|
||||
{123, 123, true, true},
|
||||
{now, now, true, true},
|
||||
{"1", 1, true, false},
|
||||
{"a", "ab", true, false},
|
||||
{12, 13, true, false},
|
||||
{time.Now(), time.Now(), true, false},
|
||||
}
|
||||
for _, mt := range tests {
|
||||
m := equalMatcher{}
|
||||
@@ -35,14 +35,14 @@ func TestEqualMatcher(t *testing.T) {
|
||||
func TestNotEqualMatcher(t *testing.T) {
|
||||
now := time.Now()
|
||||
tests := []matchTest{
|
||||
matchTest{"a", "a", true, false},
|
||||
matchTest{"abc", "abc", true, false},
|
||||
matchTest{123, 123, true, false},
|
||||
matchTest{now, now, true, false},
|
||||
matchTest{"1", 1, true, true},
|
||||
matchTest{"a", "ab", true, true},
|
||||
matchTest{12, 13, true, true},
|
||||
matchTest{time.Now(), time.Now(), true, true},
|
||||
{"a", "a", true, false},
|
||||
{"abc", "abc", true, false},
|
||||
{123, 123, true, false},
|
||||
{now, now, true, false},
|
||||
{"1", 1, true, true},
|
||||
{"a", "ab", true, true},
|
||||
{12, 13, true, true},
|
||||
{time.Now(), time.Now(), true, true},
|
||||
}
|
||||
for _, mt := range tests {
|
||||
m := notEqualMatcher{}
|
||||
@@ -54,16 +54,16 @@ func TestNotEqualMatcher(t *testing.T) {
|
||||
|
||||
func TestMoreThanMatcher(t *testing.T) {
|
||||
tests := []matchTest{
|
||||
matchTest{10, 1, true, true},
|
||||
matchTest{"10", "1", true, true},
|
||||
matchTest{8, 8, true, false},
|
||||
matchTest{"8", "8", true, false},
|
||||
matchTest{4, 9, true, false},
|
||||
matchTest{"4", "9", true, false},
|
||||
matchTest{"b", "a", true, true},
|
||||
matchTest{"a", "a", true, false},
|
||||
matchTest{"a", "b", true, false},
|
||||
matchTest{"", "", true, false},
|
||||
{10, 1, true, true},
|
||||
{"10", "1", true, true},
|
||||
{8, 8, true, false},
|
||||
{"8", "8", true, false},
|
||||
{4, 9, true, false},
|
||||
{"4", "9", true, false},
|
||||
{"b", "a", true, true},
|
||||
{"a", "a", true, false},
|
||||
{"a", "b", true, false},
|
||||
{"", "", true, false},
|
||||
}
|
||||
for _, mt := range tests {
|
||||
m := moreThanMatcher{}
|
||||
@@ -75,16 +75,16 @@ func TestMoreThanMatcher(t *testing.T) {
|
||||
|
||||
func TestLessThanMatcher(t *testing.T) {
|
||||
tests := []matchTest{
|
||||
matchTest{10, 1, true, false},
|
||||
matchTest{"10", "1", true, false},
|
||||
matchTest{8, 8, true, false},
|
||||
matchTest{"8", "8", true, false},
|
||||
matchTest{4, 9, true, true},
|
||||
matchTest{"4", "9", true, true},
|
||||
matchTest{"b", "a", true, false},
|
||||
matchTest{"a", "a", true, false},
|
||||
matchTest{"a", "b", true, true},
|
||||
matchTest{"", "", true, false},
|
||||
{10, 1, true, false},
|
||||
{"10", "1", true, false},
|
||||
{8, 8, true, false},
|
||||
{"8", "8", true, false},
|
||||
{4, 9, true, true},
|
||||
{"4", "9", true, true},
|
||||
{"b", "a", true, false},
|
||||
{"a", "a", true, false},
|
||||
{"a", "b", true, true},
|
||||
{"", "", true, false},
|
||||
}
|
||||
for _, mt := range tests {
|
||||
m := lessThanMatcher{}
|
||||
@@ -96,14 +96,14 @@ func TestLessThanMatcher(t *testing.T) {
|
||||
|
||||
func TestRegexpMatcher(t *testing.T) {
|
||||
tests := []matchTest{
|
||||
matchTest{"abcdef", "^abc", true, true},
|
||||
matchTest{"abc", "^abc", true, true},
|
||||
matchTest{"xxabcxx", "abc", true, true},
|
||||
matchTest{"123", "123", true, true},
|
||||
matchTest{"5", "^[0-9]+", true, true},
|
||||
matchTest{"xb", "abc", true, false},
|
||||
matchTest{"13", "12", true, false},
|
||||
matchTest{"xx", "^[-xxx****", false, false},
|
||||
{"abcdef", "^abc", true, true},
|
||||
{"abc", "^abc", true, true},
|
||||
{"xxabcxx", "abc", true, true},
|
||||
{"123", "123", true, true},
|
||||
{"5", "^[0-9]+", true, true},
|
||||
{"xb", "abc", true, false},
|
||||
{"13", "12", true, false},
|
||||
{"xx", "^[-xxx****", false, false},
|
||||
}
|
||||
for _, mt := range tests {
|
||||
m := regexpMatcher{}
|
||||
@@ -116,14 +116,14 @@ func TestRegexpMatcher(t *testing.T) {
|
||||
|
||||
func TestNegativeRegexpMatcher(t *testing.T) {
|
||||
tests := []matchTest{
|
||||
matchTest{"abcdef", "^abc", true, false},
|
||||
matchTest{"abc", "^abc", true, false},
|
||||
matchTest{"xxabcxx", "abc", true, false},
|
||||
matchTest{"123", "123", true, false},
|
||||
matchTest{"5", "^[0-9]+", true, false},
|
||||
matchTest{"xb", "abc", true, true},
|
||||
matchTest{"13", "12", true, true},
|
||||
matchTest{"xx", "^[-xxx****", false, true},
|
||||
{"abcdef", "^abc", true, false},
|
||||
{"abc", "^abc", true, false},
|
||||
{"xxabcxx", "abc", true, false},
|
||||
{"123", "123", true, false},
|
||||
{"5", "^[0-9]+", true, false},
|
||||
{"xb", "abc", true, true},
|
||||
{"13", "12", true, true},
|
||||
{"xx", "^[-xxx****", false, true},
|
||||
}
|
||||
for _, mt := range tests {
|
||||
m := negativeRegexMatcher{}
|
||||
|
||||
@@ -40,63 +40,63 @@ type filterConfig struct {
|
||||
// AllFilters contains the mapping of all filters along with operators they
|
||||
// support
|
||||
var AllFilters = []filterConfig{
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@alertmanager",
|
||||
LabelRe: regexp.MustCompile("^@alertmanager$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
|
||||
Factory: newAlertmanagerInstanceFilter,
|
||||
Autocomplete: alertmanagerInstanceAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@state",
|
||||
LabelRe: regexp.MustCompile("^@state$"),
|
||||
SupportedOperators: []string{equalOperator, notEqualOperator},
|
||||
Factory: newStateFilter,
|
||||
Autocomplete: stateAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@receiver",
|
||||
LabelRe: regexp.MustCompile("^@receiver$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
|
||||
Factory: newreceiverFilter,
|
||||
Autocomplete: receiverAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@age",
|
||||
LabelRe: regexp.MustCompile("^@age$"),
|
||||
SupportedOperators: []string{lessThanOperator, moreThanOperator},
|
||||
Factory: newAgeFilter,
|
||||
Autocomplete: ageAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@silence_id",
|
||||
LabelRe: regexp.MustCompile("^@silence_id$"),
|
||||
SupportedOperators: []string{equalOperator, notEqualOperator},
|
||||
Factory: newsilenceIDFilter,
|
||||
Autocomplete: silenceIDAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@silence_jira",
|
||||
LabelRe: regexp.MustCompile("^@silence_jira$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
|
||||
Factory: newSilenceJiraFilter,
|
||||
Autocomplete: silenceJiraIDAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@silence_author",
|
||||
LabelRe: regexp.MustCompile("^@silence_author$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
|
||||
Factory: newSilenceAuthorFilter,
|
||||
Autocomplete: silenceAuthorAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "@limit",
|
||||
LabelRe: regexp.MustCompile("^@limit$"),
|
||||
SupportedOperators: []string{equalOperator},
|
||||
Factory: newLimitFilter,
|
||||
Autocomplete: limitAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
{
|
||||
Label: "[a-zA-Z_][a-zA-Z0-9_]*",
|
||||
LabelRe: regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator, lessThanOperator, moreThanOperator},
|
||||
|
||||
@@ -15,20 +15,20 @@ type alertStateTest struct {
|
||||
}
|
||||
|
||||
var alertStateTests = []alertStateTest{
|
||||
alertStateTest{
|
||||
{
|
||||
alert: models.Alert{
|
||||
State: models.AlertStateActive,
|
||||
},
|
||||
isActive: true,
|
||||
},
|
||||
alertStateTest{
|
||||
{
|
||||
alert: models.Alert{
|
||||
State: models.AlertStateSuppressed,
|
||||
InhibitedBy: []string{"1234"},
|
||||
},
|
||||
isInhibited: true,
|
||||
},
|
||||
alertStateTest{
|
||||
{
|
||||
alert: models.Alert{
|
||||
State: models.AlertStateSuppressed,
|
||||
SilencedBy: []string{"1234"},
|
||||
@@ -95,7 +95,7 @@ func BenchmarkLabelsContent(b *testing.B) {
|
||||
State: models.AlertStateActive,
|
||||
StartsAt: time.Date(2015, time.March, 10, 0, 0, 0, 0, time.UTC),
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
},
|
||||
|
||||
@@ -14,31 +14,31 @@ type alertListSortTest struct {
|
||||
}
|
||||
|
||||
var alertListSortTests = []alertListSortTest{
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 5, time.UTC)},
|
||||
position: 0,
|
||||
},
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 1, time.UTC)},
|
||||
position: 1,
|
||||
},
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 0, time.UTC)},
|
||||
position: 2,
|
||||
},
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2015, time.March, 10, 0, 0, 0, 0, time.UTC)},
|
||||
position: 6,
|
||||
},
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2016, time.December, 10, 0, 0, 0, 0, time.UTC)},
|
||||
position: 4,
|
||||
},
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 0, time.UTC)},
|
||||
position: 3,
|
||||
},
|
||||
alertListSortTest{
|
||||
{
|
||||
alert: models.Alert{StartsAt: time.Date(2015, time.March, 10, 0, 0, 0, 0, time.UTC)},
|
||||
position: 5,
|
||||
},
|
||||
@@ -75,18 +75,18 @@ type agFPTest struct {
|
||||
}
|
||||
|
||||
var agFPTests = []agFPTest{
|
||||
agFPTest{
|
||||
{
|
||||
name: "empty group fingerprint",
|
||||
ag: models.AlertGroup{},
|
||||
},
|
||||
agFPTest{
|
||||
{
|
||||
name: "different Receiver shouldn't change content fingerprint",
|
||||
ag: models.AlertGroup{
|
||||
Receiver: "default",
|
||||
},
|
||||
fpChange: false,
|
||||
},
|
||||
agFPTest{
|
||||
{
|
||||
name: "different StateCount shouldn't change content fingerprint",
|
||||
ag: models.AlertGroup{
|
||||
Receiver: "default",
|
||||
@@ -94,7 +94,7 @@ var agFPTests = []agFPTest{
|
||||
},
|
||||
fpChange: false,
|
||||
},
|
||||
agFPTest{
|
||||
{
|
||||
name: "different Labels shouldn't change content fingerprint",
|
||||
ag: models.AlertGroup{
|
||||
Receiver: "default",
|
||||
@@ -103,7 +103,7 @@ var agFPTests = []agFPTest{
|
||||
},
|
||||
fpChange: false,
|
||||
},
|
||||
agFPTest{
|
||||
{
|
||||
name: "different set of alerts should change content fingerprint",
|
||||
ag: models.AlertGroup{
|
||||
Receiver: "default",
|
||||
@@ -118,7 +118,7 @@ var agFPTests = []agFPTest{
|
||||
},
|
||||
fpChange: true,
|
||||
},
|
||||
agFPTest{
|
||||
{
|
||||
name: "another different set of alerts should change content fingerprint",
|
||||
ag: models.AlertGroup{
|
||||
Receiver: "default",
|
||||
@@ -133,7 +133,7 @@ var agFPTests = []agFPTest{
|
||||
},
|
||||
fpChange: true,
|
||||
},
|
||||
agFPTest{
|
||||
{
|
||||
name: "repeating last set of alerts shouldn't change content fingerprint",
|
||||
ag: models.AlertGroup{
|
||||
Receiver: "default",
|
||||
@@ -193,7 +193,7 @@ type findLatestStartsAtTest struct {
|
||||
}
|
||||
|
||||
var findLatestStartsAtTests = []findLatestStartsAtTest{
|
||||
findLatestStartsAtTest{
|
||||
{
|
||||
alerts: []models.Alert{
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 5, time.UTC)},
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 1, time.UTC)},
|
||||
@@ -201,7 +201,7 @@ var findLatestStartsAtTests = []findLatestStartsAtTest{
|
||||
},
|
||||
expectedStartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 8, time.UTC),
|
||||
},
|
||||
findLatestStartsAtTest{
|
||||
{
|
||||
alerts: []models.Alert{
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 8, time.UTC)},
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 2, time.UTC)},
|
||||
@@ -209,7 +209,7 @@ var findLatestStartsAtTests = []findLatestStartsAtTest{
|
||||
},
|
||||
expectedStartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 8, time.UTC),
|
||||
},
|
||||
findLatestStartsAtTest{
|
||||
{
|
||||
alerts: []models.Alert{
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 1, time.UTC)},
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 1, time.UTC)},
|
||||
@@ -217,7 +217,7 @@ var findLatestStartsAtTests = []findLatestStartsAtTest{
|
||||
},
|
||||
expectedStartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 1, time.UTC),
|
||||
},
|
||||
findLatestStartsAtTest{
|
||||
{
|
||||
alerts: []models.Alert{
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 5, time.UTC)},
|
||||
{StartsAt: time.Date(2017, time.January, 10, 0, 0, 0, 8, time.UTC)},
|
||||
|
||||
@@ -13,42 +13,42 @@ type stringSliceTest struct {
|
||||
}
|
||||
|
||||
var stringSliceTests = []stringSliceTest{
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{},
|
||||
value: "aa",
|
||||
found: false,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "aa",
|
||||
found: true,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "bb",
|
||||
found: true,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "cc",
|
||||
found: true,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "dd",
|
||||
found: true,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "bbcc",
|
||||
found: false,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "b",
|
||||
found: false,
|
||||
},
|
||||
stringSliceTest{
|
||||
{
|
||||
array: []string{"aa", "bb", "cc", "dd"},
|
||||
value: "",
|
||||
found: false,
|
||||
@@ -71,32 +71,32 @@ type boolSliceTest struct {
|
||||
}
|
||||
|
||||
var boolSliceTests = []boolSliceTest{
|
||||
boolSliceTest{
|
||||
{
|
||||
array: []bool{},
|
||||
value: true,
|
||||
found: false,
|
||||
},
|
||||
boolSliceTest{
|
||||
{
|
||||
array: []bool{},
|
||||
value: false,
|
||||
found: false,
|
||||
},
|
||||
boolSliceTest{
|
||||
{
|
||||
array: []bool{true, false},
|
||||
value: true,
|
||||
found: true,
|
||||
},
|
||||
boolSliceTest{
|
||||
{
|
||||
array: []bool{true, false},
|
||||
value: false,
|
||||
found: true,
|
||||
},
|
||||
boolSliceTest{
|
||||
{
|
||||
array: []bool{false},
|
||||
value: true,
|
||||
found: false,
|
||||
},
|
||||
boolSliceTest{
|
||||
{
|
||||
array: []bool{true},
|
||||
value: false,
|
||||
found: false,
|
||||
|
||||
@@ -59,7 +59,7 @@ var colorTests = []colorTest{
|
||||
{
|
||||
customLabels: config.CustomLabelColors{
|
||||
"node": []config.CustomLabelColor{
|
||||
config.CustomLabelColor{Value: "localhost", Color: "#fff"},
|
||||
{Value: "localhost", Color: "#fff"},
|
||||
},
|
||||
},
|
||||
labels: map[string]string{
|
||||
@@ -72,7 +72,7 @@ var colorTests = []colorTest{
|
||||
{
|
||||
customLabels: config.CustomLabelColors{
|
||||
"node": []config.CustomLabelColor{
|
||||
config.CustomLabelColor{Value: "localhost", Color: "not a valid color"},
|
||||
{Value: "localhost", Color: "not a valid color"},
|
||||
},
|
||||
},
|
||||
labels: map[string]string{
|
||||
@@ -83,7 +83,7 @@ var colorTests = []colorTest{
|
||||
{
|
||||
customLabels: config.CustomLabelColors{
|
||||
"node": []config.CustomLabelColor{
|
||||
config.CustomLabelColor{ValueRegex: ".*", Color: "#123"},
|
||||
{ValueRegex: ".*", Color: "#123"},
|
||||
},
|
||||
},
|
||||
labels: map[string]string{
|
||||
@@ -94,7 +94,7 @@ var colorTests = []colorTest{
|
||||
{
|
||||
customLabels: config.CustomLabelColors{
|
||||
"node": []config.CustomLabelColor{
|
||||
config.CustomLabelColor{Value: "foo", ValueRegex: ".*", Color: "#123"},
|
||||
{Value: "foo", ValueRegex: ".*", Color: "#123"},
|
||||
},
|
||||
},
|
||||
labels: map[string]string{
|
||||
|
||||
@@ -14,64 +14,64 @@ type jiraTest struct {
|
||||
}
|
||||
|
||||
var jiraRules = []models.JiraRule{
|
||||
models.JiraRule{
|
||||
{
|
||||
Regex: "DEVOPS-[0-9]+",
|
||||
URI: "https://jira.example.com",
|
||||
},
|
||||
models.JiraRule{
|
||||
{
|
||||
Regex: "PROJECT-[0-9]+",
|
||||
URI: "https://example.com",
|
||||
},
|
||||
}
|
||||
|
||||
var jiraTests = []jiraTest{
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "Lorem ipsum dolor sit amet",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "DVOPS-123",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "DEVOPS team",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "a project-1 b",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "a PROJECT- b",
|
||||
},
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "DEVOPS-1",
|
||||
},
|
||||
jiraID: "DEVOPS-1",
|
||||
jiraLink: "https://jira.example.com/browse/DEVOPS-1",
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "DEVOPS-123",
|
||||
},
|
||||
jiraID: "DEVOPS-123",
|
||||
jiraLink: "https://jira.example.com/browse/DEVOPS-123",
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "a DEVOPS-1 b",
|
||||
},
|
||||
jiraID: "DEVOPS-1",
|
||||
jiraLink: "https://jira.example.com/browse/DEVOPS-1",
|
||||
},
|
||||
jiraTest{
|
||||
{
|
||||
silence: models.Silence{
|
||||
Comment: "PROJECT-9",
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ type stripLabelTest struct {
|
||||
}
|
||||
|
||||
var stripLabelTests = []stripLabelTest{
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{"env"},
|
||||
keep: []string{},
|
||||
before: map[string]string{
|
||||
@@ -29,7 +29,7 @@ var stripLabelTests = []stripLabelTest{
|
||||
"level": "info",
|
||||
},
|
||||
},
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{"server"},
|
||||
keep: []string{},
|
||||
before: map[string]string{
|
||||
@@ -43,7 +43,7 @@ var stripLabelTests = []stripLabelTest{
|
||||
"level": "info",
|
||||
},
|
||||
},
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{},
|
||||
keep: []string{},
|
||||
before: map[string]string{
|
||||
@@ -57,7 +57,7 @@ var stripLabelTests = []stripLabelTest{
|
||||
"level": "info",
|
||||
},
|
||||
},
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{"host"},
|
||||
keep: []string{},
|
||||
before: map[string]string{
|
||||
@@ -65,7 +65,7 @@ var stripLabelTests = []stripLabelTest{
|
||||
},
|
||||
after: map[string]string{},
|
||||
},
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{},
|
||||
keep: []string{"env"},
|
||||
before: map[string]string{
|
||||
@@ -77,7 +77,7 @@ var stripLabelTests = []stripLabelTest{
|
||||
"env": "production",
|
||||
},
|
||||
},
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{"env"},
|
||||
keep: []string{"host"},
|
||||
before: map[string]string{
|
||||
@@ -89,7 +89,7 @@ var stripLabelTests = []stripLabelTest{
|
||||
"host": "localhost",
|
||||
},
|
||||
},
|
||||
stripLabelTest{
|
||||
{
|
||||
strip: []string{},
|
||||
keep: []string{"env"},
|
||||
before: map[string]string{
|
||||
@@ -117,37 +117,37 @@ type stripReceiverTest struct {
|
||||
}
|
||||
|
||||
var stripReceiverTests = []stripReceiverTest{
|
||||
stripReceiverTest{
|
||||
{
|
||||
strip: []string{},
|
||||
keep: []string{},
|
||||
receiver: "default",
|
||||
stripped: false,
|
||||
},
|
||||
stripReceiverTest{
|
||||
{
|
||||
strip: []string{"default"},
|
||||
keep: []string{},
|
||||
receiver: "default",
|
||||
stripped: true,
|
||||
},
|
||||
stripReceiverTest{
|
||||
{
|
||||
strip: []string{"default"},
|
||||
keep: []string{"default"},
|
||||
receiver: "default",
|
||||
stripped: true,
|
||||
},
|
||||
stripReceiverTest{
|
||||
{
|
||||
strip: []string{},
|
||||
keep: []string{"default"},
|
||||
receiver: "default",
|
||||
stripped: false,
|
||||
},
|
||||
stripReceiverTest{
|
||||
{
|
||||
strip: []string{"foo", "bar"},
|
||||
keep: []string{},
|
||||
receiver: "default",
|
||||
stripped: false,
|
||||
},
|
||||
stripReceiverTest{
|
||||
{
|
||||
strip: []string{"foo", "default"},
|
||||
keep: []string{"foo", "bar"},
|
||||
receiver: "default",
|
||||
|
||||
@@ -65,20 +65,20 @@ type fileTransportTest struct {
|
||||
}
|
||||
|
||||
var fileTransportTests = []fileTransportTest{
|
||||
fileTransportTest{
|
||||
{
|
||||
uri: fmt.Sprintf("file://%s", mock.GetAbsoluteMockPath("api/v1/status", mock.ListAllMocks()[0])),
|
||||
size: getFileSize(mock.GetAbsoluteMockPath("api/v1/status", mock.ListAllMocks()[0])),
|
||||
},
|
||||
fileTransportTest{
|
||||
{
|
||||
uri: "file:///non-existing-file.abcdef",
|
||||
failed: true,
|
||||
},
|
||||
fileTransportTest{
|
||||
{
|
||||
uri: "file://uri.go",
|
||||
size: getFileSize("uri.go"),
|
||||
failed: true,
|
||||
},
|
||||
fileTransportTest{
|
||||
{
|
||||
uri: "file://../uri/uri.go",
|
||||
size: getFileSize("uri.go"),
|
||||
failed: true,
|
||||
|
||||
@@ -13,17 +13,17 @@ type joinURLTest struct {
|
||||
}
|
||||
|
||||
var joinURLTests = []joinURLTest{
|
||||
joinURLTest{
|
||||
{
|
||||
base: "http://localhost",
|
||||
sub: "/sub",
|
||||
url: "http://localhost/sub",
|
||||
},
|
||||
joinURLTest{
|
||||
{
|
||||
base: "http://localhost",
|
||||
sub: "/sub/",
|
||||
url: "http://localhost/sub",
|
||||
},
|
||||
joinURLTest{
|
||||
{
|
||||
base: "http://am.example.com",
|
||||
sub: "/api/v1/alerts",
|
||||
url: "http://am.example.com/api/v1/alerts",
|
||||
|
||||
@@ -195,7 +195,7 @@ type acTestCase struct {
|
||||
}
|
||||
|
||||
var acTests = []acTestCase{
|
||||
acTestCase{
|
||||
{
|
||||
Term: "ale",
|
||||
Results: []string{
|
||||
"alertname=Memory_Usage_Too_High",
|
||||
@@ -210,7 +210,7 @@ var acTests = []acTestCase{
|
||||
"@alertmanager!=default",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "alert",
|
||||
Results: []string{
|
||||
"alertname=Memory_Usage_Too_High",
|
||||
@@ -225,7 +225,7 @@ var acTests = []acTestCase{
|
||||
"@alertmanager!=default",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "alertname",
|
||||
Results: []string{
|
||||
"alertname=Memory_Usage_Too_High",
|
||||
@@ -238,7 +238,7 @@ var acTests = []acTestCase{
|
||||
"alertname!=Free_Disk_Space_Too_Low",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "aLeRtNaMe",
|
||||
Results: []string{
|
||||
"alertname=Memory_Usage_Too_High",
|
||||
@@ -251,21 +251,21 @@ var acTests = []acTestCase{
|
||||
"alertname!=Free_Disk_Space_Too_Low",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "http",
|
||||
Results: []string{
|
||||
"alertname=HTTP_Probe_Failed",
|
||||
"alertname!=HTTP_Probe_Failed",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "hTTp_",
|
||||
Results: []string{
|
||||
"alertname=HTTP_Probe_Failed",
|
||||
"alertname!=HTTP_Probe_Failed",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "@st",
|
||||
Results: []string{
|
||||
"@state=suppressed",
|
||||
@@ -274,7 +274,7 @@ var acTests = []acTestCase{
|
||||
"@state!=active",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "@r",
|
||||
Results: []string{
|
||||
"@receiver=by-name",
|
||||
@@ -283,7 +283,7 @@ var acTests = []acTestCase{
|
||||
"@receiver!=by-cluster-service",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "@age",
|
||||
Results: []string{
|
||||
"@age>1h",
|
||||
@@ -292,21 +292,21 @@ var acTests = []acTestCase{
|
||||
"@age<10m",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "@limit",
|
||||
Results: []string{
|
||||
"@limit=50",
|
||||
"@limit=10",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "@alertmanager",
|
||||
Results: []string{
|
||||
"@alertmanager=default",
|
||||
"@alertmanager!=default",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "nod",
|
||||
Results: []string{
|
||||
"job=node_ping",
|
||||
@@ -315,7 +315,7 @@ var acTests = []acTestCase{
|
||||
"job!=node_exporter",
|
||||
},
|
||||
},
|
||||
acTestCase{
|
||||
{
|
||||
Term: "Nod",
|
||||
Results: []string{
|
||||
"job=node_ping",
|
||||
@@ -325,7 +325,7 @@ var acTests = []acTestCase{
|
||||
},
|
||||
},
|
||||
// duplicated to test reponse caching
|
||||
acTestCase{
|
||||
{
|
||||
Term: "Nod",
|
||||
Results: []string{
|
||||
"job=node_ping",
|
||||
@@ -385,23 +385,23 @@ type staticFileTestCase struct {
|
||||
}
|
||||
|
||||
var staticFileTests = []staticFileTestCase{
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/favicon.ico",
|
||||
code: 200,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/manifest.json",
|
||||
code: 200,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/index.xml",
|
||||
code: 404,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/xxx",
|
||||
code: 404,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/static/abcd",
|
||||
code: 404,
|
||||
},
|
||||
@@ -421,23 +421,23 @@ func TestStaticFiles(t *testing.T) {
|
||||
}
|
||||
|
||||
var staticFilePrefixTests = []staticFileTestCase{
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/sub/favicon.ico",
|
||||
code: 200,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/sub/manifest.json",
|
||||
code: 200,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/sub/index.xml",
|
||||
code: 404,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/sub/xxx",
|
||||
code: 404,
|
||||
},
|
||||
staticFileTestCase{
|
||||
{
|
||||
path: "/sub/static/abcd",
|
||||
code: 404,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user