Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

feat: add new support for testing with environment variables #180

Merged
merged 3 commits into from
Feb 21, 2020

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Feb 18, 2020

EnvironmentRestorer is an RAII object that will, upon destruction,
restore the previous state of environment variables that it modified.
For example:

  // ${VAR1} and ${VAR2} have some initial state.
  {
    EnvironmentRestorer env;
    env.SetEnv("VAR1", "value");
    env.UnsetEnv("VAR2");
    // ${VAR1} now holds "value1" and ${VAR2} is unset.
  }
  // The initial state of ${VAR1} and ${VAR2} have been restored.

[Note: The idea is for this to replace EnvironmentVariableRestore.]


This change is Reviewable

`EnvironmentRestorer` is an RAII object that will, upon destruction,
restore the previous state of environment variables that it modified.
For example:
```
  // ${VAR} has some initial state.
  {
    EnvironmentRestorer env;
    env.SetEnv("VAR", "value");
    // ${VAR} now holds "value".
  }
  // The initial state of ${VAR} has been restored.
```
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 18, 2020
@codecov
Copy link

codecov bot commented Feb 18, 2020

Codecov Report

Merging #180 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   96.23%   96.27%   +0.03%     
==========================================
  Files          97       99       +2     
  Lines        4411     4429      +18     
==========================================
+ Hits         4245     4264      +19     
+ Misses        166      165       -1
Impacted Files Coverage Δ
google/cloud/testing_util/scoped_environment.cc 100% <100%> (ø)
...ogle/cloud/testing_util/scoped_environment_test.cc 100% <100%> (ø)
google/cloud/connection_options.h 100% <0%> (ø) ⬆️
google/cloud/log.h 86.84% <0%> (ø) ⬆️
google/cloud/connection_options.cc 100% <0%> (ø) ⬆️
google/cloud/connection_options_test.cc 100% <0%> (ø) ⬆️
google/cloud/optional.h 97.61% <0%> (+0.05%) ⬆️
google/cloud/log_test.cc 98.3% <0%> (+0.13%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1a0fa6...4d721d8. Read the comment docs.

@devbww devbww marked this pull request as ready for review February 18, 2020 23:06
@devbww devbww requested a review from devjgm February 18, 2020 23:06
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm_strong: Thanks!

Reviewed 6 of 6 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @devjgm)

google/cloud/testing_util/environment_restorer.h Outdated Show resolved Hide resolved
google/cloud/testing_util/environment_restorer.h Outdated Show resolved Hide resolved
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @devbww)

@devbww devbww merged commit 3dc8e30 into googleapis:master Feb 21, 2020
@devbww devbww deleted the environment-restorer branch February 21, 2020 15:08
coryan pushed a commit to coryan/google-cloud-cpp that referenced this pull request Apr 24, 2020
…pis/google-cloud-cpp-common#180)

`ScopedEnvironment` is an RAII object that will, upon destruction,
restore the previous state of the environment variable it modified.
For example:
```
  // ${VAR} has some initial state.
  {
    ScopedEnvironment env("VAR", "value");
    // ${VAR} now holds "value".
  }
  // The initial state of ${VAR} has been restored.
```
coryan pushed a commit to coryan/google-cloud-cpp that referenced this pull request Apr 24, 2020
…pis/google-cloud-cpp-common#180)

`ScopedEnvironment` is an RAII object that will, upon destruction,
restore the previous state of the environment variable it modified.
For example:
```
  // ${VAR} has some initial state.
  {
    ScopedEnvironment env("VAR", "value");
    // ${VAR} now holds "value".
  }
  // The initial state of ${VAR} has been restored.
```
coryan pushed a commit to coryan/google-cloud-cpp that referenced this pull request Apr 24, 2020
…pis/google-cloud-cpp-common#180)

`ScopedEnvironment` is an RAII object that will, upon destruction,
restore the previous state of the environment variable it modified.
For example:
```
  // ${VAR} has some initial state.
  {
    ScopedEnvironment env("VAR", "value");
    // ${VAR} now holds "value".
  }
  // The initial state of ${VAR} has been restored.
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants