Bläddra i källkod

datasource as cfg: test for reading all properties

bergquist 8 år sedan
förälder
incheckning
dc002abe4c

+ 32 - 32
conf/datasources.yaml

@@ -6,36 +6,36 @@ purge_other_datasources: false
 # list of datasources to insert/update depending 
 # whats available in the datbase
 datasources:
-    # <string, required> name of the datasource. Required
-  - name: Graphite
-    # <string, required> datasource type. Required
-    type: graphite
-    # <string, required> access mode. direct or proxy. Required
-    access: proxy
-    # <string, required> url
-    url: http://localhost:8080
-    # <string> database password, if used
-    password:
-    # <string> database user, if used
-    user:
-    # <string> database name, if used
-    database:
-    # <bool> enable/disable basic auth
-    basic_auth:
-    # <string> basic auth username
-    basic_authUser:
-    # <string> basic auth password
-    basic_auth_password:
-    # <bool> enable/disable with credentials headers
-    with_credentials:
-    # <bool> mark as default datasource. Max one per org
-    is_default:
-    # <string> json data
-    json_data: '{"graphiteVersion":"0.9"}'
-    # <string> json object of data that will be encrypted in UI.
-    secure_json_fields: ''
-  - name: Prometheus
-    type: prometheus
-    access: proxy
-    url: http://localhost:9090
+#     # <string, required> name of the datasource. Required
+#   - name: Graphite
+#     # <string, required> datasource type. Required
+#     type: graphite
+#     # <string, required> access mode. direct or proxy. Required
+#     access: proxy
+#     # <string, required> url
+#     url: http://localhost:8080
+#     # <string> database password, if used
+#     password:
+#     # <string> database user, if used
+#     user:
+#     # <string> database name, if used
+#     database:
+#     # <bool> enable/disable basic auth
+#     basic_auth:
+#     # <string> basic auth username
+#     basic_auth_user:
+#     # <string> basic auth password
+#     basic_auth_password:
+#     # <bool> enable/disable with credentials headers
+#     with_credentials:
+#     # <bool> mark as default datasource. Max one per org
+#     is_default:
+#     # <string> json data
+#     json_data: '{"graphiteVersion":"0.9"}'
+#     # <string> json object of data that will be encrypted in UI.
+#     secure_json_fields: ''
+#   - name: Prometheus
+#     type: prometheus
+#     access: proxy
+#     url: http://localhost:9090
 

+ 27 - 0
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)
+		})
 	})
 }
 

+ 17 - 0
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: ''