-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display value differences to actual environment (#158)
* Add `diffy` to create nice html diffs of values #151 * Display value differences to actual env #151 If a key is displayed from a different environment than the node is actually in _and_ a file with the same path exists in the original environment _and_ the value in that file differs from the one displayed, show the differences. Uses the `diffy` gem to highlight the differences. * Fix rubocop issues.
- Loading branch information
Showing
11 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% split_diff = Diffy::SplitDiff.new(file.value_from_original_environment(key: @key).value, value.value, format: :html) %> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th><%= @node.environment.name %></th> | ||
<th><%= @environment.name %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><%= raw(split_diff.left) %></td> | ||
<td><%= raw(split_diff.right) %></td> | ||
</tr> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% if file.has_differing_value_in_original_environment?(@key) %> | ||
<ul class="nav nav-tabs mb-2" role="tablist"> | ||
<li class="nav-item" role="presentation"> | ||
<button id="<%= "tab-value-#{dom_id(file)}" %>" class="nav-link active" data-target="<%= "#value-#{dom_id(file)}" %>" data-toggle="tab" type="button" role="tab" aria-controls="<%= "value-#{dom_id(file)}" %>" aria-selected="true">Value</button> | ||
</li> | ||
<li class="nav-item" role="presentation"> | ||
<button id="<%= "tab-diff-#{dom_id(file)}" %>" class="nav-link" data-target="<%= "#diff-#{dom_id(file)}" %>" data-toggle="tab" type="button" role="tab" aria-controls="<%= "diff-#{dom_id(file)}" %>" aria-selected="false">Diff</button> | ||
</li> | ||
</ul> | ||
|
||
<div class="tab-content"> | ||
<div id="<%= "value-#{dom_id(file)}" %>" class="tab-pane fade show active" role="tabpanel" aria-labelledby="<%= "tab-value-#{dom_id(file)}" %>"> | ||
<%= render "form", file: file, value: value %> | ||
</div> | ||
|
||
<div id="<%= "diff-#{dom_id(file)}" %>" class="tab-pane fade" role="tabpanel" aria-labelledby="<%= "tab-diff-#{dom_id(file)}" %>"> | ||
<%= render "diff", file: file, value: value %> | ||
</div> | ||
</div> | ||
<% else %> | ||
<%= render "form", file: file, value: value %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test/fixtures/files/puppet/environments/development/data/role/hdm_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
--- | ||
foobar::firstrun::linux_classes: | ||
hostname: hostname-role | ||
hdm::integer: 1 | ||
hdm::float: 2.3 |
2 changes: 2 additions & 0 deletions
2
test/fixtures/files/puppet/environments/globs/data/role/hdm_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
--- | ||
foobar::firstrun::linux_classes: | ||
hostname: hostname-role | ||
hdm::integer: 1 | ||
hdm::float: 4.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'test_helper' | ||
|
||
class DataFileTest < ActiveSupport::TestCase | ||
setup do | ||
@original_environment = Environment.new(name: "development") | ||
@node = Node.new(environment: @original_environment, hostname: "test.host") | ||
@globs_environment = Environment.new(name: "globs") | ||
@path = "role/hdm_test.yaml" | ||
end | ||
|
||
test "#has_differing_value_in_original_environment? returns false if environments are the same" do | ||
hierarchy = Hierarchy.find(@original_environment, "Eyaml hierarchy") | ||
data_file = DataFile.new(hierarchy:, node: @node, path: @path) | ||
key = Key.new(environment: @original_environment, name: "hdm::integer") | ||
|
||
assert_not data_file.has_differing_value_in_original_environment?(key) | ||
end | ||
|
||
test "#has_differing_value_in_original_environment? returns false if original environment has no file with the same path" do | ||
hierarchy = Hierarchy.find(@globs_environment, "Common") | ||
data_file = DataFile.new(hierarchy:, node: @node, path: "common/foobar.yaml") | ||
key = Key.new(environment: @globs_environment, name: "hdm::integer") | ||
|
||
assert_not data_file.has_differing_value_in_original_environment?(key) | ||
end | ||
|
||
test "#has_differing_value_in_original_environment? returns false if original environment's value is the same" do | ||
hierarchy = Hierarchy.find(@globs_environment, "Eyaml hierarchy") | ||
data_file = DataFile.new(hierarchy:, node: @node, path: @path) | ||
key = Key.new(environment: @globs_environment, name: "hdm::integer") | ||
|
||
assert_not data_file.has_differing_value_in_original_environment?(key) | ||
end | ||
|
||
test "#has_differing_value_in_original_environment? returns true if original environment's value is different" do | ||
hierarchy = Hierarchy.find(@globs_environment, "Eyaml hierarchy") | ||
data_file = DataFile.new(hierarchy:, node: @node, path: @path) | ||
key = Key.new(environment: @globs_environment, name: "hdm::float") | ||
|
||
assert data_file.has_differing_value_in_original_environment?(key) | ||
end | ||
|
||
test "#value_for returns matching value from given environment" do | ||
hierarchy = Hierarchy.find(@globs_environment, "Eyaml hierarchy") | ||
data_file = DataFile.new(hierarchy:, node: @node, path: @path) | ||
key = Key.new(environment: @globs_environment, name: "hdm::float") | ||
|
||
assert_equal "4.5", data_file.value_for(key:).value | ||
end | ||
|
||
test "#value_from_original_environment returns matching value from the node's original environment" do | ||
hierarchy = Hierarchy.find(@globs_environment, "Eyaml hierarchy") | ||
data_file = DataFile.new(hierarchy:, node: @node, path: @path) | ||
key = Key.new(environment: @globs_environment, name: "hdm::float") | ||
|
||
assert_equal "2.3", data_file.value_from_original_environment(key:).value | ||
end | ||
end |