diff --git a/steps/discover-repos.rb b/steps/discover-repos.rb index cd3fac79..74c14742 100755 --- a/steps/discover-repos.rb +++ b/steps/discover-repos.rb @@ -75,7 +75,7 @@ break end json = if opts[:dry] - { items: page > 100 ? [] : [{ full_name: "foo/#{Random.hex(5)}", created_at: Time.now }] } + { items: page > 100 ? [] : Array.new(size) { { full_name: "foo/#{Random.hex(5)}", created_at: Time.now } } } else github.search_repositories(query, per_page: size, page: page) end @@ -102,7 +102,7 @@ puts "Found #{found.count} total repositories in GitHub" if found.count > opts[:total] - found = found.first(opts[:total]) + found = found.first(opts[:total]).to_h puts "We will use only the first #{opts[:total]} repositories" end diff --git a/tests/steps/test-discover-repos.sh b/tests/steps/test-discover-repos.sh index 5eaa9611..8cd63bb0 100755 --- a/tests/steps/test-discover-repos.sh +++ b/tests/steps/test-discover-repos.sh @@ -30,7 +30,7 @@ tex=${TARGET}/foo.tex { rm -f "${csv}" - msg=$("${LOCAL}/steps/discover-repos.rb" --dry --pause=0 --total=3 --min-stars=100 --max-stars=1000 "--csv=${csv}" "--tex=${tex}") + msg=$("${LOCAL}/steps/discover-repos.rb" --dry --pause=0 --total=3 --page-size=1 --min-stars=100 --max-stars=1000 "--csv=${csv}" "--tex=${tex}") echo "${msg}" echo "${msg}" | grep "Found 1 repositories in page #0" echo "${msg}" | grep "Found 3 total repositories in GitHub" @@ -38,4 +38,16 @@ tex=${TARGET}/foo.tex test -s "${tex}" test "$(wc -l < "${csv}" | xargs)" = '4' } > "${stdout}" 2>&1 -echo "👍🏻 A few repositories discovered correctly" +echo "👍🏻 Small repositories discovery test is succeed" + +{ + rm -f "${csv}" + msg=$("${LOCAL}/steps/discover-repos.rb" --dry --pause=0 --total=35 --page-size=30 --min-stars=100 --max-stars=1000 "--csv=${csv}" "--tex=${tex}") + echo "${msg}" + echo "${msg}" | grep "Found 60 total repositories in GitHub" + echo "${msg}" | grep "We will use only the first 35 repositories" + test -e "${csv}" + test -s "${tex}" + test "$(wc -l < "${csv}" | xargs)" = '36' +} > "${stdout}" 2>&1 +echo "👍🏻 Medium repositories discovery test is succeed"