From 3a270747e2c6ff0ed618c999fd9101b3943ff61c Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Fri, 10 Nov 2017 16:02:35 -0800 Subject: [PATCH] Add test for queryConfig validation --- server/queryconfig_test.go | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 server/queryconfig_test.go diff --git a/server/queryconfig_test.go b/server/queryconfig_test.go new file mode 100644 index 0000000000..03b84558ee --- /dev/null +++ b/server/queryconfig_test.go @@ -0,0 +1,50 @@ +package server + +import ( + "testing" + + "github.com/influxdata/chronograf" +) + +func TestValidateQueryConfig(t *testing.T) { + tests := []struct { + name string + q *chronograf.QueryConfig + wantErr bool + }{ + { + name: "invalid field type", + q: &chronograf.QueryConfig{ + Fields: []chronograf.Field{ + { + Type: "invalid", + }, + }, + }, + wantErr: true, + }, + { + name: "invalid field args", + q: &chronograf.QueryConfig{ + Fields: []chronograf.Field{ + { + Type: "func", + Args: []chronograf.Field{ + { + Type: "invalid", + }, + }, + }, + }, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := ValidateQueryConfig(tt.q); (err != nil) != tt.wantErr { + t.Errorf("ValidateQueryConfig() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}