fix(tests): more config test coverage

This commit is contained in:
Łukasz Mierzwa
2020-02-06 12:04:19 +00:00
parent 3b3ce88812
commit c002a5d14c
5 changed files with 49 additions and 7 deletions

View File

@@ -19,7 +19,7 @@ func mainShoulFail() int {
if err != nil {
log.Error(err)
} else if wasFatal {
return 100
return 0
} else {
log.Error("No error logged")
return 100

View File

@@ -0,0 +1,16 @@
# Raises an error if label custom color config is using invalid regex rule
karma.bin-should-fail --log.format=text --log.config=false --log.level=error --config.file=karma.yaml
! stdout .
stderr 'msg="Failed to parse custom color regex rule ''\.\+\+\+\+'' for ''region'' label: error parsing regexp: invalid nested repetition operator: `\+\+`"'
-- karma.yaml --
alertmanager:
servers:
- name: default
uri: https://localhost:9093
labels:
color:
custom:
region:
- value_re: ".++++"
color: "#736598"

View File

@@ -0,0 +1,15 @@
# Raises an error if label custom color config is missing a value
karma.bin-should-fail --log.format=text --log.config=false --log.level=error --config.file=karma.yaml
! stdout .
stderr 'msg="Custom label color for ''region'' is missing ''value'' or ''value_re''"'
-- karma.yaml --
alertmanager:
servers:
- name: default
uri: https://localhost:9093
labels:
color:
custom:
region:
- color: "#736598"

View File

@@ -17,7 +17,6 @@ alertmanager:
readonly: true
- name: local
uri: http://localhost:9095
timeout: 10s
proxy: true
readonly: false
headers:
@@ -62,9 +61,9 @@ grid:
customValues:
labels:
cluster:
prod: 1
Prod: 1
staging: 2
dev: 3
DEV: 3
severity:
critical: 1
warning: 2
@@ -258,7 +257,7 @@ level=info msg=" headers: {}"
level=info msg=" - name: local"
level=info msg=" uri: http://localhost:9095"
level=info msg=" external_uri: \"\""
level=info msg=" timeout: 10s"
level=info msg=" timeout: 40s"
level=info msg=" proxy: true"
level=info msg=" readonly: false"
level=info msg=" tls:"
@@ -314,8 +313,8 @@ level=info msg=" label: severity"
level=info msg=" customValues:"
level=info msg=" labels:"
level=info msg=" cluster:"
level=info msg=" dev: \"3\""
level=info msg=" prod: \"1\""
level=info msg=" DEV: \"3\""
level=info msg=" Prod: \"1\""
level=info msg=" staging: \"2\""
level=info msg=" severity:"
level=info msg=" critical: \"1\""

View File

@@ -760,3 +760,15 @@ func TestSilences(t *testing.T) {
}
}
}
func TestCORS(t *testing.T) {
mockConfig()
r := ginTestEngine()
req := httptest.NewRequest("OPTIONS", "/alerts.json", nil)
req.Header.Set("Origin", "foo.example.com")
resp := httptest.NewRecorder()
r.ServeHTTP(resp, req)
if resp.Header().Get("Access-Control-Allow-Origin") != "foo.example.com" {
t.Errorf("Invalid Access-Control-Allow-Origin value %q, expected 'foo.example.com'", resp.Header().Get("Access-Control-Allow-Origin"))
}
}