diff --git a/pkg/logfile/logfile_test.go b/pkg/logfile/logfile_test.go index 990aec1..9b95d17 100644 --- a/pkg/logfile/logfile_test.go +++ b/pkg/logfile/logfile_test.go @@ -1,133 +1 @@ package logfile_test - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/go-flucky/flucky/pkg/logfile" - uuid "github.com/satori/go.uuid" - "github.com/stretchr/testify/require" -) - -var tmpDir = os.TempDir() - -type interfaceMap struct { - testFile string - logfileA logfile.Logfile - goldenFile string - logfileB logfile.Logfile -} - -func TestCompression(t *testing.T) { - require := require.New(t) - - testDir, cleanup := createTestDir(t) - defer cleanup() - - testfiles := []*interfaceMap{ - &interfaceMap{ - testFile: "pkg/logfile/test/json/testCompression_01.json", - logfileA: logfile.New(filepath.Join(testDir, "testCompression_01.json")), - goldenFile: "pkg/logfile/test/json/goldenCompression_01.json", - logfileB: logfile.New(filepath.Join(testDir, "goldenCompression_01.json")), - }, - } - - createTestFiles(t, testfiles) - - temperatures, err := testfiles[0].logfileA.ReadTemperatures() - require.Nil(err) - - temperatures = logfile.CompressTemperature(temperatures) - - diffLogfile := logfile.New(filepath.Join(testDir, "diffCompression_01.json")) - err = diffLogfile.WriteTemperatures(temperatures) - require.Nil(err) - - // verifyFileWithAsset(t, filepath.Join(testDir, "diffCompression_01.json"), "pkg/logfile/test/json/goldenCompression_01.json") -} - -func TestConvertTemperatures(t *testing.T) { - require := require.New(t) - - markupLanguages := []string{"csv", "json", "xml"} - - for _, markupLanguageFrom := range markupLanguages { - testDir, cleanup := createTestDir(t) - defer cleanup() - - for _, markupLanguageTo := range markupLanguages { - - convertMaps := []*interfaceMap{ - &interfaceMap{ - testFile: fmt.Sprintf("pkg/logfile/test/%v/validTemperatures_01.%v", markupLanguageFrom, markupLanguageFrom), - logfileA: logfile.New(filepath.Join(testDir, fmt.Sprintf("validTemperatures_01.%v", markupLanguageFrom))), - goldenFile: fmt.Sprintf("pkg/logfile/test/%v/validTemperatures_01.%v", markupLanguageTo, markupLanguageTo), - logfileB: logfile.New(filepath.Join(testDir, fmt.Sprintf("validTemperatures_01.%v", markupLanguageTo))), - }, - &interfaceMap{ - testFile: fmt.Sprintf("pkg/logfile/test/%v/validTemperatures_02.%v", markupLanguageFrom, markupLanguageFrom), - logfileA: logfile.New(filepath.Join(testDir, fmt.Sprintf("validTemperatures_02.%v", markupLanguageFrom))), - goldenFile: fmt.Sprintf("pkg/logfile/test/%v/validTemperatures_02.%v", markupLanguageTo, markupLanguageTo), - logfileB: logfile.New(filepath.Join(testDir, fmt.Sprintf("validTemperatures_02.%v", markupLanguageTo))), - }, - } - - createTestFiles(t, convertMaps) - - for _, convertMap := range convertMaps { - temperatures, err := convertMap.logfileA.ReadTemperatures() - require.Nil(err) - - err = convertMap.logfileB.WriteTemperatures(temperatures) - require.Nil(err) - - verifyFileWithAsset(t, convertMap.logfileB.GetLogfile(), convertMap.goldenFile) - } - - } - } -} - -func createTestFiles(t *testing.T, interfaceMaps []*interfaceMap) { - require := require.New(t) - - for _, interfaceMap := range interfaceMaps { - f, err := os.Create(interfaceMap.logfileA.GetLogfile()) - require.Nil(err) - f.Write(MustAsset(interfaceMap.testFile)) - f.Close() - - verifyFileWithAsset(t, interfaceMap.logfileA.GetLogfile(), interfaceMap.testFile) - } -} - -func createTestDir(t *testing.T) (string, func() error) { - require := require.New(t) - - testDir := filepath.Join(tmpDir, uuid.NewV4().String()) - - err := os.MkdirAll(testDir, 0755) - require.Nil(err) - - rmDir := func() error { - return os.RemoveAll(testDir) - } - - return testDir, rmDir -} - -func verifyFileWithAsset(t *testing.T, file string, asset string) { - require := require.New(t) - f, err := os.Open(file) - require.Nil(err) - defer f.Close() - - bytes, err := ioutil.ReadAll(f) - require.Nil(err) - - require.Equalf(string(MustAsset(asset)), string(bytes), "Asset %v and file %v not even", asset, file) -} diff --git a/pkg/logfile/test/csv/validTemperatures_01.csv b/pkg/logfile/test/csv/validTemperatures_01.csv deleted file mode 100644 index da2c99d..0000000 --- a/pkg/logfile/test/csv/validTemperatures_01.csv +++ /dev/null @@ -1,2 +0,0 @@ -a469503b-fc16-4e72-8d29-7eeee08ba957,24.562,celsius,2019-06-14 21:15:28.504051541 +0200,2019-06-14 21:18:07.384104493 +0200,84eac248-6927-4db6-b6f9-7891ce2d301e,2019-06-14 21:18:07.465885864 +0200,2019-06-14 21:18:07.46587076 +0200 -5f119ba3-bcea-4c3b-aabb-0406ea70f7e1,24.375,celsius,2019-06-14 21:15:28.583856443 +0200,2019-06-14 21:18:07.463893776 +0200,efcd755e-82d1-4789-a50b-355b8735b8d8,2019-06-14 21:18:07.465885864 +0200,2019-06-14 21:18:07.46587701 +0200 diff --git a/pkg/logfile/test/csv/validTemperatures_02.csv b/pkg/logfile/test/csv/validTemperatures_02.csv deleted file mode 100644 index 5a4af88..0000000 --- a/pkg/logfile/test/csv/validTemperatures_02.csv +++ /dev/null @@ -1,2 +0,0 @@ -a469503b-fc16-4e72-8d29-7eeee08ba957,24.562,celsius,2019-06-14 21:15:28.504051541 +0200,2019-06-14 21:18:07.384104493 +0200,84eac248-6927-4db6-b6f9-7891ce2d301e,2019-06-14 21:18:07.465885864 +0200,2019-06-14 21:18:07.46587076 +0200 -5f119ba3-bcea-4c3b-aabb-0406ea70f7e1,24.375,celsius,2019-06-14 21:15:28.583856443 +0200,2019-06-14 21:15:28.583856443 +0200,efcd755e-82d1-4789-a50b-355b8735b8d8,2019-06-14 21:18:07.465885864 +0200, diff --git a/pkg/logfile/test/json/faultyTemperatures_01.json b/pkg/logfile/test/json/faultyTemperatures_01.json deleted file mode 100644 index 8149145..0000000 --- a/pkg/logfile/test/json/faultyTemperatures_01.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_unit": "celsius", - "temperature_from_date": "2019-10-01T00:00:00+02:00", - "temperature_till_date": "2019-05-01T00:00:00+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-05-01T00:00:00+02:00", - "update_date": "2019-10-01T00:00:00+02:00" - } -] diff --git a/pkg/logfile/test/json/faultyTemperatures_02.json b/pkg/logfile/test/json/faultyTemperatures_02.json deleted file mode 100644 index 718fc43..0000000 --- a/pkg/logfile/test/json/faultyTemperatures_02.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_unit": "celsius", - "temperature_from_date": "2019-05-01T00:00:00+02:00", - "temperature_till_date": "2019-10-01T00:00:00+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-10-01T00:00:00+02:00", - "update_date": "2019-05-01T00:00:00+02:00" - } -] diff --git a/pkg/logfile/test/json/faultyTemperatures_03.json b/pkg/logfile/test/json/faultyTemperatures_03.json deleted file mode 100644 index 0cfce29..0000000 --- a/pkg/logfile/test/json/faultyTemperatures_03.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_unit": "celsius", - "temperature_from_date": "2019-05-01T00:00:00+02:00", - "temperature_till_date": "2019-10-01T00:00:00+02:00", - "sensor_id": "", - "creation_date": "2019-05-01T00:00:00+02:00", - "update_date": "2019-10-01T00:00:00+02:00" - } -] diff --git a/pkg/logfile/test/json/faultyTemperatures_04.json b/pkg/logfile/test/json/faultyTemperatures_04.json deleted file mode 100644 index 2730c30..0000000 --- a/pkg/logfile/test/json/faultyTemperatures_04.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "0", - "temperature_unit": "celsius", - "temperature_from_date": "2019-05-01T00:00:00+02:00", - "temperature_till_date": "2019-10-01T00:00:00+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-05-01T00:00:00+02:00", - "update_date": "2019-10-01T00:00:00+02:00" - } -] diff --git a/pkg/logfile/test/json/faultyTemperatures_05.json b/pkg/logfile/test/json/faultyTemperatures_05.json deleted file mode 100644 index 2699251..0000000 --- a/pkg/logfile/test/json/faultyTemperatures_05.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "temperature_id": "", - "temperature_value": "24.562", - "temperature_unit": "celsius", - "temperature_from_date": "2019-05-01T00:00:00+02:00", - "temperature_till_date": "2019-10-01T00:00:00+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-05-01T00:00:00+02:00", - "update_date": "2019-10-01T00:00:00+02:00" - } -] diff --git a/pkg/logfile/test/json/goldenCompression_01.json b/pkg/logfile/test/json/goldenCompression_01.json deleted file mode 100644 index 0263ab7..0000000 --- a/pkg/logfile/test/json/goldenCompression_01.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "temperature_id": "96b93a1c-414c-49d7-82e0-fc57aa313551", - "temperature_value": "28", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-24T20:27:16.455833877+02:00", - "temperature_till_date": "2019-06-24T20:27:19.335708331+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-24T20:27:38.712842338+02:00", - "update_date": "2019-06-24T20:27:19.338708331+02:00" - }, - { - "temperature_id": "2ae8be89-e31a-4b97-b8ba-aea9e54b8ed1", - "temperature_value": "27.75", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-24T20:27:23.175690867+02:00", - "temperature_till_date": "2019-06-24T20:27:23.175692898+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-24T20:27:38.712842338+02:00", - "update_date": null - } -] diff --git a/pkg/logfile/test/json/testCompression_01.json b/pkg/logfile/test/json/testCompression_01.json deleted file mode 100644 index e15ca10..0000000 --- a/pkg/logfile/test/json/testCompression_01.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "temperature_id": "96b93a1c-414c-49d7-82e0-fc57aa313551", - "temperature_value": "28", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-24T20:27:16.455833877+02:00", - "temperature_till_date": "2019-06-24T20:27:16.455836117+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-24T20:27:38.712842338+02:00", - "update_date": null - }, - { - "temperature_id": "da4c443b-81e7-4d23-9ad4-f912c476098a", - "temperature_value": "28", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-24T20:27:19.33570604+02:00", - "temperature_till_date": "2019-06-24T20:27:19.335708331+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-24T20:27:38.712842338+02:00", - "update_date": null - }, - { - "temperature_id": "2ae8be89-e31a-4b97-b8ba-aea9e54b8ed1", - "temperature_value": "27.75", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-24T20:27:23.175690867+02:00", - "temperature_till_date": "2019-06-24T20:27:23.175692898+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-24T20:27:38.712842338+02:00", - "update_date": null - } -] diff --git a/pkg/logfile/test/json/validTemperatures_01.json b/pkg/logfile/test/json/validTemperatures_01.json deleted file mode 100644 index 99655b5..0000000 --- a/pkg/logfile/test/json/validTemperatures_01.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-14T21:15:28.504051541+02:00", - "temperature_till_date": "2019-06-14T21:18:07.384104493+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": "2019-06-14T21:18:07.46587076+02:00" - }, - { - "temperature_id": "5f119ba3-bcea-4c3b-aabb-0406ea70f7e1", - "temperature_value": "24.375", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-14T21:15:28.583856443+02:00", - "temperature_till_date": "2019-06-14T21:18:07.463893776+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": "2019-06-14T21:18:07.46587701+02:00" - } -] diff --git a/pkg/logfile/test/json/validTemperatures_02.json b/pkg/logfile/test/json/validTemperatures_02.json deleted file mode 100644 index 9955304..0000000 --- a/pkg/logfile/test/json/validTemperatures_02.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "temperature_id": "a469503b-fc16-4e72-8d29-7eeee08ba957", - "temperature_value": "24.562", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-14T21:15:28.504051541+02:00", - "temperature_till_date": "2019-06-14T21:18:07.384104493+02:00", - "sensor_id": "84eac248-6927-4db6-b6f9-7891ce2d301e", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": "2019-06-14T21:18:07.46587076+02:00" - }, - { - "temperature_id": "5f119ba3-bcea-4c3b-aabb-0406ea70f7e1", - "temperature_value": "24.375", - "temperature_unit": "celsius", - "temperature_from_date": "2019-06-14T21:15:28.583856443+02:00", - "temperature_till_date": "2019-06-14T21:15:28.583856443+02:00", - "sensor_id": "efcd755e-82d1-4789-a50b-355b8735b8d8", - "creation_date": "2019-06-14T21:18:07.465885864+02:00", - "update_date": null - } -] diff --git a/pkg/logfile/test/xml/validTemperatures_01.xml b/pkg/logfile/test/xml/validTemperatures_01.xml deleted file mode 100644 index 205c034..0000000 --- a/pkg/logfile/test/xml/validTemperatures_01.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - a469503b-fc16-4e72-8d29-7eeee08ba957 - 24.562 - celsius - 2019-06-14T21:15:28.504051541+02:00 - 2019-06-14T21:18:07.384104493+02:00 - 84eac248-6927-4db6-b6f9-7891ce2d301e - 2019-06-14T21:18:07.465885864+02:00 - 2019-06-14T21:18:07.46587076+02:00 - - - 5f119ba3-bcea-4c3b-aabb-0406ea70f7e1 - 24.375 - celsius - 2019-06-14T21:15:28.583856443+02:00 - 2019-06-14T21:18:07.463893776+02:00 - efcd755e-82d1-4789-a50b-355b8735b8d8 - 2019-06-14T21:18:07.465885864+02:00 - 2019-06-14T21:18:07.46587701+02:00 - - \ No newline at end of file diff --git a/pkg/logfile/test/xml/validTemperatures_02.xml b/pkg/logfile/test/xml/validTemperatures_02.xml deleted file mode 100644 index 6ac6089..0000000 --- a/pkg/logfile/test/xml/validTemperatures_02.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - a469503b-fc16-4e72-8d29-7eeee08ba957 - 24.562 - celsius - 2019-06-14T21:15:28.504051541+02:00 - 2019-06-14T21:18:07.384104493+02:00 - 84eac248-6927-4db6-b6f9-7891ce2d301e - 2019-06-14T21:18:07.465885864+02:00 - 2019-06-14T21:18:07.46587076+02:00 - - - 5f119ba3-bcea-4c3b-aabb-0406ea70f7e1 - 24.375 - celsius - 2019-06-14T21:15:28.583856443+02:00 - 2019-06-14T21:15:28.583856443+02:00 - efcd755e-82d1-4789-a50b-355b8735b8d8 - 2019-06-14T21:18:07.465885864+02:00 - - \ No newline at end of file