diff options
author | Victor Toso <me@victortoso.com> | 2015-08-28 16:50:52 +0200 |
---|---|---|
committer | Victor Toso <me@victortoso.com> | 2015-08-29 17:36:45 +0200 |
commit | ef77cb7855472c5630a65810e0a243fd5472dae5 (patch) | |
tree | 6aa2c42c2bfea5dff9226ef605044c98b2acb1c4 /tests | |
parent | 3298de74b0d69655cad2dc51f67aa5d26a9caed8 (diff) |
tests: new function to reset test environment
With commit b4cf71a18de08825006ed7e7c3b8545e736b1839 we are using
temporary database for thetvdb tests. The goal of this patch is a way to
reset test environment by removing the database and re-loading the
plugin. If a test need a clean environment, it can call
test_reset_thetvdb ().
https://bugzilla.gnome.org/show_bug.cgi?id=748422
Diffstat (limited to 'tests')
-rw-r--r-- | tests/thetvdb/test_thetvdb_utils.c | 28 | ||||
-rw-r--r-- | tests/thetvdb/test_thetvdb_utils.h | 1 |
2 files changed, 23 insertions, 6 deletions
diff --git a/tests/thetvdb/test_thetvdb_utils.c b/tests/thetvdb/test_thetvdb_utils.c index 9131a74..db8f45f 100644 --- a/tests/thetvdb/test_thetvdb_utils.c +++ b/tests/thetvdb/test_thetvdb_utils.c @@ -34,11 +34,14 @@ test_setup_thetvdb (void) GrlRegistry *registry; GError *error = NULL; - tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL); - tmp_dir = g_mkdtemp (tmp_dir); - g_assert_nonnull (tmp_dir); + if (tmp_dir == NULL) { + /* Only create tmp dir and set the XDG_DATA_HOME once */ + tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL); + tmp_dir = g_mkdtemp (tmp_dir); + g_assert_nonnull (tmp_dir); - g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE); + g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE); + } config = grl_config_new (THETVDB_ID, NULL); grl_config_set_api_key (config, "THETVDB_TEST_MOCK_API_KEY"); @@ -61,8 +64,8 @@ GrlSource* test_get_source (void) return source; } -void -test_shutdown_thetvdb (void) +static void +test_unload (void) { GrlRegistry *registry; GError *error = NULL; @@ -76,5 +79,18 @@ test_shutdown_thetvdb (void) db_path = g_build_filename (tmp_dir, "grilo-plugins", "grl-thetvdb.db", NULL); g_remove (db_path); g_free (db_path); +} + +void +test_reset_thetvdb (void) +{ + test_unload (); + test_setup_thetvdb (); +} + +void +test_shutdown_thetvdb (void) +{ + test_unload (); g_clear_pointer (&tmp_dir, g_free); } diff --git a/tests/thetvdb/test_thetvdb_utils.h b/tests/thetvdb/test_thetvdb_utils.h index 746bec2..77b0d85 100644 --- a/tests/thetvdb/test_thetvdb_utils.h +++ b/tests/thetvdb/test_thetvdb_utils.h @@ -30,6 +30,7 @@ void test_setup_thetvdb (void); GrlSource* test_get_source (void); +void test_reset_thetvdb (void); void test_shutdown_thetvdb (void); #endif /* _GRL_THETVDB_TEST_UTILS_H_ */ |