2016-09-22 23:22:41 +00:00
|
|
|
package internal_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-10-20 14:38:23 +00:00
|
|
|
"github.com/influxdata/chronograf"
|
|
|
|
"github.com/influxdata/chronograf/bolt/internal"
|
2016-09-22 23:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Ensure an exploration can be marshaled and unmarshaled.
|
|
|
|
func TestMarshalExploration(t *testing.T) {
|
2016-10-20 14:38:23 +00:00
|
|
|
v := chronograf.Exploration{
|
2016-09-22 23:22:41 +00:00
|
|
|
ID: 12,
|
|
|
|
Name: "Some Exploration",
|
|
|
|
UserID: 34,
|
|
|
|
Data: "{\"data\":\"something\"}",
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
UpdatedAt: time.Now().UTC(),
|
|
|
|
}
|
|
|
|
|
2016-10-20 14:38:23 +00:00
|
|
|
var vv chronograf.Exploration
|
2016-09-22 23:22:41 +00:00
|
|
|
if buf, err := internal.MarshalExploration(&v); err != nil {
|
|
|
|
t.Fatal(err)
|
2016-09-28 19:32:58 +00:00
|
|
|
} else if err := internal.UnmarshalExploration(buf, &vv); err != nil {
|
2016-09-22 23:22:41 +00:00
|
|
|
t.Fatal(err)
|
2016-09-28 19:32:58 +00:00
|
|
|
} else if !reflect.DeepEqual(v, vv) {
|
|
|
|
t.Fatalf("exploration protobuf copy error: got %#v, expected %#v", vv, v)
|
2016-09-22 23:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-30 20:39:27 +00:00
|
|
|
|
|
|
|
func TestMarshalSource(t *testing.T) {
|
2016-10-20 14:38:23 +00:00
|
|
|
v := chronograf.Source{
|
2016-09-30 20:39:27 +00:00
|
|
|
ID: 12,
|
|
|
|
Name: "Fountain of Truth",
|
|
|
|
Type: "influx",
|
|
|
|
Username: "docbrown",
|
|
|
|
Password: "1 point twenty-one g1g@w@tts",
|
2016-10-25 15:20:06 +00:00
|
|
|
URL: "http://twin-pines.mall.io:8086",
|
2016-09-30 20:39:27 +00:00
|
|
|
Default: true,
|
2016-11-18 19:13:32 +00:00
|
|
|
Telegraf: "telegraf",
|
2016-09-30 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 14:38:23 +00:00
|
|
|
var vv chronograf.Source
|
2016-09-30 20:39:27 +00:00
|
|
|
if buf, err := internal.MarshalSource(v); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if err := internal.UnmarshalSource(buf, &vv); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if !reflect.DeepEqual(v, vv) {
|
|
|
|
t.Fatalf("source protobuf copy error: got %#v, expected %#v", vv, v)
|
|
|
|
}
|
|
|
|
}
|
2016-10-03 17:41:50 +00:00
|
|
|
|
|
|
|
func TestMarshalServer(t *testing.T) {
|
2016-10-20 14:38:23 +00:00
|
|
|
v := chronograf.Server{
|
2016-10-03 17:41:50 +00:00
|
|
|
ID: 12,
|
|
|
|
SrcID: 2,
|
|
|
|
Name: "Fountain of Truth",
|
|
|
|
Username: "docbrown",
|
|
|
|
Password: "1 point twenty-one g1g@w@tts",
|
|
|
|
URL: "http://oldmanpeabody.mall.io:9092",
|
|
|
|
}
|
|
|
|
|
2016-10-20 14:38:23 +00:00
|
|
|
var vv chronograf.Server
|
2016-10-03 17:41:50 +00:00
|
|
|
if buf, err := internal.MarshalServer(v); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if err := internal.UnmarshalServer(buf, &vv); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if !reflect.DeepEqual(v, vv) {
|
|
|
|
t.Fatalf("source protobuf copy error: got %#v, expected %#v", vv, v)
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 17:27:27 +00:00
|
|
|
|
|
|
|
func TestMarshalLayout(t *testing.T) {
|
|
|
|
layout := chronograf.Layout{
|
|
|
|
ID: "id",
|
|
|
|
Measurement: "measurement",
|
|
|
|
Application: "app",
|
|
|
|
Cells: []chronograf.Cell{
|
|
|
|
{
|
2016-11-29 21:04:54 +00:00
|
|
|
X: 1,
|
|
|
|
Y: 1,
|
|
|
|
W: 4,
|
|
|
|
H: 4,
|
|
|
|
I: "anotherid",
|
2016-12-06 10:48:12 +00:00
|
|
|
Type: "line",
|
2016-11-29 21:04:54 +00:00
|
|
|
Name: "cell1",
|
2016-11-22 17:27:27 +00:00
|
|
|
Queries: []chronograf.Query{
|
|
|
|
{
|
2016-11-29 21:04:54 +00:00
|
|
|
Range: &chronograf.Range{
|
|
|
|
Lower: 1,
|
|
|
|
Upper: 2,
|
|
|
|
},
|
|
|
|
Label: "y1",
|
2016-11-22 17:27:27 +00:00
|
|
|
Command: "select mean(usage_user) as usage_user from cpu",
|
|
|
|
Wheres: []string{
|
|
|
|
`"host"="myhost"`,
|
|
|
|
},
|
|
|
|
GroupBys: []string{
|
|
|
|
`"cpu"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var vv chronograf.Layout
|
|
|
|
if buf, err := internal.MarshalLayout(layout); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if err := internal.UnmarshalLayout(buf, &vv); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if !reflect.DeepEqual(layout, vv) {
|
|
|
|
t.Fatalf("source protobuf copy error: got %#v, expected %#v", vv, layout)
|
|
|
|
}
|
|
|
|
}
|