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.
23 # Used to factorize test treatments.
24 abstract class NitrpgTestHelper
28 var api
= new GithubAPI(get_github_oauth
)
29 api
.enable_cache
= true
34 var mongo
= new MongoClient("mongodb://mongo:27017/")
36 # Load a new test database by with a name
37 private fun load_db
(name
: String): MongoDb do return mongo
.database
(name
)
39 # Load a repo by its name.
40 fun load_repo
(name
: String): Repo do
41 var repo
= api
.load_repo
(name
)
46 # Load a game by its name.
47 fun load_game
(name
: String, db
: MongoDb): Game do
48 var game
= new Game(api
, load_repo
(name
))
49 game
.db_name
= db
.name
53 # Stack of db used for testing.
54 var test_dbs
= new Array[MongoDb]
56 # Gen a test db with a random name (to avoid race conditions).
57 fun gen_test_db
: MongoDb do
58 var testid
= "NIT_TESTING_ID".environ
.to_i
59 var db_name
= "test_nitrpg_{testid}"
60 var db
= load_db
(db_name
)
65 # Should be called after your test.
71 # Drop the databse after each test
72 fun after_test
is after
do drop_test_db