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 Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/cyber-dojo/sinatra-base:a8e581e@sha256:61a896d3ff86385c89baa0cb61500c93a8fcfb216ca76cdb774e5c32d2ff2d04
FROM ghcr.io/cyber-dojo/sinatra-base:dd38f41@sha256:78e366649c6b28379a7666503149d71aa154960b9421e8a57721da13c1eb7ab1
# The FROM statement above is typically set via an automated pull-request from the sinatra-base repo
LABEL maintainer=jon@jaggersoft.com

Expand Down
8 changes: 4 additions & 4 deletions bin/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

source "${ROOT_DIR}/bin/lib.sh"
source "${ROOT_DIR}/bin/echo_env_vars.sh"
# shellcheck disable=SC2046
export $(echo_env_vars)
exit_non_zero_unless_installed docker

show_help()
{
Expand Down Expand Up @@ -52,9 +55,6 @@ build_image()

local -r type="${1}"

exit_non_zero_unless_installed docker
# shellcheck disable=SC2046
export $(echo_env_vars)
containers_down

if [ "${CI:-}" != 'true' ]; then
Expand Down
2 changes: 1 addition & 1 deletion bin/check_coverage_metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

source "${ROOT_DIR}/bin/lib.sh"
source "${ROOT_DIR}/bin/echo_env_vars.sh"

show_help()
{
Expand Down
2 changes: 1 addition & 1 deletion bin/check_test_metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

source "${ROOT_DIR}/bin/lib.sh"
source "${ROOT_DIR}/bin/echo_env_vars.sh"

show_help()
{
Expand Down
6 changes: 3 additions & 3 deletions bin/demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

source "${ROOT_DIR}/bin/lib.sh"

exit_non_zero_unless_installed docker
source "${ROOT_DIR}/bin/echo_env_vars.sh"
# shellcheck disable=SC2046
export $(echo_env_vars)
exit_non_zero_unless_installed docker

docker compose --progress=plain up --wait --wait-timeout=10 client
copy_in_saver_test_data
TMP_HTML_FILENAME=/tmp/differ-demo.html
Expand Down
39 changes: 39 additions & 0 deletions bin/echo_env_vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

echo_env_vars()
{
# Set env-vars for this repos differ service
if [[ ! -v COMMIT_SHA ]] ; then
local -r sha="$(cd "${ROOT_DIR}" && git rev-parse HEAD)"
echo COMMIT_SHA="${sha}" # --build-arg ...
fi

# Setup port env-vars in .env file using versioner
{
echo "# This file is generated in bin/lib.sh echo_env_vars()"
echo "CYBER_DOJO_DIFFER_CLIENT_PORT=9999"
docker run --rm cyberdojo/versioner 2> /dev/null | grep PORT
} > "${ROOT_DIR}/.env"

# From versioner
docker run --rm cyberdojo/versioner 2> /dev/null

echo CYBER_DOJO_DIFFER_SHA="${sha}"
echo CYBER_DOJO_DIFFER_TAG="${sha:0:7}"
#
echo CYBER_DOJO_DIFFER_CLIENT_IMAGE=cyberdojo/differ-client
echo CYBER_DOJO_DIFFER_CLIENT_PORT=9999
#
echo CYBER_DOJO_DIFFER_CLIENT_USER=nobody
echo CYBER_DOJO_DIFFER_SERVER_USER=nobody
#
echo CYBER_DOJO_DIFFER_CLIENT_CONTAINER_NAME=test_differ_client
echo CYBER_DOJO_DIFFER_SERVER_CONTAINER_NAME=test_differ_server
#
local -r AWS_ACCOUNT_ID=244531986313
local -r AWS_REGION=eu-central-1
echo CYBER_DOJO_DIFFER_IMAGE="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/differ"

# Overrides for local development
#echo CYBER_DOJO_SAVER_SHA=d80c6e4f9d17b41da878fa69315de7298e059350
#echo CYBER_DOJO_SAVER_TAG=d80c6e4
}
39 changes: 0 additions & 39 deletions bin/lib.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@

echo_env_vars()
{
# Set env-vars for this repos differ service
if [[ ! -v COMMIT_SHA ]] ; then
local -r sha="$(cd "${ROOT_DIR}" && git rev-parse HEAD)"
echo COMMIT_SHA="${sha}" # --build-arg ...
fi

# Setup port env-vars in .env file using versioner
{
echo "# This file is generated in bin/lib.sh echo_env_vars()"
echo "CYBER_DOJO_DIFFER_CLIENT_PORT=9999"
docker run --rm cyberdojo/versioner 2> /dev/null | grep PORT
} > "${ROOT_DIR}/.env"

# From versioner
docker run --rm cyberdojo/versioner 2> /dev/null

echo CYBER_DOJO_DIFFER_SHA="${sha}"
echo CYBER_DOJO_DIFFER_TAG="${sha:0:7}"
#
echo CYBER_DOJO_DIFFER_CLIENT_IMAGE=cyberdojo/differ-client
echo CYBER_DOJO_DIFFER_CLIENT_PORT=9999
#
echo CYBER_DOJO_DIFFER_CLIENT_USER=nobody
echo CYBER_DOJO_DIFFER_SERVER_USER=nobody
#
echo CYBER_DOJO_DIFFER_CLIENT_CONTAINER_NAME=test_differ_client
echo CYBER_DOJO_DIFFER_SERVER_CONTAINER_NAME=test_differ_server
#
local -r AWS_ACCOUNT_ID=244531986313
local -r AWS_REGION=eu-central-1
echo CYBER_DOJO_DIFFER_IMAGE="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/differ"

# Overrides for local development
#echo CYBER_DOJO_SAVER_SHA=d80c6e4f9d17b41da878fa69315de7298e059350
#echo CYBER_DOJO_SAVER_TAG=d80c6e4
}

exit_non_zero_unless_installed()
{
for dependent in "$@"
Expand Down
1 change: 0 additions & 1 deletion bin/loud_curl_form_data.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
set -Eeu


loud_curl_form_data()
{
# curl that prints the server traceback if the response
Expand Down
1 change: 1 addition & 0 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "${ROOT_DIR}/bin/lib.sh"
source "${ROOT_DIR}/bin/echo_env_vars.sh"
# shellcheck disable=SC2046
export $(echo_env_vars)

Expand Down
6 changes: 3 additions & 3 deletions bin/snyk_container_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
set -Eeu

export ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

source "${ROOT_DIR}/bin/lib.sh"

exit_non_zero_unless_installed snyk
source "${ROOT_DIR}/bin/echo_env_vars.sh"
# shellcheck disable=SC2046
export $(echo_env_vars)
exit_non_zero_unless_installed snyk

readonly IMAGE_NAME="${CYBER_DOJO_DIFFER_IMAGE}:${CYBER_DOJO_DIFFER_TAG}"

snyk container test "${IMAGE_NAME}" \
Expand Down
71 changes: 45 additions & 26 deletions test/server/differ_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

class DifferTest < DifferTestBase

def self.versions_test(id58_suffix, *lines, &block)
versions = 0..2
#def self.versions_test(id58_suffix, *lines, &block)
# versions = 0..2
# versions.each do |version|
# version_test(version, id58_suffix, *lines, &block)
# end
#end

def self.versions_0_1_test(id58_suffix, *lines, &block)
versions = 0..1
versions.each do |version|
version_test(version, id58_suffix, *lines, &block)
end
Expand All @@ -23,7 +30,8 @@ def self.version_test(version, id58_suffix, *lines, &block)
# empty file
# - - - - - - - - - - - - - - - - - - - - - - - -

versions_test 'C9sA2C', %w(
#versions_test 'C9sA2C', %w(
versions_0_1_test 'C9sA2C', %w(
| empty file is created
) do
# Saver v2 uses git and its implementation currently relies on there
Expand All @@ -39,7 +47,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sA5C', %w(
#versions_test 'C9sA5C', %w(
versions_0_1_test 'C9sA5C', %w(
| empty file is deleted
) do
@was_files = { 'empty.rb' => '' }
Expand All @@ -52,7 +61,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9s3ED', %w(
#versions_test 'C9s3ED', %w(
versions_0_1_test 'C9s3ED', %w(
| empty file is unchanged
) do
@was_files = { 'empty.py' => '' }
Expand All @@ -65,7 +75,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sAA6', %w(
#versions_test 'C9sAA6', %w(
versions_0_1_test 'C9sAA6', %w(
| empty file is renamed 100% identical
) do
@was_files = { 'plain' => '' }
Expand All @@ -78,7 +89,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sA2D', %w(
#versions_test 'C9sA2D', %w(
versions_0_1_test 'C9sA2D', %w(
| empty file is renamed 100% identical across dirs
) do
@was_files = { 'plain' => '' }
Expand All @@ -91,7 +103,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sF2E', %w(
#versions_test 'C9sF2E', %w(
versions_0_1_test 'C9sF2E', %w(
| empty file has some content added
) do
@was_files = { 'empty.c' => '' }
Expand All @@ -111,7 +124,8 @@ def self.version_test(version, id58_suffix, *lines, &block)
# non-empty file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

versions_test 'C9sD09', %w(
#versions_test 'C9sD09', %w(
versions_0_1_test 'C9sD09', %w(
| non-empty file is created
) do
# Saver v2 uses git and its implementation currently relies on there
Expand All @@ -129,7 +143,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9s0C6', %w(
#versions_test 'C9s0C6', %w(
versions_0_1_test 'C9s0C6', %w(
| non-empty file is deleted
) do
@was_files = { 'non-empty.h' => "two\nlines" }
Expand All @@ -146,7 +161,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9s21D', %w(
#versions_test 'C9s21D', %w(
versions_0_1_test 'C9s21D', %w(
| non-empty file is unchanged
) do
@was_files = { 'non-empty.h' => '#include<stdio.h>' }
Expand All @@ -161,7 +177,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sAA7', %w(
#versions_test 'C9sAA7', %w(
versions_0_1_test 'C9sAA7', %w(
| non-empty file is renamed 100% identical
) do
@was_files = { 'plain' => 'xxx' }
Expand All @@ -176,7 +193,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sBA7', %w(
#versions_test 'C9sBA7', %w(
versions_0_1_test 'C9sBA7', %w(
| non-empty file is renamed 100% identical across dirs
) do
@was_files = { 'a/b/plain' => "a\nb\nc\nd" }
Expand All @@ -194,7 +212,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sAA8', %w(
#versions_test 'C9sAA8', %w(
versions_0_1_test 'C9sAA8', %w(
| non-empty file is renamed <100% identical
) do
@was_files = { 'hiker.h' => "a\nb\nc\nd" }
Expand All @@ -214,7 +233,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9sAA9', %w(
#versions_test 'C9sAA9', %w(
versions_0_1_test 'C9sAA9', %w(
| non-empty file is renamed <100% identical across dirs
) do
@was_files = { '1/2/hiker.h' => "a\nb\nc\nd" }
Expand All @@ -234,7 +254,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9s4D0', %w(
#versions_test 'C9s4D0', %w(
versions_0_1_test 'C9s4D0', %w(
| non-empty file has some content added at the start
) do
@was_files = { 'non-empty.c' => 'something' }
Expand All @@ -251,7 +272,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9s4D1', %w(
#versions_test 'C9s4D1', %w(
versions_0_1_test 'C9s4D1', %w(
| non-empty file has some content added at the end
) do
@was_files = { 'non-empty.c' => 'something' }
Expand All @@ -268,7 +290,8 @@ def self.version_test(version, id58_suffix, *lines, &block)

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

versions_test 'C9s4D2', %w(
#versions_test 'C9s4D2', %w(
versions_0_1_test 'C9s4D2', %w(
| non-empty file has some content added in the middle
) do
@was_files = { 'non-empty.c' => "a\nc" }
Expand All @@ -293,21 +316,17 @@ def self.version_test(version, id58_suffix, *lines, &block)
manifest['version'] = 2
id = saver.kata_create(manifest)

was_files = { '1/2/hiker.h' => "a\nb\nc\nd" }
now_files = { '3/4/diamond.h' => "a\nb\nX\nd" }
kata_ran_tests(id, was_index = 1, was_files)
kata_ran_tests(id, now_index = 2, now_files)
ex = assert_raises(RuntimeError) do
differ.diff_lines(id: id, was_index: was_index, now_index: now_index + 1)
differ.diff_lines(id: id, was_index: 1, now_index: 2)
end
assert_equal "Invalid index #{now_index + 1}", ex.message
assert_equal 'Invalid index 1', ex.message
end

private

def assert_diff(raw_expected)
expected = expected_diff(raw_expected)
assert_diff_lines(expected)
assert_diff_lines(expected) # <<
expected[0].delete(:lines)
assert_diff_summary(expected)
end
Expand Down Expand Up @@ -342,7 +361,7 @@ def run_diff_prepare
kata_ran_tests(id, was_index = 1, @was_files)
kata_ran_tests(id, now_index = 2, @now_files)
[id, was_index, now_index]
end
end

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

Expand Down
Loading