1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Test tools for NitRPG.
24 # Used to factorize test treatments.
25 abstract class NitrpgTestHelper
30 var api
= new GithubAPI(get_github_oauth
)
31 api
.enable_cache
= true
36 var mongo
= new MongoClient("mongodb://localhost:27017/")
38 # Load a new test database by with a name
39 private fun load_db
(name
: String): MongoDb do return mongo
.database
(name
)
41 # Load a repo by its name.
42 fun load_repo
(name
: String): Repo do
43 var repo
= api
.load_repo
(name
)
48 # Load a game by its name.
49 fun load_game
(name
: String, db
: MongoDb): Game do
50 var game
= new Game(api
, load_repo
(name
))
51 game
.db_name
= db
.name
55 # Stack of db used for testing.
56 var test_dbs
= new Array[MongoDb]
58 # Gen a test db with a random name (to avoid race conditions).
59 fun gen_test_db
: MongoDb do
60 var testid
= "NIT_TESTING_ID".environ
.to_i
61 var db_name
= "test_nitrpg_{testid}"
62 var db
= load_db
(db_name
)
67 # Should be called after your test.
73 redef fun after_test
do drop_test_db