|
12 | 12 | #include <gtest/gtest.h> |
13 | 13 |
|
14 | 14 | namespace nixC { |
15 | | -class nix_api_store_test : public nix_api_util_context |
| 15 | + |
| 16 | +class nix_api_store_test_base : public nix_api_util_context |
16 | 17 | { |
17 | 18 | public: |
18 | | - nix_api_store_test() |
| 19 | + nix_api_store_test_base() |
19 | 20 | { |
20 | 21 | nix_libstore_init(ctx); |
21 | | - init_local_store(); |
22 | 22 | }; |
23 | 23 |
|
24 | | - ~nix_api_store_test() override |
| 24 | + ~nix_api_store_test_base() override |
25 | 25 | { |
26 | | - nix_store_free(store); |
27 | | - |
28 | | - for (auto & path : std::filesystem::recursive_directory_iterator(nixDir)) { |
29 | | - std::filesystem::permissions(path, std::filesystem::perms::owner_all); |
| 26 | + if (exists(std::filesystem::path{nixDir})) { |
| 27 | + for (auto & path : std::filesystem::recursive_directory_iterator(nixDir)) { |
| 28 | + std::filesystem::permissions(path, std::filesystem::perms::owner_all); |
| 29 | + } |
| 30 | + std::filesystem::remove_all(nixDir); |
30 | 31 | } |
31 | | - std::filesystem::remove_all(nixDir); |
32 | 32 | } |
33 | 33 |
|
34 | | - Store * store; |
35 | 34 | std::string nixDir; |
36 | 35 | std::string nixStoreDir; |
37 | 36 | std::string nixStateDir; |
38 | 37 | std::string nixLogDir; |
39 | 38 |
|
40 | 39 | protected: |
41 | | - void init_local_store() |
| 40 | + Store * open_local_store() |
42 | 41 | { |
43 | 42 | #ifdef _WIN32 |
44 | 43 | // no `mkdtemp` with MinGW |
@@ -66,11 +65,37 @@ protected: |
66 | 65 |
|
67 | 66 | const char ** params[] = {p1, p2, p3, nullptr}; |
68 | 67 |
|
69 | | - store = nix_store_open(ctx, "local", params); |
| 68 | + auto * store = nix_store_open(ctx, "local", params); |
70 | 69 | if (!store) { |
71 | 70 | std::string errMsg = nix_err_msg(nullptr, ctx, nullptr); |
72 | | - ASSERT_NE(store, nullptr) << "Could not open store: " << errMsg; |
| 71 | + EXPECT_NE(store, nullptr) << "Could not open store: " << errMsg; |
| 72 | + assert(store); |
73 | 73 | }; |
| 74 | + return store; |
74 | 75 | } |
75 | 76 | }; |
| 77 | + |
| 78 | +class nix_api_store_test : public nix_api_store_test_base |
| 79 | +{ |
| 80 | +public: |
| 81 | + nix_api_store_test() |
| 82 | + : nix_api_store_test_base{} |
| 83 | + { |
| 84 | + init_local_store(); |
| 85 | + }; |
| 86 | + |
| 87 | + ~nix_api_store_test() override |
| 88 | + { |
| 89 | + nix_store_free(store); |
| 90 | + } |
| 91 | + |
| 92 | + Store * store; |
| 93 | + |
| 94 | +protected: |
| 95 | + void init_local_store() |
| 96 | + { |
| 97 | + store = open_local_store(); |
| 98 | + } |
| 99 | +}; |
| 100 | + |
76 | 101 | } // namespace nixC |
0 commit comments