2015-05-29 19:50:05 +00:00
|
|
|
package toml_test
|
|
|
|
|
|
|
|
import (
|
2015-11-06 00:40:42 +00:00
|
|
|
"bytes"
|
|
|
|
"strings"
|
2015-05-29 19:50:05 +00:00
|
|
|
"testing"
|
2015-11-06 00:40:42 +00:00
|
|
|
"time"
|
2015-05-29 19:50:05 +00:00
|
|
|
|
2015-11-06 00:40:42 +00:00
|
|
|
"github.com/BurntSushi/toml"
|
2016-02-10 17:26:18 +00:00
|
|
|
"github.com/influxdata/influxdb/cmd/influxd/run"
|
|
|
|
itoml "github.com/influxdata/influxdb/toml"
|
2015-05-29 19:50:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Ensure that megabyte sizes can be parsed.
|
|
|
|
func TestSize_UnmarshalText_MB(t *testing.T) {
|
2015-11-06 00:40:42 +00:00
|
|
|
var s itoml.Size
|
2015-05-29 19:50:05 +00:00
|
|
|
if err := s.UnmarshalText([]byte("200m")); err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
} else if s != 200*(1<<20) {
|
|
|
|
t.Fatalf("unexpected size: %d", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that gigabyte sizes can be parsed.
|
|
|
|
func TestSize_UnmarshalText_GB(t *testing.T) {
|
2015-11-06 00:40:42 +00:00
|
|
|
var s itoml.Size
|
2015-08-19 19:50:54 +00:00
|
|
|
if err := s.UnmarshalText([]byte("1g")); err != nil {
|
2015-05-29 19:50:05 +00:00
|
|
|
t.Fatalf("unexpected error: %s", err)
|
2015-08-19 19:50:54 +00:00
|
|
|
} else if s != 1073741824 {
|
2015-05-29 19:50:05 +00:00
|
|
|
t.Fatalf("unexpected size: %d", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_Encode(t *testing.T) {
|
2015-11-06 00:40:42 +00:00
|
|
|
var c run.Config
|
|
|
|
c.Cluster.WriteTimeout = itoml.Duration(time.Minute)
|
2015-05-29 19:50:05 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := toml.NewEncoder(buf).Encode(&c); err != nil {
|
|
|
|
t.Fatal("Failed to encode: ", err)
|
|
|
|
}
|
2015-11-06 00:40:42 +00:00
|
|
|
got, search := buf.String(), `write-timeout = "1m0s"`
|
2015-05-29 19:50:05 +00:00
|
|
|
if !strings.Contains(got, search) {
|
|
|
|
t.Fatalf("Encoding config failed.\nfailed to find %s in:\n%s\n", search, got)
|
|
|
|
}
|
|
|
|
}
|