1 /** 2 This module implements integration tests for Influx API 3 4 Authors: Atila Neves (Kaleidic Associates Advisory Limited) 5 6 Generated documentation: 7 http://influxdb.code.kaleidic.io/influxdb.html 8 9 */ 10 module integration.api; 11 12 import unit_threaded; 13 import influxdb; 14 import integration.common: influxURL; 15 16 17 /// 18 @Serial 19 @("Database api") 20 unittest { 21 22 import influxdb.api: Database, Measurement; 23 24 const database = Database(influxURL, "myspecialDB"); 25 scope(exit) database.drop; 26 27 database.insert(Measurement("cpu", ["tag1": "foo"], ["temperature": "42"])); 28 database.insert(Measurement("cpu", ["tag1": "foo"], ["temperature": "68"])); 29 30 { 31 const response = database.query("SELECT * from cpu"); 32 const result = response.results[0]; 33 const series = result.series[0]; 34 series.rows.length.shouldEqual(2); 35 } 36 37 { 38 const response = database.query("SELECT * from cpu WHERE temperature > 50"); 39 const result = response.results[0]; 40 const series = result.series[0]; 41 series.rows.length.shouldEqual(1); 42 } 43 } 44 45 /// 46 @Serial 47 @("Database multiple inserts") 48 unittest { 49 50 import influxdb.api: Database, Measurement; 51 52 const database = Database(influxURL, "myspecialDB"); 53 scope(exit) database.drop; 54 55 database.insert(Measurement("cpu", ["tag1": "foo"], ["temperature": "42"]), 56 Measurement("cpu", ["tag1": "bar"], ["temperature": "68"]), 57 Measurement("cpu", ["tag1": "baz"], ["temperature": "54"])); 58 59 const response = database.query("SELECT * from cpu WHERE temperature > 50"); 60 const result = response.results[0]; 61 const series = result.series[0]; 62 series.rows.length.shouldEqual(2); 63 } 64 65 /// 66 @Serial 67 @("Database explicit timestamps") 68 unittest { 69 70 import influxdb.api: Database, Measurement; 71 import std.datetime; 72 73 const database = Database(influxURL, "myspecialDB"); 74 scope(exit) database.drop; 75 76 database.insert(Measurement("cpu", ["tag1": "foo"], ["temperature": "42"], SysTime(DateTime(2017, 1, 1)))); 77 database.insert(Measurement("cpu", ["tag1": "foo"], ["temperature": "68"], SysTime(DateTime(2015, 1, 1)))); 78 79 { 80 const response = database.query("SELECT * from cpu"); 81 const result = response.results[0]; 82 const series = result.series[0]; 83 series.rows.length.shouldEqual(2); 84 } 85 86 { 87 const response = database.query("SELECT * from cpu WHERE time >= '2016-01-01 00:00:00'"); 88 const result = response.results[0]; 89 const series = result.series[0]; 90 series.rows.length.shouldEqual(1); 91 } 92 93 } 94 95 @Serial 96 @("string data") 97 unittest { 98 import influxdb.api: Database, Measurement; 99 100 const database = Database(influxURL, "myspecialDB"); 101 scope(exit) database.drop; 102 103 database.insert(Measurement("cpu", ["string": "foo"])); 104 } 105 106 @Serial 107 @("float data") 108 unittest { 109 import influxdb.api: Database, Measurement; 110 111 const database = Database(influxURL, "myspecialDB"); 112 scope(exit) database.drop; 113 114 database.insert(Measurement("cpu", ["value": "42.3"])); 115 } 116 117 @Serial 118 @("bool data") 119 unittest { 120 import influxdb.api: Database, Measurement; 121 122 const database = Database(influxURL, "myspecialDB"); 123 scope(exit) database.drop; 124 125 database.insert(Measurement("cpu", ["value": "true"])); 126 database.insert(Measurement("cpu", ["value": "false"])); 127 }