Pārlūkot izejas kodu

feat(apps): fixed unit tests

Torkel Ödegaard 9 gadi atpakaļ
vecāks
revīzija
615b692442

+ 0 - 30
pkg/plugins/dashboards.go

@@ -105,33 +105,3 @@ func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) {
 
 
 	return m.NewDashboardFromJson(data), nil
 	return m.NewDashboardFromJson(data), nil
 }
 }
-
-func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*PluginDashboardInfoDTO, error) {
-	res := &PluginDashboardInfoDTO{}
-
-	var dashboard *m.Dashboard
-	var err error
-
-	if dashboard, err = loadPluginDashboard(plugin.Id, path); err != nil {
-		return nil, err
-	}
-
-	res.Path = path
-	res.PluginId = plugin.Id
-	res.Title = dashboard.Title
-	res.Revision = dashboard.Data.Get("revision").MustInt64(1)
-
-	query := m.GetDashboardQuery{OrgId: orgId, Slug: dashboard.Slug}
-
-	if err := bus.Dispatch(&query); err != nil {
-		if err != m.ErrDashboardNotFound {
-			return nil, err
-		}
-	} else {
-		res.Imported = true
-		res.ImportedUri = "db/" + query.Result.Slug
-		res.ImportedRevision = query.Result.Data.Get("revision").MustInt64(1)
-	}
-
-	return res, nil
-}

+ 20 - 5
pkg/plugins/dashboards_test.go

@@ -4,6 +4,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
+	"github.com/grafana/grafana/pkg/components/simplejson"
 	m "github.com/grafana/grafana/pkg/models"
 	m "github.com/grafana/grafana/pkg/models"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 	. "github.com/smartystreets/goconvey/convey"
 	. "github.com/smartystreets/goconvey/convey"
@@ -31,6 +32,20 @@ func TestPluginDashboards(t *testing.T) {
 			return m.ErrDashboardNotFound
 			return m.ErrDashboardNotFound
 		})
 		})
 
 
+		bus.AddHandler("test", func(query *m.GetDashboardsByPluginIdQuery) error {
+			var data = simplejson.New()
+			data.Set("title", "Nginx Connections")
+			data.Set("revision", 22)
+
+			query.Result = []*m.Dashboard{
+				&m.Dashboard{
+					Slug: "nginx-connections",
+					Data: data,
+				},
+			}
+			return nil
+		})
+
 		dashboards, err := GetPluginDashboards(1, "test-app")
 		dashboards, err := GetPluginDashboards(1, "test-app")
 
 
 		So(err, ShouldBeNil)
 		So(err, ShouldBeNil)
@@ -41,12 +56,12 @@ func TestPluginDashboards(t *testing.T) {
 
 
 		Convey("should include installed version info", func() {
 		Convey("should include installed version info", func() {
 			So(dashboards[0].Title, ShouldEqual, "Nginx Connections")
 			So(dashboards[0].Title, ShouldEqual, "Nginx Connections")
-			//So(dashboards[0].Revision, ShouldEqual, "1.5")
-			//So(dashboards[0].InstalledRevision, ShouldEqual, "1.1")
-			//So(dashboards[0].InstalledUri, ShouldEqual, "db/nginx-connections")
+			So(dashboards[0].Revision, ShouldEqual, 25)
+			So(dashboards[0].ImportedRevision, ShouldEqual, 22)
+			So(dashboards[0].ImportedUri, ShouldEqual, "db/nginx-connections")
 
 
-			//So(dashboards[1].Revision, ShouldEqual, "2.0")
-			//So(dashboards[1].InstalledRevision, ShouldEqual, "")
+			So(dashboards[1].Revision, ShouldEqual, 2)
+			So(dashboards[1].ImportedRevision, ShouldEqual, 0)
 		})
 		})
 	})
 	})
 
 

+ 1 - 1
tests/test-app/dashboards/connections.json

@@ -8,7 +8,7 @@
   ],
   ],
 
 
   "title": "Nginx Connections",
   "title": "Nginx Connections",
-  "revision": "1.5",
+  "revision": 25,
   "schemaVersion": 11,
   "schemaVersion": 11,
   "tags": ["tag1", "tag2"],
   "tags": ["tag1", "tag2"],
   "number_array": [1,2,3,10.33],
   "number_array": [1,2,3,10.33],

+ 1 - 1
tests/test-app/dashboards/connections_result.json

@@ -1,5 +1,5 @@
 {
 {
-  "revision": "1.5",
+  "revision": 25,
   "tags": ["tag1", "tag2"],
   "tags": ["tag1", "tag2"],
   "boolean_false": false,
   "boolean_false": false,
   "boolean_true": true,
   "boolean_true": true,

+ 1 - 1
tests/test-app/dashboards/memory.json

@@ -1,5 +1,5 @@
 {
 {
   "title": "Nginx Memory",
   "title": "Nginx Memory",
-  "revision": "2.0",
+  "revision": 2,
   "schemaVersion": 11
   "schemaVersion": 11
 }
 }