Commit c296ae11 by Torkel Ödegaard

refactoring: fixing unit tests broken in last commit

parent e1800715
...@@ -32,12 +32,12 @@ func init() { ...@@ -32,12 +32,12 @@ func init() {
// CompareDashboardVersionsCommand computes the JSON diff of two versions, // CompareDashboardVersionsCommand computes the JSON diff of two versions,
// assigning the delta of the diff to the `Delta` field. // assigning the delta of the diff to the `Delta` field.
func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) error { func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) error {
original, err := getDashboardVersion(cmd.DashboardId, cmd.Original, cmd.OrgId) original, err := getDashboardVersion(cmd.DashboardId, cmd.Original)
if err != nil { if err != nil {
return err return err
} }
newDashboard, err := getDashboardVersion(cmd.DashboardId, cmd.New, cmd.OrgId) newDashboard, err := getDashboardVersion(cmd.DashboardId, cmd.New)
if err != nil { if err != nil {
return err return err
} }
...@@ -80,7 +80,7 @@ func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) err ...@@ -80,7 +80,7 @@ func CompareDashboardVersionsCommand(cmd *m.CompareDashboardVersionsCommand) err
// GetDashboardVersion gets the dashboard version for the given dashboard ID // GetDashboardVersion gets the dashboard version for the given dashboard ID
// and version number. // and version number.
func GetDashboardVersion(query *m.GetDashboardVersionQuery) error { func GetDashboardVersion(query *m.GetDashboardVersionQuery) error {
result, err := getDashboardVersion(query.DashboardId, query.Version, query.OrgId) result, err := getDashboardVersion(query.DashboardId, query.Version)
if err != nil { if err != nil {
return err return err
} }
...@@ -128,7 +128,7 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error { ...@@ -128,7 +128,7 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error {
// session instead of using the global `x`, so we copy those functions // session instead of using the global `x`, so we copy those functions
// here, replacing `x` with `sess` // here, replacing `x` with `sess`
dashboardVersion := m.DashboardVersion{} dashboardVersion := m.DashboardVersion{}
has, err := sess.Where("dashboard_id=? AND version=? AND org_id=?", cmd.DashboardId, cmd.Version, cmd.OrgId).Get(&dashboardVersion) has, err := sess.Where("dashboard_id=? AND version=?", cmd.DashboardId, cmd.Version).Get(&dashboardVersion)
if err != nil { if err != nil {
return err return err
} }
...@@ -190,9 +190,9 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error { ...@@ -190,9 +190,9 @@ func RestoreDashboardVersion(cmd *m.RestoreDashboardVersionCommand) error {
// getDashboardVersion is a helper function that gets the dashboard version for // getDashboardVersion is a helper function that gets the dashboard version for
// the given dashboard ID and version ID. // the given dashboard ID and version ID.
func getDashboardVersion(dashboardId int64, version int, orgId int64) (*m.DashboardVersion, error) { func getDashboardVersion(dashboardId int64, version int) (*m.DashboardVersion, error) {
dashboardVersion := m.DashboardVersion{} dashboardVersion := m.DashboardVersion{}
has, err := x.Where("dashboard_id=? AND version=? AND org_id=?", dashboardId, version, orgId).Get(&dashboardVersion) has, err := x.Where("dashboard_id=? AND version=?", dashboardId, version).Get(&dashboardVersion)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -30,15 +30,15 @@ func TestGetDashboardVersion(t *testing.T) { ...@@ -30,15 +30,15 @@ func TestGetDashboardVersion(t *testing.T) {
Convey("Get a Dashboard ID and version ID", func() { Convey("Get a Dashboard ID and version ID", func() {
savedDash := insertTestDashboard("test dash 26", 1, "diff") savedDash := insertTestDashboard("test dash 26", 1, "diff")
cmd := m.GetDashboardVersionCommand{ query := m.GetDashboardVersionQuery{
DashboardId: savedDash.Id, DashboardId: savedDash.Id,
Version: savedDash.Version, Version: savedDash.Version,
} }
err := GetDashboardVersion(&cmd) err := GetDashboardVersion(&query)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(savedDash.Id, ShouldEqual, cmd.DashboardId) So(savedDash.Id, ShouldEqual, query.DashboardId)
So(savedDash.Version, ShouldEqual, cmd.Version) So(savedDash.Version, ShouldEqual, query.Version)
dashCmd := m.GetDashboardQuery{ dashCmd := m.GetDashboardQuery{
OrgId: savedDash.OrgId, OrgId: savedDash.OrgId,
...@@ -46,17 +46,17 @@ func TestGetDashboardVersion(t *testing.T) { ...@@ -46,17 +46,17 @@ func TestGetDashboardVersion(t *testing.T) {
} }
err = GetDashboard(&dashCmd) err = GetDashboard(&dashCmd)
So(err, ShouldBeNil) So(err, ShouldBeNil)
eq := reflect.DeepEqual(dashCmd.Result.Data, cmd.Result.Data) eq := reflect.DeepEqual(dashCmd.Result.Data, query.Result.Data)
So(eq, ShouldEqual, true) So(eq, ShouldEqual, true)
}) })
Convey("Attempt to get a version that doesn't exist", func() { Convey("Attempt to get a version that doesn't exist", func() {
cmd := m.GetDashboardVersionCommand{ query := m.GetDashboardVersionQuery{
DashboardId: int64(999), DashboardId: int64(999),
Version: 123, Version: 123,
} }
err := GetDashboardVersion(&cmd) err := GetDashboardVersion(&query)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
So(err, ShouldEqual, m.ErrDashboardVersionNotFound) So(err, ShouldEqual, m.ErrDashboardVersionNotFound)
}) })
...@@ -69,24 +69,20 @@ func TestGetDashboardVersions(t *testing.T) { ...@@ -69,24 +69,20 @@ func TestGetDashboardVersions(t *testing.T) {
savedDash := insertTestDashboard("test dash 43", 1, "diff-all") savedDash := insertTestDashboard("test dash 43", 1, "diff-all")
Convey("Get all versions for a given Dashboard ID", func() { Convey("Get all versions for a given Dashboard ID", func() {
cmd := m.GetDashboardVersionsCommand{ query := m.GetDashboardVersionsQuery{DashboardId: savedDash.Id, OrgId: 1}
DashboardId: savedDash.Id,
}
err := GetDashboardVersions(&cmd) err := GetDashboardVersions(&query)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(cmd.Result), ShouldEqual, 1) So(len(query.Result), ShouldEqual, 1)
}) })
Convey("Attempt to get the versions for a non-existent Dashboard ID", func() { Convey("Attempt to get the versions for a non-existent Dashboard ID", func() {
cmd := m.GetDashboardVersionsCommand{ query := m.GetDashboardVersionsQuery{DashboardId: int64(999), OrgId: 1}
DashboardId: int64(999),
}
err := GetDashboardVersions(&cmd) err := GetDashboardVersions(&query)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
So(err, ShouldEqual, m.ErrNoVersionsForDashboardId) So(err, ShouldEqual, m.ErrNoVersionsForDashboardId)
So(len(cmd.Result), ShouldEqual, 0) So(len(query.Result), ShouldEqual, 0)
}) })
Convey("Get all versions for an updated dashboard", func() { Convey("Get all versions for an updated dashboard", func() {
...@@ -94,12 +90,11 @@ func TestGetDashboardVersions(t *testing.T) { ...@@ -94,12 +90,11 @@ func TestGetDashboardVersions(t *testing.T) {
"tags": "different-tag", "tags": "different-tag",
}) })
cmd := m.GetDashboardVersionsCommand{ query := m.GetDashboardVersionsQuery{DashboardId: savedDash.Id, OrgId: 1}
DashboardId: savedDash.Id, err := GetDashboardVersions(&query)
}
err := GetDashboardVersions(&cmd)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(cmd.Result), ShouldEqual, 2) So(len(query.Result), ShouldEqual, 2)
}) })
}) })
} }
...@@ -114,19 +109,19 @@ func TestCompareDashboardVersions(t *testing.T) { ...@@ -114,19 +109,19 @@ func TestCompareDashboardVersions(t *testing.T) {
}) })
Convey("Compare two versions that are different", func() { Convey("Compare two versions that are different", func() {
getVersionCmd := m.GetDashboardVersionsCommand{ query := m.GetDashboardVersionsQuery{DashboardId: savedDash.Id, OrgId: 1}
DashboardId: savedDash.Id,
} err := GetDashboardVersions(&query)
err := GetDashboardVersions(&getVersionCmd)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(getVersionCmd.Result), ShouldEqual, 2) So(len(query.Result), ShouldEqual, 2)
cmd := m.CompareDashboardVersionsCommand{ cmd := m.CompareDashboardVersionsCommand{
DashboardId: savedDash.Id, DashboardId: savedDash.Id,
Original: getVersionCmd.Result[0].Version, Original: query.Result[0].Version,
New: getVersionCmd.Result[1].Version, New: query.Result[1].Version,
DiffType: m.DiffDelta, DiffType: m.DiffDelta,
} }
err = CompareDashboardVersionsCommand(&cmd) err = CompareDashboardVersionsCommand(&cmd)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(cmd.Delta, ShouldNotBeNil) So(cmd.Delta, ShouldNotBeNil)
...@@ -169,10 +164,8 @@ func TestRestoreDashboardVersion(t *testing.T) { ...@@ -169,10 +164,8 @@ func TestRestoreDashboardVersion(t *testing.T) {
}) })
Convey("Restore dashboard to a previous version", func() { Convey("Restore dashboard to a previous version", func() {
versionsCmd := m.GetDashboardVersionsCommand{ query := m.GetDashboardVersionsQuery{DashboardId: savedDash.Id, OrgId: 1}
DashboardId: savedDash.Id, err := GetDashboardVersions(&query)
}
err := GetDashboardVersions(&versionsCmd)
So(err, ShouldBeNil) So(err, ShouldBeNil)
cmd := m.RestoreDashboardVersionCommand{ cmd := m.RestoreDashboardVersionCommand{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment