Skip to content

Commit 110dbc4

Browse files
committed
(PUP-11348) Move Puppet::Util.withenv tests
Move tests for unicode key & value and nil values from run_mode_spec.rb to util_spec.rb. We're already testing that env variables passed to `withenv` are not set when the method returns.
1 parent 5a43845 commit 110dbc4

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

spec/unit/util/run_mode_spec.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,6 @@
171171
end
172172
end
173173
end
174-
175-
describe "#without_env internal helper with UTF8 characters" do
176-
let(:varname) { "\u16A0\u16C7\u16BB\u16EB\u16D2\u16E6\u16A6\u16EB\u16A0\u16B1\u16A9\u16A0\u16A2\u16B1\u16EB\u16A0\u16C1\u16B1\u16AA\u16EB\u16B7\u16D6\u16BB\u16B9\u16E6\u16DA\u16B3\u16A2\u16D7" }
177-
let(:rune_utf8) { "\u16A0\u16C7\u16BB\u16EB\u16D2\u16E6\u16A6\u16EB\u16A0\u16B1\u16A9\u16A0\u16A2\u16B1\u16EB\u16A0\u16C1\u16B1\u16AA\u16EB\u16B7\u16D6\u16BB\u16B9\u16E6\u16DA\u16B3\u16A2\u16D7" }
178-
179-
before do
180-
Puppet::Util::Windows::Process.set_environment_variable(varname, rune_utf8)
181-
end
182-
183-
it "removes environment variables within the block with UTF8 name" do
184-
without_env(varname) do
185-
expect(ENV[varname]).to be(nil)
186-
end
187-
end
188-
189-
it "restores UTF8 characters in environment variable values" do
190-
without_env(varname) do
191-
Puppet::Util::Windows::Process.set_environment_variable(varname, 'bad value')
192-
end
193-
194-
envhash = Puppet::Util::Windows::Process.get_environment_strings
195-
expect(envhash[varname]).to eq(rune_utf8)
196-
end
197-
end
198174
end
199175

200176
def as_root
@@ -206,12 +182,4 @@ def as_non_root
206182
allow(Puppet.features).to receive(:root?).and_return(false)
207183
yield
208184
end
209-
210-
def without_env(name, &block)
211-
saved = Puppet::Util.get_env(name)
212-
Puppet::Util.set_env(name, nil)
213-
yield
214-
ensure
215-
Puppet::Util.set_env(name, saved)
216-
end
217185
end

spec/unit/util_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ def get_mode(file)
6565
end
6666
expect(ENV["FOO"]).to eq(nil)
6767
end
68+
it "accepts a unicode key" do
69+
key = "\u16A0\u16C7\u16BB\u16EB\u16D2\u16E6\u16A6\u16EB\u16A0\u16B1\u16A9\u16A0\u16A2\u16B1\u16EB\u16A0\u16C1\u16B1\u16AA\u16EB\u16B7\u16D6\u16BB\u16B9\u16E6\u16DA\u16B3\u16A2\u16D7"
70+
71+
Puppet::Util.withenv(key => "bar") do
72+
expect(ENV[key]).to eq("bar")
73+
end
74+
end
75+
76+
it "accepts a unicode value" do
77+
value = "\u16A0\u16C7\u16BB\u16EB\u16D2\u16E6\u16A6\u16EB\u16A0\u16B1\u16A9\u16A0\u16A2\u16B1\u16EB\u16A0\u16C1\u16B1\u16AA\u16EB\u16B7\u16D6\u16BB\u16B9\u16E6\u16DA\u16B3\u16A2\u16D7"
78+
79+
Puppet::Util.withenv("runes" => value) do
80+
expect(ENV["runes"]).to eq(value)
81+
end
82+
end
83+
84+
it "accepts a nil value" do
85+
Puppet::Util.withenv("foo" => nil) do
86+
expect(ENV["foo"]).to eq(nil)
87+
end
88+
end
89+
6890
end
6991

7092
describe "#withenv on POSIX", :unless => Puppet::Util::Platform.windows? do

0 commit comments

Comments
 (0)