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",
|
|
|
|
URL: []string{"http://twin-pines.mall.io:8086", "https://lonepine.mall.io:8086"},
|
|
|
|
Default: true,
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|