Skip to content

Commit

Permalink
Check for invalid legend attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Mar 29, 2020
1 parent 1dc6a21 commit f1b11b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions decoder/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ rows:
require.Equal(t, ErrNoAlertThresholdDefined, err)
}

func TestUnmarshalYAMLWithInvalidLegendGraph(t *testing.T) {
payload := `
rows:
- name: Test row
panels:
- graph:
title: Heap allocations
legend: [invalid_attribute]
targets:
- prometheus: { query: "go_memstats_heap_alloc_bytes" }
`

_, err := UnmarshalYAML(bytes.NewBufferString(payload))

require.Error(t, err)
require.Equal(t, ErrInvalidLegendAttribute, err)
}

func TestUnmarshalYAMLWithInvalidAlertValueFunctionGraph(t *testing.T) {
payload := `
rows:
Expand Down
3 changes: 3 additions & 0 deletions decoder/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

var ErrNoAlertThresholdDefined = fmt.Errorf("no threshold defined")
var ErrInvalidAlertValueFunc = fmt.Errorf("invalid alert value function")
var ErrInvalidLegendAttribute = fmt.Errorf("invalid legend attribute")

type DashboardGraph struct {
Title string
Expand Down Expand Up @@ -100,6 +101,8 @@ func (graphPanel *DashboardGraph) legend() ([]graph.LegendOption, error) {
opt = graph.NoNullSeries
case "no_zero_series":
opt = graph.NoZeroSeries
default:
return nil, ErrInvalidLegendAttribute
}

opts = append(opts, opt)
Expand Down

0 comments on commit f1b11b0

Please sign in to comment.