Return nothing from previously set bounds

Previously, if bounds were not set, the default value that would be
returned was ["0", "0"], which is incorrect. This now returns [] when
there was nothing set for a particular axis.
pull/10616/head
Tim Raymond 2017-08-02 10:58:01 -04:00
parent c0cc730857
commit 803906e25a
2 changed files with 82 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package internal
import (
"encoding/json"
"strconv"
"github.com/gogo/protobuf/proto"
"github.com/influxdata/chronograf"
@ -268,16 +267,15 @@ func UnmarshalDashboard(data []byte, d *chronograf.Dashboard) error {
axes := make(map[string]chronograf.Axis, len(c.Axes))
for a, r := range c.Axes {
axis := chronograf.Axis{}
// repair legacy bounds
for _, bound := range r.LegacyBounds {
axis.Bounds = append(axis.Bounds, strconv.FormatInt(bound, 10))
if r.Bounds != nil {
axes[a] = chronograf.Axis{
Bounds: r.Bounds,
}
} else {
axes[a] = chronograf.Axis{
Bounds: []string{},
}
}
if len(r.Bounds) > 0 {
axis.Bounds = r.Bounds
}
axes[a] = axis
}
cells[i] = chronograf.DashboardCell{

View File

@ -201,7 +201,80 @@ func Test_MarshalDashboard_WithLegacyBounds(t *testing.T) {
},
Axes: map[string]chronograf.Axis{
"y": chronograf.Axis{
Bounds: []string{"0", "5"},
Bounds: []string{},
},
},
Type: "line",
},
},
Templates: []chronograf.Template{},
Name: "Dashboard",
}
var actual chronograf.Dashboard
if buf, err := internal.MarshalDashboard(dashboard); err != nil {
t.Fatal("Error marshaling dashboard: err", err)
} else if err := internal.UnmarshalDashboard(buf, &actual); err != nil {
t.Fatal("Error unmarshaling dashboard: err:", err)
} else if !cmp.Equal(expected, actual) {
t.Fatalf("Dashboard protobuf copy error: diff follows:\n%s", cmp.Diff(expected, actual))
}
}
func Test_MarshalDashboard_WithNoLegacyBounds(t *testing.T) {
dashboard := chronograf.Dashboard{
ID: 1,
Cells: []chronograf.DashboardCell{
{
ID: "9b5367de-c552-4322-a9e8-7f384cbd235c",
X: 0,
Y: 0,
W: 4,
H: 4,
Name: "Super awesome query",
Queries: []chronograf.DashboardQuery{
{
Command: "select * from cpu",
Label: "CPU Utilization",
Range: &chronograf.Range{
Upper: int64(100),
},
},
},
Axes: map[string]chronograf.Axis{
"y": chronograf.Axis{
LegacyBounds: [2]int64{},
},
},
Type: "line",
},
},
Templates: []chronograf.Template{},
Name: "Dashboard",
}
expected := chronograf.Dashboard{
ID: 1,
Cells: []chronograf.DashboardCell{
{
ID: "9b5367de-c552-4322-a9e8-7f384cbd235c",
X: 0,
Y: 0,
W: 4,
H: 4,
Name: "Super awesome query",
Queries: []chronograf.DashboardQuery{
{
Command: "select * from cpu",
Label: "CPU Utilization",
Range: &chronograf.Range{
Upper: int64(100),
},
},
},
Axes: map[string]chronograf.Axis{
"y": chronograf.Axis{
Bounds: []string{},
},
},
Type: "line",