Sfoglia il codice sorgente

InfluxDB integration test

Nick Babcock 6 anni fa
parent
commit
fc3fec5416
3 ha cambiato i file con 33 aggiunte e 1 eliminazioni
  1. 25 0
      OhmGraphite.Test/InfluxTest.cs
  2. 1 1
      OhmGraphite/InfluxWriter.cs
  3. 7 0
      docker-compose.yml

+ 25 - 0
OhmGraphite.Test/InfluxTest.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Net.Http;
+using System.Threading;
+using Xunit;
+
+namespace OhmGraphite.Test
+{
+    public class InfluxTest
+    {
+        [Fact, Trait("Category", "integration")]
+        public async void CanInsertIntoInflux()
+        {
+            var config = new InfluxConfig(new Uri("http://influx:8086"), "mydb", "my_user", "my_pass");
+            var writer = new InfluxWriter(config, "my-pc");
+            await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
+
+            Thread.Sleep(TimeSpan.FromSeconds(1));
+            var client = new HttpClient();
+            var resp = await client.GetAsync("http://influx:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
+            Assert.True(resp.IsSuccessStatusCode);
+            var content = await resp.Content.ReadAsStringAsync();
+            Assert.Contains("/intelcpu/0/temperature/0", content);
+        }
+    }
+}

+ 1 - 1
OhmGraphite/InfluxWriter.cs

@@ -9,7 +9,7 @@ using OpenHardwareMonitor.Hardware;
 
 namespace OhmGraphite
 {
-    class InfluxWriter : IWriteMetrics
+    public class InfluxWriter : IWriteMetrics
     {
         private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
 

+ 7 - 0
docker-compose.yml

@@ -1,5 +1,11 @@
 version: '3'
 services:
+  influx:
+    image: influxdb:alpine
+    environment:
+      INFLUXDB_DB: "mydb"
+      INFLUXDB_USER: "my_user"
+      INFLUXDB_USER_PASSWORD: "my_pass"
   redis:
     image: redis:alpine
   graphite:
@@ -21,4 +27,5 @@ services:
     depends_on:
       - timescale
       - graphite
+      - influx
     command: ./ci/wait-for-it.sh timescale:5432 -- ./ci/wait-for-it.sh graphite:80 -- mono /root/.nuget/packages/xunit.runner.console/2.4.0/tools/net461/xunit.console.exe OhmGraphite.Test/bin/Debug/net461/OhmGraphite.Test.dll