|
@@ -16,6 +16,8 @@ package file
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "github.com/benbjohnson/clock"
|
|
|
|
+ "github.com/lf-edge/ekuiper/internal/conf"
|
|
"github.com/lf-edge/ekuiper/internal/io/mock"
|
|
"github.com/lf-edge/ekuiper/internal/io/mock"
|
|
"github.com/lf-edge/ekuiper/pkg/api"
|
|
"github.com/lf-edge/ekuiper/pkg/api"
|
|
"io"
|
|
"io"
|
|
@@ -33,10 +35,11 @@ func TestJsonFile(t *testing.T) {
|
|
meta := map[string]interface{}{
|
|
meta := map[string]interface{}{
|
|
"file": filepath.Join(path, "test", "test.json"),
|
|
"file": filepath.Join(path, "test", "test.json"),
|
|
}
|
|
}
|
|
|
|
+ mc := conf.Clock.(*clock.Mock)
|
|
exp := []api.SourceTuple{
|
|
exp := []api.SourceTuple{
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(1), "name": "John Doe"}, meta),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(2), "name": "Jane Doe"}, meta),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(3), "name": "John Smith"}, meta),
|
|
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(1), "name": "John Doe"}, meta, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(2), "name": "Jane Doe"}, meta, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(3), "name": "John Smith"}, meta, mc.Now()),
|
|
}
|
|
}
|
|
p := map[string]interface{}{
|
|
p := map[string]interface{}{
|
|
"path": filepath.Join(path, "test"),
|
|
"path": filepath.Join(path, "test"),
|
|
@@ -55,14 +58,15 @@ func TestJsonFolder(t *testing.T) {
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ mc := conf.Clock.(*clock.Mock)
|
|
moveToFolder := filepath.Join(path, "test", "moveTo")
|
|
moveToFolder := filepath.Join(path, "test", "moveTo")
|
|
exp := []api.SourceTuple{
|
|
exp := []api.SourceTuple{
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(1), "name": "John Doe", "height": 1.82}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f1.json")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(2), "name": "Jane Doe", "height": 1.65}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f1.json")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(3), "name": "Will Doe", "height": 1.76}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f2.json")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(4), "name": "Dude Doe", "height": 1.92}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f3.json")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(5), "name": "Jane Doe", "height": 1.72}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f3.json")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(6), "name": "John Smith", "height": 2.22}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f3.json")}),
|
|
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(1), "name": "John Doe", "height": 1.82}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f1.json")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(2), "name": "Jane Doe", "height": 1.65}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f1.json")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(3), "name": "Will Doe", "height": 1.76}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f2.json")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(4), "name": "Dude Doe", "height": 1.92}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f3.json")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(5), "name": "Jane Doe", "height": 1.72}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f3.json")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(6), "name": "John Smith", "height": 2.22}, map[string]interface{}{"file": filepath.Join(path, "test", "json", "f3.json")}, mc.Now()),
|
|
}
|
|
}
|
|
p := map[string]interface{}{
|
|
p := map[string]interface{}{
|
|
"path": filepath.Join(path, "test"),
|
|
"path": filepath.Join(path, "test"),
|
|
@@ -111,12 +115,13 @@ func TestCSVFolder(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ mc := conf.Clock.(*clock.Mock)
|
|
// Start testing
|
|
// Start testing
|
|
exp := []api.SourceTuple{
|
|
exp := []api.SourceTuple{
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"@": "#", "id": "1", "ts": "1670170500", "value": "161.927872"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "a.csv")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"@": "#", "id": "2", "ts": "1670170900", "value": "176"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "a.csv")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": "33", "ts": "1670270500", "humidity": "89"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "b.csv")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": "44", "ts": "1670270900", "humidity": "76"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "b.csv")}),
|
|
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"@": "#", "id": "1", "ts": "1670170500", "value": "161.927872"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "a.csv")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"@": "#", "id": "2", "ts": "1670170900", "value": "176"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "a.csv")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": "33", "ts": "1670270500", "humidity": "89"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "b.csv")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": "44", "ts": "1670270900", "humidity": "76"}, map[string]interface{}{"file": filepath.Join(path, "test", "csvTemp", "b.csv")}, mc.Now()),
|
|
}
|
|
}
|
|
p := map[string]interface{}{
|
|
p := map[string]interface{}{
|
|
"fileType": "csv",
|
|
"fileType": "csv",
|
|
@@ -175,10 +180,11 @@ func TestCSVFile(t *testing.T) {
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ mc := conf.Clock.(*clock.Mock)
|
|
exp := []api.SourceTuple{
|
|
exp := []api.SourceTuple{
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"ns": "@", "id": "id", "ts": "ts", "number": "value"}, map[string]interface{}{"file": filepath.Join(path, "test", "csv", "a.csv")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"ns": "#", "id": "1", "ts": "1670170500", "number": "161.927872"}, map[string]interface{}{"file": filepath.Join(path, "test", "csv", "a.csv")}),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"ns": "#", "id": "2", "ts": "1670170900", "number": "176"}, map[string]interface{}{"file": filepath.Join(path, "test", "csv", "a.csv")}),
|
|
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"ns": "@", "id": "id", "ts": "ts", "number": "value"}, map[string]interface{}{"file": filepath.Join(path, "test", "csv", "a.csv")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"ns": "#", "id": "1", "ts": "1670170500", "number": "161.927872"}, map[string]interface{}{"file": filepath.Join(path, "test", "csv", "a.csv")}, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"ns": "#", "id": "2", "ts": "1670170900", "number": "176"}, map[string]interface{}{"file": filepath.Join(path, "test", "csv", "a.csv")}, mc.Now()),
|
|
}
|
|
}
|
|
p := map[string]interface{}{
|
|
p := map[string]interface{}{
|
|
"fileType": "csv",
|
|
"fileType": "csv",
|
|
@@ -205,10 +211,11 @@ func TestJsonLines(t *testing.T) {
|
|
meta := map[string]interface{}{
|
|
meta := map[string]interface{}{
|
|
"file": filepath.Join(path, "test", "test.lines"),
|
|
"file": filepath.Join(path, "test", "test.lines"),
|
|
}
|
|
}
|
|
|
|
+ mc := conf.Clock.(*clock.Mock)
|
|
exp := []api.SourceTuple{
|
|
exp := []api.SourceTuple{
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(1), "name": "John Doe"}, meta),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(2), "name": "Jane Doe"}, meta),
|
|
|
|
- api.NewDefaultSourceTuple(map[string]interface{}{"id": float64(3), "name": "John Smith"}, meta),
|
|
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(1), "name": "John Doe"}, meta, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(2), "name": "Jane Doe"}, meta, mc.Now()),
|
|
|
|
+ api.NewDefaultSourceTupleWithTime(map[string]interface{}{"id": float64(3), "name": "John Smith"}, meta, mc.Now()),
|
|
}
|
|
}
|
|
p := map[string]interface{}{
|
|
p := map[string]interface{}{
|
|
"path": filepath.Join(path, "test"),
|
|
"path": filepath.Join(path, "test"),
|