Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2025, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html)
Copyright (c) 2026, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html)
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ $ make {image_server|image_client}
# Run all tests
$ make {test_server|test_client}

# Run only specific tests
$ ./bin/run_tests.sh {-h|--help}
$ ./bin/run_tests.sh {server|client} B56Sp3
# Run only tests whose id starts with B56
$ make {test_server|test_client} tid=B56

# Check test metrics
Expand Down
160 changes: 94 additions & 66 deletions test/client/differ_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
require 'cgi'

class DifferClientTest < ClientTestBase
def self.id58_prefix
'2q0'
end

hostname = 'server'
port = ENV['CYBER_DOJO_DIFFER_PORT'].to_i

# - - - - - - - - - - - - - - - - - - - -

test 'jj8', %w[
clients use probes with a trailing question mark in their path which is overly cute
so support both with and without ? until all clients have switched to non ?
] do
test '2q0jj8', %w(
| clients use probes with a trailing question mark in their path which is overly cute
| so support both with and without ? until all clients have switched to non ?
) do
requester = HttpJsonHash::Requester.new(hostname, port)
http = HttpJsonHash::Unpacker.new('differ', requester)
assert http.get('alive?', {}).instance_of?(TrueClass)
Expand All @@ -25,10 +22,10 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'jj9', %w(
/diff_summary can use GET query args
which is important since in jQuery a $.getJSON() call
always passes its arguments in the query string
test '2q0jj9', %w(
| /diff_summary can use GET query args
| which is important since in jQuery a $.getJSON() call
| always passes its arguments in the query string
) do
requester = HttpJsonHash::Requester.new(hostname, port)
http = HttpJsonHash::Unpacker.new('differ', requester)
Expand Down Expand Up @@ -73,16 +70,18 @@ def self.id58_prefix
# >10K query was a problem for thin at one time
# - - - - - - - - - - - - - - - - - - - -

test '347',
'>10K query is not rejected by web server' do
test '2q0347', %w(
| >10K query is not rejected by web server
) do
@old_files = { 'wibble.h' => 'X' * 45 * 1024 }
@new_files = {}
id, was_index, now_index = *run_diff_prepare
differ.diff_summary(id, was_index, now_index)
end

test '348',
'>10K query in nested sub-dir is not rejected by web-server' do
test '2q0348', %w(
| >10K query in nested sub-dir is not rejected by web-server
) do
@old_files = { 'gh/jk/wibble.h' => 'X' * 45 * 1024 }
@new_files = {}
id, was_index, now_index = *run_diff_prepare
Expand All @@ -91,12 +90,16 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '944', 'probes 200' do
test '2q0944', %w(
| probes 200
) do
assert differ.alive.instance_of?(TrueClass)
assert differ.ready.instance_of?(TrueClass)
end

test '945', 'sha 200' do
test '2q0945', %w(
| sha 200
) do
sha = differ.sha
assert_equal 40, sha.size, 'sha.size'
sha.each_char do |ch|
Expand All @@ -108,7 +111,9 @@ def self.id58_prefix
# failure cases
# - - - - - - - - - - - - - - - - - - - -

test '7C0', %w[calling unknown method raises] do
test '2q07C0', %w(
| calling unknown method raises
) do
requester = HttpJsonHash::Requester.new(hostname, port)
http = HttpJsonHash::Unpacker.new('differ', requester)
error = assert_raises(RuntimeError) { http.get(:shar, { x: 42 }) }
Expand All @@ -131,8 +136,9 @@ def self.id58_prefix
# delete file
# - - - - - - - - - - - - - - - - - - - -

test '313',
'deleted empty file' do
test '2q0313', %w(
| deleted empty file
) do
@old_files = { 'hiker.h' => '' }
@new_files = {}
assert_diff(
Expand All @@ -158,8 +164,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '314',
'deleted empty file in nested sub-dir' do
test '2q0314', %w(
| deleted empty file in nested sub-dir
) do
@old_files = { '6/7/8/hiker.h' => '' }
@new_files = {}
assert_diff(
Expand All @@ -175,8 +182,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'FE9',
'deleted non-empty file shows as all lines deleted' do
test '2q0FE9', %w(
| deleted non-empty file shows as all lines deleted
) do
@old_files = { 'hiker.h' => "a\nb\nc\nd\n" }
@new_files = {}
assert_diff(
Expand Down Expand Up @@ -208,8 +216,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'FEA',
'deleted non-empty file in nested sub-dir shows as all lines deleted' do
test '2q0FEA', %w(
| deleted non-empty file in nested sub-dir shows as all lines deleted
) do
@old_files = { '4/5/6/7/hiker.h' => "a\nb\nc\nd\n" }
@new_files = {}
assert_diff(
Expand All @@ -233,9 +242,10 @@ def self.id58_prefix
# delete content
# - - - - - - - - - - - - - - - - - - - -

test 'B67',
'all lines deleted but file not deleted',
'shows as all lines deleted' do
test '2q0B67', %w(
| all lines deleted but file not deleted
| shows as all lines deleted
) do
@old_files = { 'hiker.h' => "a\nb\nc\nd\n" }
@new_files = { 'hiker.h' => '' }
assert_diff(
Expand All @@ -257,9 +267,10 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'B68',
'all lines deleted but nested sub-dir file not deleted',
'shows as all lines deleted' do
test '2q0B68', %w(
| all lines deleted but nested sub-dir file not deleted
| shows as all lines deleted
) do
@old_files = { 'r/t/y/hiker.h' => "a\nb\nc\nd\n" }
@new_files = { 'r/t/y/hiker.h' => '' }
assert_diff(
Expand All @@ -283,8 +294,9 @@ def self.id58_prefix
# new file
# - - - - - - - - - - - - - - - - - - - -

test '95F',
%w[created new empty file] do
test '2q095F', %w(
| created new empty file
) do
@old_files = {}
@new_files = { 'diamond.h' => '' }
assert_diff(
Expand All @@ -300,8 +312,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '960',
%w[created empty file in nested sub-dir] do
test '2q0960', %w(
| created empty file in nested sub-dir
) do
@old_files = {}
@new_files = { 'a/b/c/diamond.h' => '' }
assert_diff(
Expand All @@ -327,8 +340,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '2C3',
%w[created non-empty file] do
test '2q02C3', %w(
| created non-empty file
) do
@old_files = {}
@new_files = { 'diamond.h' => "a\nb\nc\nd" }
assert_diff(
Expand All @@ -350,8 +364,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '2C4',
%w[created non-empty file in nested sub-dir] do
test '2q02C4', %w(
| created non-empty file in nested sub-dir
) do
@old_files = {}
@new_files = { 'q/w/e/diamond.h' => "a\nb\nc\nd" }
assert_diff(
Expand All @@ -375,8 +390,9 @@ def self.id58_prefix
# change
# - - - - - - - - - - - - - - - - - - - -

test 'E3E',
%w[changed non-empty file] do
test '2q0E3E', %w(
| changed non-empty file
) do
@old_files = { 'diamond.h' => 'a' }
@new_files = { 'diamond.h' => 'b' }
assert_diff(
Expand All @@ -396,8 +412,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'E3F',
%w[changed non-empty file in nested sub-dir] do
test '2q0E3F', %w(
| changed non-empty file in nested sub-dir
) do
@old_files = { 't/y/u/diamond.h' => 'a1' }
@new_files = { 't/y/u/diamond.h' => 'b2' }
assert_diff(
Expand All @@ -417,9 +434,10 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'B9E',
'changed non-empty file shows as deleted and added lines',
'with each hunk in its own indexed section' do
test '2q0B9E', %w(
| changed non-empty file shows as deleted and added lines
| with each hunk in its own indexed section
) do
@old_files = {
'diamond.h' =>
[
Expand Down Expand Up @@ -475,9 +493,10 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'B9F',
'changed non-empty file in nested sub-dir shows as deleted and added lines',
'with each hunk in its own indexed section' do
test '2q0B9F', %w(
| changed non-empty file in nested sub-dir shows as deleted and added lines
| with each hunk in its own indexed section
) do
@old_files = {
'a/b/c/diamond.h' =>
[
Expand Down Expand Up @@ -535,8 +554,9 @@ def self.id58_prefix
# renamed file
# - - - - - - - - - - - - - - - - - - - -

test 'E50',
'100% identical renamed file' do
test '2q0E50', %w(
| 100% identical renamed file
) do
@old_files = { 'hiker.h' => "a\nb\nc\nd" }
@new_files = { 'diamond.h' => "a\nb\nc\nd" }
assert_diff(
Expand Down Expand Up @@ -567,8 +587,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'E51',
'100% identical renamed file in nested sub-dir' do
test '2q0E51', %w(
| 100% identical renamed file in nested sub-dir
) do
@old_files = { 'a/f/d/hiker.h' => "a\nb\nc\nd" }
@new_files = { 'a/f/d/diamond.h' => "a\nb\nc\nd" }
assert_diff(
Expand All @@ -589,8 +610,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'FDB',
'<100% identical rename' do
test '2q0FDB', %w(
| <100% identical rename
) do
@old_files = { 'hiker.h' => "a\nb\nc\nd" }
@new_files = { 'diamond.h' => "a\nb\nX\nd" }
assert_diff(
Expand All @@ -613,8 +635,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test 'FDC',
'<100% identical renamed in nested sub-dir' do
test '2q0FDC', %w(
| <100% identical renamed in nested sub-dir
) do
@old_files = { 'a/b/c/hiker.h' => "a\nb\nc\nd" }
@new_files = { 'a/b/c/diamond.h' => "a\nb\nX\nd" }
assert_diff(
Expand All @@ -639,8 +662,9 @@ def self.id58_prefix
# unchanged files
# - - - - - - - - - - - - - - - - - - - -

test 'AEC',
'unchanged empty files' do
test '2q0AEC', %w(
| unchanged empty files
) do
@old_files = { 'diamond.h' => '' }
@new_files = { 'diamond.h' => '' }
assert_diff(
Expand All @@ -656,8 +680,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '7FF',
'unchanged empty-file in nested sub-dir' do
test '2q07FF', %w(
| unchanged empty-file in nested sub-dir
) do
@old_files = { 'w/e/r/diamond.h' => '' }
@new_files = { 'w/e/r/diamond.h' => '' }
assert_diff(
Expand All @@ -673,8 +698,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '365',
'unchanged non-empty file' do
test '2q0365', %w(
| unchanged non-empty file
) do
@old_files = { 'diamond.h' => "a\nb\nc\nd" }
@new_files = { 'diamond.h' => "a\nb\nc\nd" }
assert_diff(
Expand All @@ -695,8 +721,9 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - - - - -

test '366',
'unchanged non-empty file in nested sub-dir shows as all lines same' do
test '2q0366', %w(
| unchanged non-empty file in nested sub-dir shows as all lines same
) do
@old_files = { 'r/t/y/diamond.h' => "a\nbb\nc\nd" }
@new_files = { 'r/t/y/diamond.h' => "a\nbb\nc\nd" }
assert_diff(
Expand Down Expand Up @@ -825,4 +852,5 @@ def line(text, type, number)
def section(index)
{ 'type' => 'section', 'index' => index }
end

end
Loading