Skip to content

Commit

Permalink
Update some unit tests
Browse files Browse the repository at this point in the history
Based on suggestions from code review

Co-Authored-By: José Iván López González <jlopez@suse.com>
  • Loading branch information
dgdavid and joseivanlopez committed Apr 4, 2019
1 parent fc9f730 commit cdfced4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
7 changes: 5 additions & 2 deletions test/y2storage/proposal/settings_generator/legacy_test.rb
Expand Up @@ -47,12 +47,15 @@
next_settings = subject.next_settings

expect(next_settings).to be_a(Y2Storage::ProposalSettings)
expect(next_settings.object_id).to_not eq(settings.object_id)
expect(next_settings).to_not equal(settings)
end

context "when called for first time" do
it "returns the same values as the initial settings" do
expect(subject.next_settings).to eq(settings)
settings_values = Marshal.dump(settings)
next_settings_values = Marshal.dump(subject.next_settings)

expect(next_settings_values).to eq(settings_values)
end
end

Expand Down
7 changes: 5 additions & 2 deletions test/y2storage/proposal/settings_generator/ng_test.rb
Expand Up @@ -75,12 +75,15 @@ def volume_from_settings(settings, mount_point)
next_settings = subject.next_settings

expect(next_settings).to be_a(Y2Storage::ProposalSettings)
expect(next_settings.object_id).to_not eq(settings.object_id)
expect(next_settings).to_not equal(settings)
end

context "when called for first time" do
it "returns the same values as the initial settings" do
expect(subject.next_settings).to eq(settings)
settings_values = Marshal.dump(settings)
next_settings_values = Marshal.dump(subject.next_settings)

expect(next_settings_values).to eq(settings_values)
end

it "creates an empty SettingsAdjustment object" do
Expand Down
31 changes: 12 additions & 19 deletions test/y2storage/proposal_settings_test.rb
Expand Up @@ -61,29 +61,22 @@ def stub_partitioning_features(features = {})
stub_partitioning_features(partitioning)
end

it "returns a deep copy of settings" do
copy = settings.deep_copy

# Let's simply check two nested levels: it's expected to find the same amount of objects with
# a different identity. In other words, the objects must be equal but must be different instances.
it "creates a new object" do
expect(settings.deep_copy).to_not equal(settings)
end

copy_volumes = copy.volumes
copy_volumes_ids = copy_volumes.map(&:object_id)
copy_volumes_desired_sizes = copy_volumes.map(&:desired_size)
copy_volumes_desired_sizes_ids = copy_volumes_desired_sizes.map(&:object_id)
it "creates an object with the same values" do
settings_values = Marshal.dump(settings)
settings_deep_copy_values = Marshal.dump(settings.deep_copy)

settings_volumes = settings.volumes
settings_volumes_ids = settings_volumes.map(&:object_id)
settings_volumes_desired_sizes = settings_volumes.map(&:desired_size)
settings_volumes_desired_sizes_ids = settings_volumes_desired_sizes.map(&:object_id)
expect(settings_deep_copy_values).to eq(settings_values)
end

expect(copy_volumes.map(&:mount_point)).to eq(settings_volumes.map(&:mount_point))
expect(copy_volumes.map(&:fs_type)).to eq(settings_volumes.map(&:fs_type))
expect(copy_volumes_desired_sizes).to eq(settings_volumes_desired_sizes)
it "creates an object with different references" do
ids = settings.volumes.map(&:object_id).sort
new_ids = settings.deep_copy.volumes.map(&:object_id).sort

expect(copy.object_id).to_not eq(settings.object_id)
expect(copy_volumes_ids).to_not eq(settings_volumes_ids)
expect(copy_volumes_desired_sizes_ids).to_not eq(settings_volumes_desired_sizes_ids)
expect(new_ids).to_not eq(ids)
end
end

Expand Down

0 comments on commit cdfced4

Please sign in to comment.