Provisioning: Add validation for missing organisations in datasource, dashboard, and notifier configurations (#26601)

* Provisioning: Check that org. from config exists

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

* Apply suggestions from code review

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

* Fix some code after applying suggestions

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

* Add negative test case

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Maksim Nabokikh
2020-07-30 13:59:12 +04:00
committed by GitHub
parent 3f21283655
commit ba2524cd88
8 changed files with 119 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package notifiers
import (
"fmt"
"os"
"testing"
@@ -31,6 +32,12 @@ func TestNotificationAsConfig(t *testing.T) {
Convey("Testing notification as configuration", t, func() {
sqlstore.InitTestDB(t)
for i := 1; i < 5; i++ {
orgCommand := models.CreateOrgCommand{Name: fmt.Sprintf("Main Org. %v", i)}
err := sqlstore.CreateOrg(&orgCommand)
So(err, ShouldBeNil)
}
alerting.RegisterNotifier(&alerting.NotifierPlugin{
Type: "slack",
Name: "slack",
@@ -227,12 +234,12 @@ func TestNotificationAsConfig(t *testing.T) {
})
Convey("Can read correct properties with orgName instead of orgId", func() {
existingOrg1 := models.CreateOrgCommand{Name: "Main Org. 1"}
err := sqlstore.CreateOrg(&existingOrg1)
existingOrg1 := models.GetOrgByNameQuery{Name: "Main Org. 1"}
err := sqlstore.GetOrgByName(&existingOrg1)
So(err, ShouldBeNil)
So(existingOrg1.Result, ShouldNotBeNil)
existingOrg2 := models.CreateOrgCommand{Name: "Main Org. 2"}
err = sqlstore.CreateOrg(&existingOrg2)
existingOrg2 := models.GetOrgByNameQuery{Name: "Main Org. 2"}
err = sqlstore.GetOrgByName(&existingOrg2)
So(err, ShouldBeNil)
So(existingOrg2.Result, ShouldNotBeNil)