Skip to content

Commit

Permalink
fix: compatibility with web platform
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Jan 4, 2022
1 parent b057b0d commit 93546a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions test/commons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:influxdb_client/api.dart';

/// enable HTTP tracing
bool debugEnabled = true;
/// check if a platform is WEB
const bool isWeb = identical(0, 0.0);

/// global test properties
late InfluxDBClient client;
Expand Down
15 changes: 9 additions & 6 deletions test/point_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:influxdb_client/api.dart';
import 'commons_test.dart';

import 'package:test/test.dart';

Expand Down Expand Up @@ -34,14 +35,14 @@ void main() {
.addTag('loc1', 'europe')
.addTag('loc2', 'america')
.addField('int', 1)
.addField('double', 2.0)
.addField('double', 2.2)
.addField('bigInt', BigInt.from(8))
.addField('boolFalse', false)
.addField('boolTrue', true)
.addField('string', 'string value');

var expected = 'h2o,loc1=europe,loc2=america bigInt=8,boolFalse=false,'
'boolTrue=true,double=2.0,int=1i,string="string value"';
'boolTrue=true,double=2.2,int=1i,string="string value"';
expect(point.toLineProtocol(WritePrecision.ns), expected);
});

Expand All @@ -53,15 +54,15 @@ void main() {
expect(point.toLineProtocol(WritePrecision.ns),
'h2o,location=europe level=2i 123');

var date = 9223372036854775807;
var date = 9007199254740991;

point = Point.measurement('h2o')
.addTag('location', 'europe')
.addField('level', 2)
.time(date);

expect(point.toLineProtocol(WritePrecision.ns),
'h2o,location=europe level=2i 9223372036854775807');
'h2o,location=europe level=2i 9007199254740991');

var time = DateTime.parse('2020-06-22T10:26:03.800123456Z');

Expand All @@ -70,16 +71,18 @@ void main() {
.addField('level', 2)
.time(time);

final ns_precision = isWeb ? '1592821563800000000' : '1592821563800123000';
expect(point.toLineProtocol(WritePrecision.ns),
'h2o,location=europe level=2i 1592821563800123000');
'h2o,location=europe level=2i $ns_precision');

point = Point.measurement('h2o')
.addTag('location', 'europe')
.addField('level', 2)
.time(time);

final us_precision = isWeb ? '1592821563800000' : '1592821563800123';
expect(point.toLineProtocol(WritePrecision.us),
'h2o,location=europe level=2i 1592821563800123');
'h2o,location=europe level=2i $us_precision');

point = Point.measurement('h2o')
.addTag('location', 'europe')
Expand Down

0 comments on commit 93546a2

Please sign in to comment.