diff --git a/board.go b/board.go index da8edf1f..e3aaa1fd 100644 --- a/board.go +++ b/board.go @@ -85,7 +85,7 @@ type ( AutoCount *int `json:"auto_count,omitempty"` Datasource *string `json:"datasource"` Refresh BoolInt `json:"refresh"` - Options []Option `json:"options"` + Options []Option `json:"options,omitempty"` IncludeAll bool `json:"includeAll"` AllFormat string `json:"allFormat"` AllValue string `json:"allValue"` diff --git a/rest-dashboard_test.go b/rest-dashboard_test.go index c80fef94..852eaa3b 100644 --- a/rest-dashboard_test.go +++ b/rest-dashboard_test.go @@ -410,3 +410,52 @@ func TestCustomPanelSerialization(t *testing.T) { t.Fatalf("expected to not have any CustomPanel keys, got: %v", cnt) } } + +func TestTemplatingOptionsSerialization(t *testing.T) { + + for i := 0; i < 2; i++ { + + var options []sdk.Option = nil + + if i == 1 { + options = []sdk.Option{{}} + } + + board := &sdk.Board{ + Templating: sdk.Templating{List: []sdk.TemplateVar{ + { + Options: options, + }, + }}, + } + + boardJson, err := json.Marshal(board) + if err != nil { + t.Fatal(err) + } + + var boardMap map[string]interface{} + + err = json.Unmarshal(boardJson, &boardMap) + if err != nil { + t.Fatal(err) + } + + templatingMap, found := boardMap["templating"].(map[string]interface{}) + if !found { + t.Fatal() + } + + list, found := templatingMap["list"].([]interface{}) + if !found { + t.Fatal() + } + + _, found = list[0].(map[string]interface{})["options"] + if options == nil && found { + t.Fatal() + } else if options != nil && !found { + t.Fatal() + } + } +}