Skip to content
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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

rico89
Copy link
Contributor

@rico89 rico89 commented Oct 26, 2017

No description provided.

@@ -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)
Copy link
Contributor

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

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|
Copy link
Contributor

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.

@@ -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"
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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.

@coveralls
Copy link

coveralls commented Oct 26, 2017

Coverage Status

Coverage decreased (-0.3%) to 96.296% when pulling a95390d on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 96.296% when pulling a95390d on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

@rico89 rico89 force-pushed the feature/support_for_hash_values branch from daaf57e to 5561f99 Compare October 27, 2017 17:06
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 96.761% when pulling 5561f99 on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

1 similar comment
@coveralls
Copy link

coveralls commented Oct 27, 2017

Coverage Status

Coverage increased (+0.2%) to 96.761% when pulling 5561f99 on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 96.761% when pulling 4109c27 on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

1 similar comment
@coveralls
Copy link

coveralls commented Oct 27, 2017

Coverage Status

Coverage increased (+0.2%) to 96.761% when pulling 4109c27 on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

@coveralls
Copy link

coveralls commented Oct 27, 2017

Coverage Status

Coverage decreased (-31.8%) to 64.773% when pulling 71cbee8 on rico89:feature/support_for_hash_values into 17c8aa9 on camptocamp:master.

@@ -5,7 +5,7 @@
commands :lgpo => 'lgpo.exe'

def exists?
@property_hash[:ensure] == :present
Copy link
Contributor

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

@raphink raphink force-pushed the feature/support_for_hash_values branch from ea7634c to 7ade80b Compare May 4, 2018 08:33
@raphink
Copy link
Contributor

raphink commented May 16, 2018

@rico89 do you want this to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants