New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for deleting hash tables #1
base: master
Are you sure you want to change the base?
Conversation
@@ -60,6 +60,25 @@ def stub_create(scope, content, cse) | |||
provider.class.expects(:lgpo).once.with(*args).returns(nil) | |||
expect(File).to receive(:delete).once.with(out_polfile).and_return(nil) | |||
end | |||
def hash_delete(scope, content, cse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this stub_hash_delete
lib/puppet/provider/gpo/lgpo.rb
Outdated
gpos.split("\n\n").reject { |l| l.start_with? ';' }.each do |g| | ||
split_g = g.split("\n") | ||
unless split_g[1] == key | ||
File.open(out_file_path, 'a') do |out_file| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather open the file outside the loop to avoid opening/closing for every line.
lib/puppet/provider/gpo/lgpo.rb
Outdated
@@ -138,4 +140,18 @@ def set_value(val) | |||
lgpo(*lgpo_args) | |||
File.delete(out_polfile_path) | |||
end | |||
|
|||
def remove_key(key, scope) | |||
pol_file = "C:\\Windows\\System32\\GroupPolicy\\#{scope.capitalize}\\Registry.pol" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return if pol_file doesn't exist to avoid lgpo
from crashing
@@ -60,6 +60,25 @@ def stub_create(scope, content, cse) | |||
provider.class.expects(:lgpo).once.with(*args).returns(nil) | |||
expect(File).to receive(:delete).once.with(out_polfile).and_return(nil) | |||
end | |||
def hash_delete(scope, content, cse) | |||
file = StringIO.new | |||
allow(File).to receive(:open).once.with(out_file, 'w').and_yield(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect
would be better here.
allow(file).to receive(:write).with(content) | ||
|
||
stub_lgpo_pol(scope, true) | ||
allow(file).to receive(:open).at_least(:once).with(out_file, 'a').and_yield(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is expect(File)
, not expect(file)
since we're stubbing the File
module, not the file
object.
1 similar comment
daaf57e
to
5561f99
Compare
1 similar comment
1 similar comment
lib/puppet/provider/gpo/lgpo.rb
Outdated
@@ -5,7 +5,7 @@ | |||
commands :lgpo => 'lgpo.exe' | |||
|
|||
def exists? | |||
@property_hash[:ensure] == :present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think exists?
should be kept strictly for checking ensure => present
. We should use another method to checking if the resource is deleted. See for example what was done with in_position?
in https://github.com/hercules-team/augeasproviders_postgresql/blob/master/lib/puppet/type/pg_hba.rb#L21
ea7634c
to
7ade80b
Compare
@rico89 do you want this to be merged? |
No description provided.