Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
Align dependencies (#51)
Browse files Browse the repository at this point in the history
* Align dependencies

* Fix storage tests

* Fix pub/sub tests

* Transform expect into assert

* Update documentation about indexes for datastore

* Fix dartanalyzer warnings

* Remove .idea in gitignore
  • Loading branch information
sestegra authored and jakobr-google committed Mar 15, 2018
1 parent a2f49db commit fd53065
Show file tree
Hide file tree
Showing 19 changed files with 444 additions and 394 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pubspec.lock
packages
.pub
.packages
.packages
8 changes: 5 additions & 3 deletions lib/src/pubsub_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,12 @@ class _TopicPageImpl implements Page<Topic> {
final List<Topic> items;

_TopicPageImpl(this._api, this._pageSize, pubsub.ListTopicsResponse response)
: items = new List(response.topics.length),
: items = new List(response.topics != null ? response.topics.length : 0),
_nextPageToken = response.nextPageToken {
for (int i = 0; i < response.topics.length; i++) {
items[i] = new _TopicImpl(_api, response.topics[i]);
if (response.topics != null) {
for (int i = 0; i < response.topics.length; i++) {
items[i] = new _TopicImpl(_api, response.topics[i]);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/storage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class _MediaUploadStreamSink implements StreamSink<List<int>> {
final _controller = new StreamController<List<int>>(sync: true);
StreamSubscription _subscription;
StreamController _resumableController;
final _doneCompleter = new Completer<_ObjectInfoImpl>();
final _doneCompleter = new Completer<dynamic>();

static const int _STATE_LENGTH_KNOWN = 0;
static const int _STATE_PROBING_LENGTH = 1;
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ homepage: https://github.com/dart-lang/gcloud
environment:
sdk: '>=1.13.0 <2.0.0'
dependencies:
googleapis: '>=0.2.0 <0.45.0'
googleapis_beta: '>=0.10.0 <0.40.0'
googleapis: '>=0.50.0 <0.51.0'
googleapis_beta: '>=0.45.0 <0.46.0'
http: '>=0.11.0 <0.12.0'
dev_dependencies:
googleapis_auth: '>=0.2.3 <0.3.0'
http_parser: '>=2.0.0 <4.0.0'
mime: '>=0.9.0+3 <0.10.0'
unittest: '>=0.11.0 <0.12.0'
test: '>=0.12.0 <0.13.0'
transformers:
- $dart2js:
$include: []
2 changes: 1 addition & 1 deletion test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:http/http.dart' as http;
import 'package:http/testing.dart' as http_testing;
import 'package:http_parser/http_parser.dart' as http_parser;
import 'package:mime/mime.dart' as mime;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

const CONTENT_TYPE_JSON_UTF8 = 'application/json; charset=utf-8';

Expand Down
28 changes: 2 additions & 26 deletions test/common_e2e.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ library gcloud.test.common_e2e;
import 'dart:async';
import 'dart:io';

import 'package:unittest/unittest.dart';
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:http/http.dart' as http;

Expand Down Expand Up @@ -78,7 +77,7 @@ Future withAuthClient(List<String> scopes, AuthCallback callback,

if (!onBot() && (project == null || serviceKeyLocation == null)) {
throw new StateError(
'Envoronment variables $PROJECT_ENV and $SERVICE_KEY_LOCATION_ENV '
'Environment variables $PROJECT_ENV and $SERVICE_KEY_LOCATION_ENV '
'required when not running on the package bot');
}

Expand All @@ -92,30 +91,7 @@ Future withAuthClient(List<String> scopes, AuthCallback callback,
.clientViaServiceAccount(creds, scopes)
.then((http.Client client) {
if (trace) client = new TraceClient(client);
return callback(project, client).whenComplete(() => client.close());
return callback(project, client);
});
});
}

Future runE2EUnittest(Function callback) {
var config = new E2EConfiguration();

unittestConfiguration = config;
callback();

return config.done;
}

class E2EConfiguration extends SimpleConfiguration {
final Completer _completer = new Completer();

Future get done => _completer.future;

onDone(success) {
new Future.sync(() {
super.onDone(success);
})
.then((_) => _completer.complete(_))
.catchError((error, stack) => _completer.completeError(error, stack));
}
}
40 changes: 25 additions & 15 deletions test/datastore/e2e/datastore_test_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ library datastore_test;
/// - name: listproperty
/// - name: test_property
/// direction: desc
/// $ gcloud preview datastore create-indexes .
/// 02:19 PM Host: appengine.google.com
/// 02:19 PM Uploading index definitions.
/// $ gcloud datastore create-indexes index.yaml
///
/// Now, wait for indexing done
import 'dart:async';

import 'package:gcloud/datastore.dart';
import 'package:gcloud/src/datastore_impl.dart' as datastore_impl;
import 'package:gcloud/common.dart';
import 'package:unittest/unittest.dart';
import 'package:http/http.dart';
import 'package:test/test.dart';

import '../../common_e2e.dart';
import '../error_matchers.dart';
Expand All @@ -47,7 +48,7 @@ Future<List<Entity>> consumePages(FirstPageProvider provider) {
return new StreamFromPages(provider).stream.toList();
}

runTests(Datastore datastore, String namespace) {
void runTests(Datastore datastore, String namespace) {
Partition partition = new Partition(namespace);

Future withTransaction(Function f, {bool xg: false}) {
Expand Down Expand Up @@ -254,10 +255,10 @@ runTests(Datastore datastore, String namespace) {
transactional: true, xg: true);
});

test('negative_insert_20000_entities', () {
test('negative_insert_20000_entities', () async {
// Maybe it should not be a [DataStoreError] here?
// FIXME/TODO: This was adapted
expect(datastore.commit(inserts: named20000), throws);
expect(datastore.commit(inserts: named20000), throwsA(isSocketException));
});

// TODO: test invalid inserts (like entities without key, ...)
Expand Down Expand Up @@ -598,6 +599,7 @@ runTests(Datastore datastore, String namespace) {
throwsA(isTransactionAbortedError));
});
});

group('query', () {
Future<List<Entity>> testQuery(String kind,
{List<Filter> filters,
Expand Down Expand Up @@ -737,7 +739,7 @@ runTests(Datastore datastore, String namespace) {
var sortedAndFiltered = sorted.where(filterFunction).toList();
var sortedAndListFiltered = sorted.where(listFilterFunction).toList();
var indexedEntity = sorted.where(indexFilterMatches).toList();
expect(indexedEntity.length, equals(1));
assert(indexedEntity.length == 1);

var filters = [
new Filter(FilterRelation.GreatherThan, QUERY_KEY, QUERY_LOWER_BOUND),
Expand Down Expand Up @@ -1019,7 +1021,7 @@ runTests(Datastore datastore, String namespace) {
return datastore.commit(deletes: [subSubKey, subSubKey2]);
}
];
return Future.forEach(futures, (f) => f()).then(expectAsync((_) {}));
return Future.forEach(futures, (f) => f()).then(expectAsync1((_) {}));
});
});
});
Expand Down Expand Up @@ -1098,13 +1100,21 @@ Future waitUntilEntitiesHelper(
});
}

main() {
Future main() async {
Datastore datastore;
BaseClient client;

var scopes = datastore_impl.DatastoreImpl.SCOPES;
await withAuthClient(scopes, (String project, httpClient) {
datastore = new datastore_impl.DatastoreImpl(httpClient, project);
client = httpClient;
return cleanupDB(datastore, null);
});

withAuthClient(scopes, (String project, httpClient) {
var datastore = new datastore_impl.DatastoreImpl(httpClient, 's~$project');
return cleanupDB(datastore, null).then((_) {
return runE2EUnittest(() => runTests(datastore, null));
});
tearDownAll(() async {
await cleanupDB(datastore, null);
client.close();
});

runTests(datastore, null);
}
11 changes: 10 additions & 1 deletion test/datastore/error_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

library error_matchers;

import 'package:unittest/unittest.dart';
import 'dart:io';

import 'package:test/test.dart';
import 'package:gcloud/datastore.dart';

class _ApplicationError extends TypeMatcher {
Expand Down Expand Up @@ -37,6 +39,11 @@ class _IntMatcher extends TypeMatcher {
bool matches(item, Map matchState) => item is int;
}

class _SocketException extends TypeMatcher {
const _SocketException() : super("SocketException");
bool matches(item, Map matchState) => item is SocketException;
}

const isApplicationError = const _ApplicationError();

const isDataStoreError = const _DataStoreError();
Expand All @@ -45,3 +52,5 @@ const isNeedIndexError = const _NeedIndexError();
const isTimeoutError = const _TimeoutError();

const isInt = const _IntMatcher();

const isSocketException = const _SocketException();
2 changes: 1 addition & 1 deletion test/db/db_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
library gcloud.db_test;

import 'package:gcloud/db.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

@Kind()
class Foobar extends Model {}
Expand Down
48 changes: 29 additions & 19 deletions test/db/e2e/db_test_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ library db_test;
/// - name: name
/// direction: asc
///
/// $ gcloud preview datastore create-indexes .
/// 02:19 PM Host: appengine.google.com
/// 02:19 PM Uploading index definitions.
/// $ gcloud datastore create-indexes index.yaml
///
/// Now, wait for indexing done
import 'dart:async';

import 'package:unittest/unittest.dart';
import 'package:gcloud/db.dart' as db;
import 'package:gcloud/src/datastore_impl.dart' as datastore_impl;
import 'package:http/http.dart';
import 'package:test/test.dart';

import '../../common_e2e.dart';
import '../../datastore/e2e/datastore_test_impl.dart' as datastore_test;
Expand Down Expand Up @@ -137,7 +138,7 @@ class ExpandoPerson extends db.ExpandoModel {

Future sleep(Duration duration) => new Future.delayed(duration);

runTests(db.DatastoreDB store, String namespace) {
void runTests(db.DatastoreDB store, String namespace) {
var partition = store.newPartition(namespace);

void compareModels(List<db.Model> expectedModels, List<db.Model> models,
Expand Down Expand Up @@ -180,11 +181,13 @@ runTests(db.DatastoreDB store, String namespace) {
});
});
} else {
return store.commit(inserts: objects).then(expectAsync((_) {
return store.lookup(keys).then(expectAsync((List<db.Model> models) {
return store.commit(inserts: objects).then(expectAsync1((_) {
return store.lookup(keys).then(expectAsync1((List<db.Model> models) {
compareModels(objects, models);
return store.commit(deletes: keys).then(expectAsync((_) {
return store.lookup(keys).then(expectAsync((List<db.Model> models) {
return store.commit(deletes: keys).then(expectAsync1((_) {
return store
.lookup(keys)
.then(expectAsync1((List<db.Model> models) {
for (var i = 0; i < models.length; i++) {
expect(models[i], isNull);
}
Expand Down Expand Up @@ -330,7 +333,7 @@ runTests(db.DatastoreDB store, String namespace) {
..parentKey = root
..age = 83
..name = 'user83');
return store.commit(inserts: persons).then(expectAsync((_) {
return store.commit(inserts: persons).then(expectAsync1((_) {
// At this point, autoIds are allocated and are reflected in the
// models (as well as parentKey if it was empty).

Expand Down Expand Up @@ -360,13 +363,13 @@ runTests(db.DatastoreDB store, String namespace) {
// because an id doesn't need to be globally unique, only under
// entities with the same parent.

return store.lookup(keys).then(expectAsync((List<Person> models) {
return store.lookup(keys).then(expectAsync1((List<db.Model> models) {
// Since the id/parentKey fields are set after commit and a lookup
// returns new model instances, we can do full model comparison
// here.
compareModels(persons, models);
return store.commit(deletes: keys).then(expectAsync((_) {
return store.lookup(keys).then(expectAsync((List models) {
return store.commit(deletes: keys).then(expectAsync1((_) {
return store.lookup(keys).then(expectAsync1((List models) {
for (var i = 0; i < models.length; i++) {
expect(models[i], isNull);
}
Expand Down Expand Up @@ -677,14 +680,21 @@ Future waitUntilEntitiesHelper(db.DatastoreDB mdb, List<db.Key> keys,
});
}

main() {
var scopes = datastore_impl.DatastoreImpl.SCOPES;
Future main() async {
db.DatastoreDB store;
BaseClient client;

withAuthClient(scopes, (String project, httpClient) {
var datastore = new datastore_impl.DatastoreImpl(httpClient, 's~$project');
var scopes = datastore_impl.DatastoreImpl.SCOPES;
await withAuthClient(scopes, (String project, httpClient) {
var datastore = new datastore_impl.DatastoreImpl(httpClient, project);
return datastore_test.cleanupDB(datastore, null).then((_) {
return runE2EUnittest(
() => runTests(new db.DatastoreDB(datastore), null));
store = new db.DatastoreDB(datastore);
});
});

tearDownAll(() {
client?.close();
});

runTests(store, null);
}
8 changes: 4 additions & 4 deletions test/db/e2e/metamodel_test_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library metamodel_test;

import 'dart:async';

import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'package:gcloud/datastore.dart';
import 'package:gcloud/datastore.dart' show Key, Partition;
Expand Down Expand Up @@ -45,7 +45,7 @@ Future sleep(Duration duration) {
return completer.future;
}

runTests(datastore, db.DatastoreDB store) {
void runTests(datastore, db.DatastoreDB store) {
// Shorten this name, so we don't have to break lines at 80 chars.
final cond = predicate;

Expand Down Expand Up @@ -74,8 +74,8 @@ runTests(datastore, db.DatastoreDB store) {
var futures = <Future>[];
for (var namespace in namespaces) {
if (!(namespace == null ||
namespace == 'FooNamespace' ||
namespace == 'BarNamespace')) {
namespace.name == 'FooNamespace' ||
namespace.name == 'BarNamespace')) {
continue;
}
var partition = store.newPartition(namespace.name);
Expand Down
2 changes: 1 addition & 1 deletion test/db/model_db_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library gcloud.db_impl_test;
import 'dart:async';

import 'package:gcloud/db.dart';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'model_dbs/duplicate_fieldname.dart' as test4;
import 'model_dbs/duplicate_kind.dart' as test1;
Expand Down
2 changes: 1 addition & 1 deletion test/db/properties_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:typed_data';

import 'package:gcloud/db.dart';
import 'package:gcloud/datastore.dart' as datastore;
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

main() {
group('properties', () {
Expand Down
Loading

0 comments on commit fd53065

Please sign in to comment.