diff --git a/testdata/csverror.csv b/testdata/csverror.csv new file mode 100644 index 0000000..db0fee0 --- /dev/null +++ b/testdata/csverror.csv @@ -0,0 +1,3 @@ +2018-01-01T10:00:00.0Z,1.0 +2018-01-02T10:00:00.0Z +2018-01-02T10:00:00.0Z,2.0 diff --git a/testdata/floaterror.csv b/testdata/floaterror.csv new file mode 100644 index 0000000..02104bd --- /dev/null +++ b/testdata/floaterror.csv @@ -0,0 +1,3 @@ +2018-01-01T10:00:00.0Z,1.0 +2018-01-02T10:00:00.0Z,str +2018-01-02T10:00:00.0Z,2.0 diff --git a/timeseries_test.go b/timeseries_test.go index 0c59493..73da33f 100644 --- a/timeseries_test.go +++ b/timeseries_test.go @@ -33,6 +33,14 @@ func TestTimeSeriesRead(t *testing.T) { if record != 1.0 { t.Errorf("unexpected record value %#v", record) } + + testtime = time.Date(2018, 1, 1, 11, 0, 0, 0, time.UTC) + record, err = ts.Lookup(testtime) + err, ok := err.(InvalidTimestamp) + if !ok { + t.Fatalf("expected InvalidTimestamp") + } + err.Error() } func TestTimeSeriesRead_DateOnly(t *testing.T) { @@ -46,6 +54,42 @@ func TestTimeSeriesRead_DateOnly(t *testing.T) { } } +func TestTimeSeriesRead_Error(t *testing.T) { + ts := NewTimeSeries() + err := ts.Read("testdata/csverror.csv") + if err == nil { + t.Fatal("expected error") + } + length := len(ts.records) + if length != 1 { + t.Errorf("unexpected series length %v", length) + } +} + +func TestTimeSeriesRead_DateError(t *testing.T) { + ts := NewTimeSeries() + err := ts.Read("testdata/dateerror.csv") + if err == nil { + t.Fatal("expected error") + } + length := len(ts.records) + if length != 1 { + t.Errorf("unexpected series length %v", length) + } +} + +func TestTimeSeriesRead_FloatError(t *testing.T) { + ts := NewTimeSeries() + err := ts.Read("testdata/floaterror.csv") + if err == nil { + t.Fatal("expected error") + } + length := len(ts.records) + if length != 1 { + t.Errorf("unexpected series length %v", length) + } +} + func TestTimeSeriesWrite(t *testing.T) { ts := NewTimeSeries() if err := ts.Read("testdata/simple.csv"); err != nil {