2018-07-04 00:40:50 +00:00
|
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
2018-07-06 01:40:52 +00:00
|
|
|
|
"context"
|
2018-07-04 00:40:50 +00:00
|
|
|
|
"encoding/json"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf"
|
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf/mocks"
|
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf/organizations"
|
2018-07-04 00:40:50 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestOrganizationConfig(t *testing.T) {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
type args struct {
|
|
|
|
|
organizationID string
|
|
|
|
|
}
|
2018-07-04 00:40:50 +00:00
|
|
|
|
type fields struct {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore chronograf.OrganizationConfigStore
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
type wants struct {
|
|
|
|
|
statusCode int
|
|
|
|
|
contentType string
|
|
|
|
|
body string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
2018-07-06 01:40:52 +00:00
|
|
|
|
args args
|
2018-07-04 00:40:50 +00:00
|
|
|
|
fields fields
|
|
|
|
|
wants wants
|
|
|
|
|
}{
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
name: "Get organization configuration",
|
|
|
|
|
args: args{
|
|
|
|
|
organizationID: "default",
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "default":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
OrganizationID: "default",
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "time",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 1,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
2018-07-06 01:40:52 +00:00
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
2018-07-06 01:40:52 +00:00
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "message",
|
|
|
|
|
Position: 3,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "facility",
|
|
|
|
|
Position: 4,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "procid",
|
|
|
|
|
Position: 5,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "displayName",
|
|
|
|
|
Value: "Proc ID",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "appname",
|
|
|
|
|
Position: 6,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "displayName",
|
|
|
|
|
Value: "Application",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "host",
|
|
|
|
|
Position: 7,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
contentType: "application/json",
|
2018-07-10 23:05:11 +00:00
|
|
|
|
body: `{"links":{"self":"/chronograf/v1/org_config","logViewer":"/chronograf/v1/org_config/logviewer"},"organization":"default","logViewer":{"columns":[{"name":"time","position":0,"encodings":[{"type":"visibility","value":"hidden"}]},{"name":"severity","position":1,"encodings":[{"type":"visibility","value":"visible"},{"type":"label","value":"icon"},{"type":"label","value":"text"}]},{"name":"timestamp","position":2,"encodings":[{"type":"visibility","value":"visible"}]},{"name":"message","position":3,"encodings":[{"type":"visibility","value":"visible"}]},{"name":"facility","position":4,"encodings":[{"type":"visibility","value":"visible"}]},{"name":"procid","position":5,"encodings":[{"type":"visibility","value":"visible"},{"type":"displayName","value":"Proc ID"}]},{"name":"appname","position":6,"encodings":[{"type":"visibility","value":"visible"},{"type":"displayName","value":"Application"}]},{"name":"host","position":7,"encodings":[{"type":"visibility","value":"visible"}]}]}}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
s := &Service{
|
|
|
|
|
Store: &mocks.Store{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
OrganizationConfigStore: tt.fields.organizationConfigStore,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
r := httptest.NewRequest("GET", "http://any.url", nil)
|
2018-07-06 01:40:52 +00:00
|
|
|
|
ctx := context.WithValue(r.Context(), organizations.ContextKey, tt.args.organizationID)
|
|
|
|
|
r = r.WithContext(ctx)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
2018-07-06 01:40:52 +00:00
|
|
|
|
s.OrganizationConfig(w, r)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
|
|
|
|
resp := w.Result()
|
|
|
|
|
content := resp.Header.Get("Content-Type")
|
|
|
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
|
|
if resp.StatusCode != tt.wants.statusCode {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
t.Errorf("%q. OrganizationConfig() = %v, want %v", tt.name, resp.StatusCode, tt.wants.statusCode)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
if tt.wants.contentType != "" && content != tt.wants.contentType {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
t.Errorf("%q. OrganizationConfig() = %v, want %v", tt.name, content, tt.wants.contentType)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
t.Errorf("%q. OrganizationConfig() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLogViewerOrganizationConfig(t *testing.T) {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
type args struct {
|
|
|
|
|
organizationID string
|
|
|
|
|
}
|
2018-07-04 00:40:50 +00:00
|
|
|
|
type fields struct {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore chronograf.OrganizationConfigStore
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
type wants struct {
|
|
|
|
|
statusCode int
|
|
|
|
|
contentType string
|
|
|
|
|
body string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
2018-07-06 01:40:52 +00:00
|
|
|
|
args args
|
2018-07-04 00:40:50 +00:00
|
|
|
|
fields fields
|
|
|
|
|
wants wants
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "Get log viewer configuration",
|
2018-07-06 01:40:52 +00:00
|
|
|
|
args: args{
|
|
|
|
|
organizationID: "default",
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "default":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "emergency",
|
|
|
|
|
Name: "ruby",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "displayName",
|
|
|
|
|
Value: "Log Severity",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
contentType: "application/json",
|
2018-07-06 01:40:52 +00:00
|
|
|
|
body: `{"links":{"self":"/chronograf/v1/org_config/logviewer"},"columns":[{"name":"severity","position":0,"encodings":[{"type":"color","value":"emergency","name":"ruby"},{"type":"color","value":"info","name":"rainforest"},{"type":"displayName","value":"Log Severity"}]}]}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
s := &Service{
|
|
|
|
|
Store: &mocks.Store{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
OrganizationConfigStore: tt.fields.organizationConfigStore,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
r := httptest.NewRequest("GET", "http://any.url", nil)
|
2018-07-06 01:40:52 +00:00
|
|
|
|
ctx := context.WithValue(r.Context(), organizations.ContextKey, tt.args.organizationID)
|
|
|
|
|
r = r.WithContext(ctx)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
2018-07-10 19:05:29 +00:00
|
|
|
|
s.OrganizationLogViewerConfig(w, r)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
|
|
|
|
resp := w.Result()
|
|
|
|
|
content := resp.Header.Get("Content-Type")
|
|
|
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
|
|
if resp.StatusCode != tt.wants.statusCode {
|
2018-07-09 23:36:22 +00:00
|
|
|
|
t.Errorf("%q. LogViewerOrganizationConfig() = %v, want %v", tt.name, resp.StatusCode, tt.wants.statusCode)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
if tt.wants.contentType != "" && content != tt.wants.contentType {
|
2018-07-09 23:36:22 +00:00
|
|
|
|
t.Errorf("%q. LogViewerOrganizationConfig() = %v, want %v", tt.name, content, tt.wants.contentType)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
|
2018-07-09 23:36:22 +00:00
|
|
|
|
t.Errorf("%q. LogViewerOrganizationConfig() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestReplaceLogViewerOrganizationConfig(t *testing.T) {
|
|
|
|
|
type fields struct {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore chronograf.OrganizationConfigStore
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
type args struct {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
payload interface{} // expects JSON serializable struct
|
|
|
|
|
organizationID string
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
type wants struct {
|
|
|
|
|
statusCode int
|
|
|
|
|
contentType string
|
|
|
|
|
body string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
fields fields
|
|
|
|
|
args args
|
|
|
|
|
wants wants
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "Set log viewer configuration",
|
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "1337":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-10 22:42:44 +00:00
|
|
|
|
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
return nil
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
payload: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 1,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "pineapple",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "emergency",
|
|
|
|
|
Name: "ruby",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "messages",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "displayName",
|
|
|
|
|
Value: "Log Messages",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationID: "1337",
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
contentType: "application/json",
|
2018-07-06 01:40:52 +00:00
|
|
|
|
body: `{"links":{"self":"/chronograf/v1/org_config/logviewer"},"columns":[{"name":"severity","position":1,"encodings":[{"type":"color","value":"info","name":"pineapple"},{"type":"color","value":"emergency","name":"ruby"},{"type":"visibility","value":"visible"},{"type":"label","value":"icon"}]},{"name":"messages","position":0,"encodings":[{"type":"displayName","value":"Log Messages"},{"type":"visibility","value":"visible"}]}]}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Set invalid log viewer configuration – empty",
|
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "1337":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-10 22:42:44 +00:00
|
|
|
|
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
return nil
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
payload: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationID: "1337",
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 400,
|
|
|
|
|
contentType: "application/json",
|
2018-11-21 14:22:35 +00:00
|
|
|
|
body: `{"code":400,"message":"invalid log viewer config: must have at least 1 column"}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Set invalid log viewer configuration - duplicate column name",
|
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "1337":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "procid",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-10 22:42:44 +00:00
|
|
|
|
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
return nil
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
payload: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "procid",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "procid",
|
|
|
|
|
Position: 1,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationID: "1337",
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 400,
|
|
|
|
|
contentType: "application/json",
|
2018-11-21 14:22:35 +00:00
|
|
|
|
body: `{"code":400,"message":"invalid log viewer config: Duplicate column name procid"}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Set invalid log viewer configuration - multiple columns with same position value",
|
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "1337":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "procid",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-10 22:42:44 +00:00
|
|
|
|
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
return nil
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
payload: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "procid",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "hidden",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationID: "1337",
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 400,
|
|
|
|
|
contentType: "application/json",
|
2018-11-21 14:22:35 +00:00
|
|
|
|
body: `{"code":400,"message":"invalid log viewer config: Multiple columns with same position value"}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Set invalid log viewer configuration – no visibility",
|
|
|
|
|
fields: fields{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationConfigStore: &mocks.OrganizationConfigStore{
|
|
|
|
|
FindOrCreateF: func(ctx context.Context, orgID string) (*chronograf.OrganizationConfig, error) {
|
|
|
|
|
switch orgID {
|
|
|
|
|
case "1337":
|
|
|
|
|
return &chronograf.OrganizationConfig{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
2018-07-04 00:40:50 +00:00
|
|
|
|
{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}, nil
|
|
|
|
|
default:
|
2018-07-10 18:28:58 +00:00
|
|
|
|
return nil, chronograf.ErrOrganizationConfigNotFound
|
2018-07-06 01:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-10 22:42:44 +00:00
|
|
|
|
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
2018-07-06 01:40:52 +00:00
|
|
|
|
return nil
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
payload: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 1,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "pineapple",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "emergency",
|
|
|
|
|
Name: "ruby",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
organizationID: "1337",
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
statusCode: 400,
|
|
|
|
|
contentType: "application/json",
|
2018-11-21 14:22:35 +00:00
|
|
|
|
body: `{"code":400,"message":"invalid log viewer config: missing visibility encoding in column severity"}`,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
s := &Service{
|
|
|
|
|
Store: &mocks.Store{
|
2018-07-06 01:40:52 +00:00
|
|
|
|
OrganizationConfigStore: tt.fields.organizationConfigStore,
|
2018-07-04 00:40:50 +00:00
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
r := httptest.NewRequest("GET", "http://any.url", nil)
|
2018-07-06 01:40:52 +00:00
|
|
|
|
ctx := context.WithValue(r.Context(), organizations.ContextKey, tt.args.organizationID)
|
|
|
|
|
r = r.WithContext(ctx)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
buf, _ := json.Marshal(tt.args.payload)
|
|
|
|
|
r.Body = ioutil.NopCloser(bytes.NewReader(buf))
|
|
|
|
|
|
2018-07-10 19:05:29 +00:00
|
|
|
|
s.ReplaceOrganizationLogViewerConfig(w, r)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
|
|
|
|
|
resp := w.Result()
|
|
|
|
|
content := resp.Header.Get("Content-Type")
|
|
|
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
|
|
if resp.StatusCode != tt.wants.statusCode {
|
2018-07-09 23:36:22 +00:00
|
|
|
|
t.Errorf("%q. ReplaceLogViewerOrganizationConfig() = %v, want %v", tt.name, resp.StatusCode, tt.wants.statusCode)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
if tt.wants.contentType != "" && content != tt.wants.contentType {
|
2018-07-09 23:36:22 +00:00
|
|
|
|
t.Errorf("%q. ReplaceLogViewerOrganizationConfig() = %v, want %v", tt.name, content, tt.wants.contentType)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
if eq, _ := jsonEqual(string(body), tt.wants.body); tt.wants.body != "" && !eq {
|
2018-07-09 23:36:22 +00:00
|
|
|
|
t.Errorf("%q. ReplaceLogViewerOrganizationConfig() = \n***%v***\n,\nwant\n***%v***", tt.name, string(body), tt.wants.body)
|
2018-07-04 00:40:50 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-10 00:29:48 +00:00
|
|
|
|
|
|
|
|
|
func Test_validLogViewerConfig(t *testing.T) {
|
|
|
|
|
type args struct {
|
|
|
|
|
LogViewer chronograf.LogViewerConfig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
args args
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "cannot have 0 columns",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: nil,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "can have 1 column",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "can have more than 1 column",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "message",
|
|
|
|
|
Position: 3,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "facility",
|
|
|
|
|
Position: 4,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "cannot have multiple columns with the same name value",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 3,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "cannot have multiple columns with the same position value",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "message",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "each column must have a visibility encoding value of either 'visible' or 'hidden'",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "timestamp",
|
|
|
|
|
Position: 2,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "bob",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "message",
|
|
|
|
|
Position: 3,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "severity column can have 1 of each icon and text label encoding",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "severity column can 1 icon label encoding",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "severity column can have 1 text label encoding",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "severity column cannot have 0 label encodings",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "severity column cannot have more than 1 icon label encoding",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "icon",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "severity column cannot have more than 1 text label encoding",
|
|
|
|
|
args: args{
|
|
|
|
|
LogViewer: chronograf.LogViewerConfig{
|
|
|
|
|
Columns: []chronograf.LogViewerColumn{
|
|
|
|
|
{
|
|
|
|
|
Name: "severity",
|
|
|
|
|
Position: 0,
|
|
|
|
|
Encodings: []chronograf.ColumnEncoding{
|
|
|
|
|
{
|
|
|
|
|
Type: "visibility",
|
|
|
|
|
Value: "visible",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "color",
|
|
|
|
|
Value: "info",
|
|
|
|
|
Name: "rainforest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "text",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Type: "label",
|
|
|
|
|
Value: "text",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
got := validLogViewerConfig(tt.args.LogViewer)
|
|
|
|
|
|
2018-11-01 19:03:51 +00:00
|
|
|
|
if (tt.wantErr && got == nil) || (!tt.wantErr && got != nil) {
|
2018-07-10 00:29:48 +00:00
|
|
|
|
t.Errorf("%q. validLogViewerConfig().\ngot: %v\nwantErr: %v", tt.name, got, tt.wantErr)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|