From dc002abe4caa6747d4ae0966af477cec727833e5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 24 Oct 2017 10:15:06 +0200 Subject: [PATCH] datasource as cfg: test for reading all properties --- conf/datasources.yaml | 64 +++++++++---------- .../datasources/datasources_test.go | 27 ++++++++ .../test-configs/all-properties.yaml | 17 +++++ 3 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 pkg/services/provisioning/datasources/test-configs/all-properties.yaml diff --git a/conf/datasources.yaml b/conf/datasources.yaml index 53fc9a70a50..f38f009437c 100644 --- a/conf/datasources.yaml +++ b/conf/datasources.yaml @@ -6,36 +6,36 @@ purge_other_datasources: false # list of datasources to insert/update depending # whats available in the datbase datasources: - # name of the datasource. Required - - name: Graphite - # datasource type. Required - type: graphite - # access mode. direct or proxy. Required - access: proxy - # url - url: http://localhost:8080 - # database password, if used - password: - # database user, if used - user: - # database name, if used - database: - # enable/disable basic auth - basic_auth: - # basic auth username - basic_authUser: - # basic auth password - basic_auth_password: - # enable/disable with credentials headers - with_credentials: - # mark as default datasource. Max one per org - is_default: - # json data - json_data: '{"graphiteVersion":"0.9"}' - # json object of data that will be encrypted in UI. - secure_json_fields: '' - - name: Prometheus - type: prometheus - access: proxy - url: http://localhost:9090 +# # name of the datasource. Required +# - name: Graphite +# # datasource type. Required +# type: graphite +# # access mode. direct or proxy. Required +# access: proxy +# # url +# url: http://localhost:8080 +# # database password, if used +# password: +# # database user, if used +# user: +# # database name, if used +# database: +# # enable/disable basic auth +# basic_auth: +# # basic auth username +# basic_auth_user: +# # basic auth password +# basic_auth_password: +# # enable/disable with credentials headers +# with_credentials: +# # mark as default datasource. Max one per org +# is_default: +# # json data +# json_data: '{"graphiteVersion":"0.9"}' +# # json object of data that will be encrypted in UI. +# secure_json_fields: '' +# - name: Prometheus +# type: prometheus +# access: proxy +# url: http://localhost:9090 diff --git a/pkg/services/provisioning/datasources/datasources_test.go b/pkg/services/provisioning/datasources/datasources_test.go index b39b20e6558..796f0308af9 100644 --- a/pkg/services/provisioning/datasources/datasources_test.go +++ b/pkg/services/provisioning/datasources/datasources_test.go @@ -15,6 +15,7 @@ var ( twoDatasourcesConfig string = "./test-configs/two-datasources.yaml" twoDatasourcesConfigPurgeOthers string = "./test-configs/two-datasources-purge-others.yaml" doubleDatasourcesConfig string = "./test-configs/double-default-datasources.yaml" + allProperties string = "./test-configs/all-properties.yaml" ) func TestDatasourceAsConfig(t *testing.T) { @@ -102,6 +103,32 @@ func TestDatasourceAsConfig(t *testing.T) { }) }) }) + + Convey("can read all properties", func() { + + cfgProvifer := configProvider{} + cfg, err := cfgProvifer.readConfig(allProperties) + if err != nil { + t.Fatalf("readConfig return an error %v", err) + } + + So(cfg.PurgeOtherDatasources, ShouldBeTrue) + ds := cfg.Datasources[0] + + So(ds.Name, ShouldEqual, "name") + So(ds.Type, ShouldEqual, "type") + So(ds.Access, ShouldEqual, models.DS_ACCESS_PROXY) + So(ds.OrgId, ShouldEqual, 2) + So(ds.Url, ShouldEqual, "url") + So(ds.User, ShouldEqual, "user") + So(ds.Password, ShouldEqual, "password") + So(ds.Database, ShouldEqual, "database") + So(ds.BasicAuth, ShouldBeTrue) + So(ds.BasicAuthUser, ShouldEqual, "basic_auth_user") + So(ds.BasicAuthPassword, ShouldEqual, "basic_auth_password") + So(ds.WithCredentials, ShouldBeTrue) + So(ds.IsDefault, ShouldBeTrue) + }) }) } diff --git a/pkg/services/provisioning/datasources/test-configs/all-properties.yaml b/pkg/services/provisioning/datasources/test-configs/all-properties.yaml new file mode 100644 index 00000000000..e818f22c4d8 --- /dev/null +++ b/pkg/services/provisioning/datasources/test-configs/all-properties.yaml @@ -0,0 +1,17 @@ +purge_other_datasources: true +datasources: + - name: name + type: type + access: proxy + org_id: 2 + url: url + password: password + user: user + database: database + basic_auth: true + basic_auth_user: basic_auth_user + basic_auth_password: basic_auth_password + with_credentials: true + is_default: true + json_data: '{"graphiteVersion":"0.9"}' + secure_json_fields: ''