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

DM-13608: Do not rely on locale when using diff #80

Merged
merged 2 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions scripts/newinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,24 @@ n8l::up2date_check() {
set +e

local amidiff
amidiff=$($CURL "$CURL_OPTS" -L "$NEWINSTALL_URL" | diff --brief - "$0")
diff --brief "$0" <($CURL "$CURL_OPTS" -L "$NEWINSTALL_URL") > /dev/null
amidiff=$?

if [[ $amidiff == *differ ]]; then
if [[ $amidiff = 1 ]] ; then
n8l::print_error "$(cat <<-EOF
!!! This script differs from the official version on the distribution
server. If this is not intentional, get the current version from here:
${NEWINSTALL_URL}
EOF
)"
else
if [[ $amidiff != 0 ]] ; then
n8l::print_error "$(cat <<-EOF
!!! There is an error in comparing the official version with the local
copy of the script.
EOF
)"
fi
fi

set -e
Expand Down
22 changes: 19 additions & 3 deletions spec/unit/n8l/up2date_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

context 'script matches master' do
it 'prints nothing' do
stubbed_env.stub_command('diff').outputs('notta')
stubbed_env.stub_command('diff').returns_exitstatus(0)

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
Expand All @@ -24,7 +24,7 @@

context 'script out of sync with master' do
it 'prints a non-fatal warning' do
stubbed_env.stub_command('diff').outputs('differ')
stubbed_env.stub_command('diff').returns_exitstatus(1)

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
Expand All @@ -36,5 +36,21 @@
expect(out).to eq('')
expect(err).to match(/This script differs from the official version/)
end
end # script matches master
end # script out of sync with master

context 'unknown error comparing source against master' do
it 'prints a non-fatal warning' do
stubbed_env.stub_command('diff').returns_exitstatus(2)

out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
{ 'CURL' => 'true' },
)

expect(status.exitstatus).to be 0
expect(out).to eq('')
expect(err).to match(/There is an error in comparing/)
end
end # unknown error comparing source against master
end