-
Notifications
You must be signed in to change notification settings - Fork 55
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
Extract variable Tower data from tests #93
Extract variable Tower data from tests #93
Conversation
This pull request is not mergeable. Please rebase and repush. |
a18a58b
to
86e4a8d
Compare
#91 got merged. Rebased to resolve conflicts: Removed data for Tower v2 tests. |
@Glutexo - Can you address the conflicts please so we can get this in. |
86e4a8d
to
0f817a0
Compare
Rebased, resolved. VCRs were re-recorded and because of that ids and counts in spec changed. If this gets merged, doing such and update would be easier for anybody. (@jameswnl in this case) |
@jameswnl, can this one please get reviewed so we can slowly get to the point when Stepan's PRs are merged? 😉 |
@@ -11,6 +11,10 @@ | |||
:verify_ssl => false,).tap { |provider| provider.authentications << auth } | |||
end | |||
|
|||
let(:tower_data) { Spec::Support::TowerDataHelper.tower_data } |
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.
We should be able to do a YAML.load_file(TOWER_DATA_FILE)
where the TOWER_DATA_FILE point to the yaml file.
This way we can eliminate that spec/support/tower_data_helper.rb
file which will make @jrafanie 😄
Can either define TOWER_DATA_FILE in spec_helper.rb
or even load it up there. But may be other spec experts can help here
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.
Eliminate the need for spec/support/tower_data_helper.rb
This is great! |
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.
@@ -14,27 +14,38 @@ | |||
end | |||
let(:manager_class) { manager_class } | |||
|
|||
let(:tower_data) { Spec::Support::TowerDataHelper.tower_data } | |||
|
|||
let(:targeted_refresh_id) { tower_data['items']['targeted_refresh']['id'] } |
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.
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 PR extracts the actual data used in the specs. I tried to map it as well as possible to the data created by the Rake task, but still they are more or less independent. If I recall correctly, the ids used here were different from the hello_repo and another_repo, so I created a separate entity for them in the YAML.
This can be resolved when merging with the other PR by using hello_repo instead and changing the data in this spec. This will however require re-recording of the VCRs, which is what I didn’t want to do here. It’s the inconsistency between specs I was talking about with you earlier. :(
let(:targeted_refresh_id) { tower_data['items']['targeted_refresh']['id'] } | ||
let(:targeted_refresh_last_updated) { tower_data['items']['targeted_refresh']['last_updated'].utc } | ||
let(:targeted_refresh_playbooks) { tower_data['items']['targeted_refresh']['playbooks'] } | ||
let(:nonexistent_repo_id) { tower_data['items']['nonexistent_repo']['id'] } |
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.
The same case as the previous comment. This PR is the first one mentioning a nonexistent_repo
. Is this the same as failed_repo
?
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.
As the name suggests, a nonexistent_repo is an invalid id. It was used to ensure that the refresher does not even try to load this repo when updating the targeted_refresh one. When merging with the Rake task changes, it would be necessary to create such id. That can be achieved by creating some repo and then deleting it, making sure the id is captured and it neither belongs to any existing project in Tower, nor going to be reused unexpectedly in the future.
ab0f83f
to
d08a72c
Compare
508c13a
to
7f4bdfe
Compare
This pull request is not mergeable. Please rebase and repush. |
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.
Hey, spotted some issues.
lib/tasks_private/spec_helper.rake
Outdated
@@ -434,6 +434,20 @@ class PopulateTower | |||
last_update = wait_for_project_update(jobless_project) | |||
@conn.delete(last_update['url']) | |||
|
|||
# Create and remove project - record an collect an ID of missing entity | |||
uri = '/api/v1/projects/' | |||
uri = '/api/v1/projects/' |
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.
Dupy dupy dupy dup dup dup.
} | ||
nonexistent_project = create_obj(uri, data) | ||
@tower_data[:items][data[:name]] = { :id => nonexistent_project['id'] } | ||
del_obj(uri, data[:name]) |
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.
Just remember, that del_obj
does some safety sleep. This might be necessary when recreating object that are already present in Tower. It is however useless here, when we just want to delete an object without any intention of creating its replacement.
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.
What's the issue with this? The rake job is run only in case of regenerating VCRs. It doesn't slow down the test run or anything...
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.
You just wait a long time for nothing before going to the next step – populating item counts.
@@ -0,0 +1,3 @@ | |||
shared_context "uses tower_data.yml" do | |||
let(:tower_data) { YAML.load_file(ManageIQ::Providers::AnsibleTower::Engine.root.join("spec/support/tower_data.yml")) } |
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 still don’t like this. Can’t we turn the path into a constant then use it when writing the file by the Rake task?
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 would be a global constant better than a shared context? The context defines the test scope. Global constant would require the file to be loaded for any spec execution within this repo. A shared context allows lazy loading of the file - only if the spec requires it. In other words, this way it is not required to have the YAML present and loaded at all when you're running a spec which doesn't include the context.
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.
There is nothing bad with the shared context. I’d just extract the file path to the global content. That is virtually no overhead (as compared to loading and parsing the whole file) for that and then in can be used even outside the specs for writing the file.
c2466bf
to
02bff00
Compare
This pull request is not mergeable. Please rebase and repush. |
Some properties of the records expected in a Tower instance are not entered directly by the user: ids, timestamps, external data… These are subject to change with every population and cassette re-recording. In such case manual update of expectations in specs was required. Collection of this data to a single resource file allows to change only this single file instead of hunting the right magic literals in the specs examples.
02bff00
to
38f0f9a
Compare
Some comments on commits Glutexo/manageiq-providers-ansible_tower@7043e91~...38f0f9a lib/tasks_private/spec_helper.rake
|
Checked commits Glutexo/manageiq-providers-ansible_tower@7043e91~...38f0f9a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@miq-bot remove_label unmergeable |
@miq-bot add_label enhancement, test |
Some properties of the records expected in a Tower instance are not
entered directly by the user: ids, timestamps, external data… These
are subject to change with every population and cassette re-recording.
In such case manual update of expectations in specs was
required. Collection of this data to a single resource file allows to
change only this single file instead of hunting the right magic
literals in the specs examples.
Extracted from #79 for easier review. This part contains only changes to the specs. Goes along with #92.
@miq-bot add_reviewer @jameswnl