-
Notifications
You must be signed in to change notification settings - Fork 897
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
Changed get_file method to receive a resource as parameter. #17406
Conversation
fd864d5
to
e008c16
Compare
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.
Additionally, can you create a second test instead of modifying the original? The reason is because the original tests that MiqServer.my_server is used as the default, whereas this tests shows passing a resource.
Alternately, if get_file is not used anywhere else, and you are only ever going to pass a resource, then we can remove the defaulting in this method.
spec/lib/vmdb/config_spec.rb
Outdated
expect(VMDB::Config.get_file).to eq( | ||
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n" | ||
expect(VMDB::Config.get_file(resource)).to eq( | ||
"--- !ruby/object:Config::Options\ntable:\n :http_proxy: !ruby/object:Config::Options\n table:\n :default: !ruby/object:Config::Options\n table:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n modifiable: true\n modifiable: true\n" |
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.
If that is the result of running your test, then something is broken, because we don't want yaml with Config::Options in it
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.
Try .to_hash.to_yaml
instead?
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.
@Fryguy fixed that, please re-review
ca80e4c
to
d5d0f09
Compare
spec/lib/vmdb/config_spec.rb
Outdated
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}}) | ||
|
||
expect(VMDB::Config.get_file).to eq( | ||
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n" | ||
) | ||
end | ||
|
||
it ".get_file for sepecified resource" do |
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.
typo sepecified
-> specified
spec/lib/vmdb/config_spec.rb
Outdated
@@ -2,14 +2,24 @@ | |||
let(:password) { "pa$$w0rd" } | |||
let(:enc_pass) { MiqPassword.encrypt(password) } | |||
|
|||
it ".get_file" do | |||
it ".get_file for current server" do |
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.
Can you reorgnize this like
describe ".get_file" do
it "for current server" do
end
it "for specified resource" do
end
end
spec/lib/vmdb/config_spec.rb
Outdated
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}}) | ||
|
||
expect(VMDB::Config.get_file).to eq( | ||
"---\n:http_proxy:\n :default:\n :host: proxy.example.com\n :user: user\n :password: #{enc_pass}\n :port: 80\n" | ||
) | ||
end | ||
|
||
it ".get_file for sepecified resource" do | ||
resource = FactoryGirl.create(:miq_server) | ||
stub_settings(:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}}) |
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.
stub_settings should probably not be used here because the way it works is by stubbing things globally.
Instead, I think it's better to maybe create some changes, save them, then see if they come back? This should be done in both tests.
Maybe something like...
resource = FactoryGirl.create(:miq_server)
Vmdb::Settings.save!(resource, {:http_proxy => {:default => {:host => "proxy.example.com", :user => "user", :password => password, :port => 80}}})
resource.reload
yaml = VMDB::Config.get_file(resource)
yaml = YAML.load(yaml)
expect(yaml.fetch_path(:http_proxy, :default, :host)).to eq "proxy.example.com"
expect(yaml.fetch_path(:http_proxy, :default, :user)).to eq "user"
expect(yaml.fetch_path(:http_proxy, :default, :port)).to eq 80
expect(yaml.fetch_path(:http_proxy, :default, :password)).to be_encrypted
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.
@h-kataria I edited the snippet above to be more proper
a96e47f
to
f6331b6
Compare
@Fryguy made requested changes |
lib/vmdb/config.rb
Outdated
def self.get_file | ||
Vmdb::Settings.encrypt_passwords!(::Settings.to_hash).to_yaml | ||
def self.get_file(resource = MiqServer.my_server) | ||
Vmdb::Settings.encrypt_passwords!(resource.settings_for_resource).to_hash.to_yaml |
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.
@h-kataria You have to put the .to_hash
inside of the encrypt_passwords, otherwise it modifies the passwords of the resource's settings).
Vmdb::Settings.encrypt_passwords!(resource.settings_for_resource.to_hash).to_yaml
@h-kataria I think you missed my changes as requested in #17406 (review) . The code is still using stub_settings which is not testing this properly. |
f6331b6
to
5e943a4
Compare
@Fryguy updated once again! |
0eda305
to
7972878
Compare
|
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 you want shared examples or a method where the expectations can live instead since the expectations shouldn't be in the after
block. Then you can also expect the hash to have_attributes
so that it is a single expectation.
spec/lib/vmdb/config_spec.rb
Outdated
|
||
after do | ||
yaml = YAML.load(@yaml) | ||
expect(yaml.fetch_path(:http_proxy, :default, :host)).to eq "proxy.example.com" |
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.
Why are the expectations in the after
block? Shouldn't these be in the test or a shared example instead?
7972878
to
44c182d
Compare
This change returns settings for passed in resource region/zone/server. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1536524
44c182d
to
91b7996
Compare
Checked commit h-kataria@91b7996 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 spec/lib/vmdb/config_spec.rb
|
This change returns settings for passed in resource region/zone/server.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1536524
@Fryguy @gtanzillo please review.