From 5f53207f0ac0efe1297ff8c8997b53a2b6de528e Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Mon, 24 Jun 2019 22:57:45 +0200 Subject: [PATCH] test(pkg/logfile): compress temperature logfile --- pkg/logfile/{interface.go => interfaces.go} | 0 pkg/logfile/logfile_test.go | 31 +++++++++++++++++- .../test/json/goldenCompression_01.json | 22 +++++++++++++ pkg/logfile/test/json/testCompression_01.json | 32 +++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) rename pkg/logfile/{interface.go => interfaces.go} (100%) create mode 100644 pkg/logfile/test/json/goldenCompression_01.json create mode 100644 pkg/logfile/test/json/testCompression_01.json diff --git a/pkg/logfile/interface.go b/pkg/logfile/interfaces.go similarity index 100% rename from pkg/logfile/interface.go rename to pkg/logfile/interfaces.go diff --git a/pkg/logfile/logfile_test.go b/pkg/logfile/logfile_test.go index 4a3ed9f..990aec1 100644 --- a/pkg/logfile/logfile_test.go +++ b/pkg/logfile/logfile_test.go @@ -21,7 +21,36 @@ type interfaceMap struct { logfileB logfile.Logfile } -func TestConvert(t *testing.T) { +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"} diff --git a/pkg/logfile/test/json/goldenCompression_01.json b/pkg/logfile/test/json/goldenCompression_01.json new file mode 100644 index 0000000..0263ab7 --- /dev/null +++ b/pkg/logfile/test/json/goldenCompression_01.json @@ -0,0 +1,22 @@ +[ + { + "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 new file mode 100644 index 0000000..e15ca10 --- /dev/null +++ b/pkg/logfile/test/json/testCompression_01.json @@ -0,0 +1,32 @@ +[ + { + "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 + } +]