Skip to content

Commit

Permalink
add extra test for nested bencode lists
Browse files Browse the repository at this point in the history
  • Loading branch information
sarp committed Oct 24, 2023
1 parent 328c0a5 commit bb3bc99
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
21 changes: 21 additions & 0 deletions internal/stage_bencode_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,26 @@ func testBencodeList(stageHarness *tester_utils.StageHarness) error {
return err
}

// Test for a nested list: [[4], 5]
nestedListEncoded = "lli4eei5ee"
nestedList = []string{
"[[4],5]\n",
"[[4], 5]\n",
}
logger.Infof("Running ./your_bittorrent.sh decode %s", nestedListEncoded)
logger.Infof("Expected output: %s", strings.TrimSpace(nestedList[0]))
result, err = executable.Run("decode", nestedListEncoded)
if err != nil {
return err
}

if err = assertExitCode(result, 0); err != nil {
return err
}

if err = assertStdoutList(result, nestedList); err != nil {
return err
}

return nil
}
21 changes: 12 additions & 9 deletions internal/test_helpers/fixtures/handshake/with_peer_check
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Debug = true
[stage-3] Running ./your_bittorrent.sh decode lli461e4:pearee
[stage-3] Expected output: [[461,"pear"]]
[your_program] [[461,"pear"]]
[stage-3] Running ./your_bittorrent.sh decode lli4eei5ee
[stage-3] Expected output: [[4],5]
[your_program] [[4],5]
[stage-3] Test passed.

[stage-4] Running tests for Stage #4: bencode-dict
Expand All @@ -41,7 +44,7 @@ Debug = true
[stage-4] Test passed.

[stage-5] Running tests for Stage #5: parse-torrent
[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2052448423/codercat.gif.torrent
[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2207864171/codercat.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2994120
[your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db
Expand All @@ -66,7 +69,7 @@ Debug = true
[stage-5] Test passed.

[stage-6] Running tests for Stage #6: infohash
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1703661002/itsworking.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents856298118/itsworking.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2549700
[your_program] Info Hash: 70edcac2611a8829ebf467a6849f5d8408d9d8f4
Expand All @@ -82,7 +85,7 @@ Debug = true
[your_program] 272a8ff8fc865b053d974a78681414b38077d7b1
[your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4
[your_program] 7affc94f0985b985eb888a36ec92652821a21be4
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1703661002/congratulations.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents856298118/congratulations.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 820892
[your_program] Info Hash: 1cad4a486798d952614c394eb15e75bec587fd08
Expand All @@ -92,7 +95,7 @@ Debug = true
[your_program] 69f885b3988a52ffb03591985402b6d5285940ab
[your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1703661002/codercat.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents856298118/codercat.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2994120
[your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db
Expand All @@ -113,7 +116,7 @@ Debug = true
[stage-6] Test passed.

[stage-7] Running tests for Stage #7: hashes
[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1607475511/test.torrent
[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1460619742/test.torrent
[your_program] Tracker URL: http://bttracker.debian.org:6969/announce
[your_program] Length: 1835008
[your_program] Info Hash: 1840a71323682db707d1e8c9761049e875c03656
Expand All @@ -129,8 +132,8 @@ Debug = true
[stage-7] Test passed.

[stage-8] Running tests for Stage #8: peers
[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2494430895/test.torrent
[stage-8] Server started on port 127.0.0.1:51421...
[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1169253597/test.torrent
[stage-8] Server started on port 127.0.0.1:51530...

[your_program] 188.119.61.177:6881
[your_program] 71.224.0.29:51414
Expand All @@ -144,8 +147,8 @@ Debug = true
[stage-8] Test passed.

[stage-9] Running tests for Stage #9: handshake
[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1326706543/test.torrent 127.0.0.1:51423
[stage-9] Server started on port 127.0.0.1:51424...
[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1324119407/test.torrent 127.0.0.1:51532
[stage-9] Server started on port 127.0.0.1:51533...

[stage-9] Waiting for handshake message
[stage-9] Received handshake: [infohash: c7e51462e85d8631c25f8c9b8c5479345a1de26b, peer_id: 3030313132323333343435353636373738383939]
Expand Down
23 changes: 13 additions & 10 deletions internal/test_helpers/fixtures/pass_all
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
[stage-3] Running ./your_bittorrent.sh decode lli461e4:pearee
[stage-3] Expected output: [[461,"pear"]]
[your_program] [[461,"pear"]]
[stage-3] Running ./your_bittorrent.sh decode lli4eei5ee
[stage-3] Expected output: [[4],5]
[your_program] [[4],5]
[stage-3] Test passed.

[stage-4] Running tests for Stage #4: bencode-dict
Expand All @@ -39,7 +42,7 @@
[stage-4] Test passed.

[stage-5] Running tests for Stage #5: parse-torrent
[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents308331727/codercat.gif.torrent
[stage-5] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1616922747/codercat.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2994120
[your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db
Expand All @@ -62,7 +65,7 @@
[stage-5] Test passed.

[stage-6] Running tests for Stage #6: infohash
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2614696642/itsworking.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2551964154/itsworking.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2549700
[your_program] Info Hash: 70edcac2611a8829ebf467a6849f5d8408d9d8f4
Expand All @@ -78,7 +81,7 @@
[your_program] 272a8ff8fc865b053d974a78681414b38077d7b1
[your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4
[your_program] 7affc94f0985b985eb888a36ec92652821a21be4
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2614696642/congratulations.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2551964154/congratulations.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 820892
[your_program] Info Hash: 1cad4a486798d952614c394eb15e75bec587fd08
Expand All @@ -88,7 +91,7 @@
[your_program] 69f885b3988a52ffb03591985402b6d5285940ab
[your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2614696642/codercat.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2551964154/codercat.gif.torrent
[your_program] Tracker URL: http://bittorrent-test-tracker.codecrafters.io/announce
[your_program] Length: 2994120
[your_program] Info Hash: c77829d2a77d6516f88cd7a3de1a26abcbfab0db
Expand All @@ -109,7 +112,7 @@
[stage-6] Test passed.

[stage-7] Running tests for Stage #7: hashes
[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2451637776/test.torrent
[stage-7] Running ./your_bittorrent.sh info /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1322099590/test.torrent
[your_program] Tracker URL: http://bttracker.debian.org:6969/announce
[your_program] Length: 1835008
[your_program] Info Hash: 1840a71323682db707d1e8c9761049e875c03656
Expand All @@ -125,7 +128,7 @@
[stage-7] Test passed.

[stage-8] Running tests for Stage #8: peers
[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents382743495/test.torrent
[stage-8] Running ./your_bittorrent.sh peers /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents712288102/test.torrent
[your_program] 188.119.61.177:6881
[your_program] 71.224.0.29:51414
[your_program] 62.153.208.98:3652
Expand All @@ -138,15 +141,15 @@
[stage-8] Test passed.

[stage-9] Running tests for Stage #9: handshake
[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents1302044088/test.torrent 127.0.0.1:51430
[stage-9] Running ./your_bittorrent.sh handshake /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents660096687/test.torrent 127.0.0.1:51538
[your_program] Peer ID: ee8f5140bfc195c36b0567cd055ac9839e682ab0
[stage-9] Test passed.

[stage-10] Running tests for Stage #10: dl-piece
[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/piece-2 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/congratulations.gif.torrent 2
[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/piece-3 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3765219977/congratulations.gif.torrent 3
[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/piece-2 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/congratulations.gif.torrent 2
[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/piece-3 /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents3503847342/congratulations.gif.torrent 3
[stage-10] Test passed.

[stage-11] Running tests for Stage #11: dl-file
[stage-11] Running ./your_bittorrent.sh download -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2788206242/codercat.gif /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents2788206242/codercat.gif.torrent
[stage-11] Running ./your_bittorrent.sh download -o /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents4213953347/codercat.gif /var/folders/08/v_mzt9816270xbqv5t3xgzyr0000gn/T/torrents4213953347/codercat.gif.torrent
[stage-11] Test passed.

0 comments on commit bb3bc99

Please sign in to comment.