Apache Mesos
environment.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 
17 #ifndef __TESTS_ENVIRONMENT_HPP__
18 #define __TESTS_ENVIRONMENT_HPP__
19 
20 #include <list>
21 #include <string>
22 
23 #include <gtest/gtest.h>
24 
25 #include <stout/try.hpp>
26 
28 
29 #include "tests/flags.hpp"
30 
31 namespace mesos {
32 namespace internal {
33 namespace tests {
34 
35 // Used to set up and manage the test environment.
37 public:
38  Environment(const Flags& flags);
39 
40  void SetUp() override;
41 
42  void TearDown() override;
43 
44  // Helper to create a temporary directory based on the current test
45  // case name and test name (derived from TestInfo via
46  // ::testing::UnitTest::GetInstance()->current_test_info()). Note
47  // that the directory will automagically get removed when the
48  // test finishes.
50 
51 private:
52  // Used to clean up temporary directories after tests finish.
53  class TemporaryDirectoryEventListener
54  : public ::testing::EmptyTestEventListener
55  {
56  public:
58 
59  protected:
60  void OnTestEnd(const ::testing::TestInfo&) override;
61 
62  // Temporary directories that we created and need to remove.
63  std::list<std::string> directories;
64  };
65 
66  const Flags flags;
67 
68  TemporaryDirectoryEventListener* temporaryDirectoryEventListener;
69 };
70 
71 
72 // Global environment instance.
73 extern Environment* environment;
74 
75 } // namespace tests {
76 } // namespace internal {
77 } // namespace mesos {
78 
79 #endif // __TESTS_ENVIRONMENT_HPP__
Definition: check.hpp:33
Environment * environment
Definition: flags.hpp:34
Definition: agent.hpp:25
Definition: environment.hpp:94
Definition: environment.hpp:36
Definition: attributes.hpp:24
Definition: parse.hpp:33