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
parent
c0cc730857
commit
803906e25a
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/influxdata/chronograf"
|
"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))
|
axes := make(map[string]chronograf.Axis, len(c.Axes))
|
||||||
for a, r := range c.Axes {
|
for a, r := range c.Axes {
|
||||||
axis := chronograf.Axis{}
|
if r.Bounds != nil {
|
||||||
// repair legacy bounds
|
axes[a] = chronograf.Axis{
|
||||||
for _, bound := range r.LegacyBounds {
|
Bounds: r.Bounds,
|
||||||
axis.Bounds = append(axis.Bounds, strconv.FormatInt(bound, 10))
|
}
|
||||||
|
} else {
|
||||||
|
axes[a] = chronograf.Axis{
|
||||||
|
Bounds: []string{},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Bounds) > 0 {
|
|
||||||
axis.Bounds = r.Bounds
|
|
||||||
}
|
|
||||||
axes[a] = axis
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cells[i] = chronograf.DashboardCell{
|
cells[i] = chronograf.DashboardCell{
|
||||||
|
|
|
@ -201,7 +201,80 @@ func Test_MarshalDashboard_WithLegacyBounds(t *testing.T) {
|
||||||
},
|
},
|
||||||
Axes: map[string]chronograf.Axis{
|
Axes: map[string]chronograf.Axis{
|
||||||
"y": 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",
|
Type: "line",
|
||||||
|
|
Loading…
Reference in New Issue