1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2025 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef ENV_VAR_WRAPPER_H
#define ENV_VAR_WRAPPER_H

#include <string>

namespace isc {
namespace test {

/// @brief Wrapper for environment variable that restores the
/// variable to its original value.
class EnvVarWrapper {
public:
    /// @brief Constructor
    ///
    /// Fetchs and retains the variable's current value as
    /// the "original" value.
    EnvVarWrapper(const std::string& name);

    /// @brief Destructor.
    ///
    /// Restores the original value (if one), otherwise it
    /// unsets it.
    ~EnvVarWrapper();

    /// @brief Fetches the original value of the env variable.
    std::string getOriginalValue() const;<--- Function 'getOriginalValue()' should return member 'original_value_' by const reference.

    /// @brief Fetches the current value of the env variable.
    std::string getValue() const;

    /// @brief Sets the current value of the env variable.
    ///
    /// @param value new value of the variable. If empty the
    /// variable is unset.
    void setValue(const std::string value = "");

private:
    /// @brief Name of the variable.
    std::string name_;

    /// @brief Value of the env variable at the time the wrapper
    /// was constructed.
    std::string original_value_;
};

}  // end of isc::test namespace
}  // end of isc namespace

#endif // ENV_VAR_WRAPPER_H