Skip to content

Commit

Permalink
Merge pull request #16 from codecrafters-io/update-course-stage-slug
Browse files Browse the repository at this point in the history
CC-1227 update course stage slug
  • Loading branch information
libmartinito authored May 17, 2024
2 parents 2a6b482 + 0bfd1b1 commit 26db4ad
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 359 deletions.
8 changes: 4 additions & 4 deletions internal/stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ func TestStages(t *testing.T) {

testCases := map[string]tester_utils_testing.TesterOutputTestCase{
"bencoded_string_failure": {
UntilStageSlug: "bencode-string",
UntilStageSlug: "ns2",
CodePath: "./test_helpers/scenarios/init/failure",
ExpectedExitCode: 1,
StdoutFixturePath: "./test_helpers/fixtures/init/failure",
NormalizeOutputFunc: normalizeTesterOutput,
},
"bencoded_string_success": {
UntilStageSlug: "bencode-string",
UntilStageSlug: "ns2",
CodePath: "./test_helpers/scenarios/init/success",
ExpectedExitCode: 0,
StdoutFixturePath: "./test_helpers/fixtures/init/success",
NormalizeOutputFunc: normalizeTesterOutput,
},
"handshake_with_peer_check": {
UntilStageSlug: "handshake",
UntilStageSlug: "ca4",
CodePath: "./test_helpers/scenarios/handshake/with_peer_check",
ExpectedExitCode: 0,
StdoutFixturePath: "./test_helpers/fixtures/handshake/with_peer_check",
NormalizeOutputFunc: normalizeTesterOutput,
},
"pass_all": {
UntilStageSlug: "dl-file",
UntilStageSlug: "jv8",
CodePath: "./test_helpers/scenarios/pass_all",
ExpectedExitCode: 0,
StdoutFixturePath: "./test_helpers/fixtures/pass_all",
Expand Down
659 changes: 356 additions & 303 deletions internal/test_helpers/course_definition.yml

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions internal/test_helpers/fixtures/handshake/with_peer_check
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Debug = true

[stage-9] Running tests for Stage #9: handshake
[stage-9] Running ./your_bittorrent.sh handshake /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents3277457488/test.torrent 127.0.0.1:63432
[stage-9] Server started on port 127.0.0.1:63433...
[stage-9] Running tests for Stage #9: ca4
[stage-9] Running ./your_bittorrent.sh handshake /tmp/torrents459831871/test.torrent 127.0.0.1:46425
[stage-9] Server started on port 127.0.0.1:33805...
[stage-9] 
[stage-9] Waiting for handshake message
[stage-9] Received handshake: [infohash: c7e51462e85d8631c25f8c9b8c5479345a1de26b, peer_id: 3030313132323333343435353636373738383939]
Expand All @@ -11,9 +11,9 @@ Debug = true
[your_program] Peer ID: ee8f5140bfc195c36b0567cd055ac9839e682ab0
[stage-9] Test passed.

[stage-8] Running tests for Stage #8: peers
[stage-8] Running ./your_bittorrent.sh peers /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents1486925982/test.torrent
[stage-8] Server started on port 127.0.0.1:63438...
[stage-8] Running tests for Stage #8: fi9
[stage-8] Running ./your_bittorrent.sh peers /tmp/torrents3722462756/test.torrent
[stage-8] Server started on port 127.0.0.1:36151...
[stage-8] 
[your_program] 188.119.61.177:6881
[your_program] 71.224.0.29:51414
Expand All @@ -26,8 +26,8 @@ Debug = true
[your_program] 216.195.129.27:60000
[stage-8] Test passed.

[stage-7] Running tests for Stage #7: hashes
[stage-7] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2337476787/test.torrent
[stage-7] Running tests for Stage #7: bf7
[stage-7] Running ./your_bittorrent.sh info /tmp/torrents2748604680/test.torrent
[your_program] Tracker URL: http://bttracker.debian.org:6969/announce
[your_program] Length: 1835008
[your_program] Info Hash: 1840a71323682db707d1e8c9761049e875c03656
Expand All @@ -42,8 +42,8 @@ Debug = true
[your_program] 70edcac2611a8829ebf467a6849f5d8408d9d8f4
[stage-7] Test passed.

[stage-6] Running tests for Stage #6: infohash
[stage-6] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2493686961/itsworking.gif.torrent
[stage-6] Running tests for Stage #6: rb2
[stage-6] Running ./your_bittorrent.sh info /tmp/torrents2177985479/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 @@ -59,7 +59,7 @@ Debug = true
[your_program] 272a8ff8fc865b053d974a78681414b38077d7b1
[your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4
[your_program] 7affc94f0985b985eb888a36ec92652821a21be4
[stage-6] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2493686961/congratulations.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /tmp/torrents2177985479/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 @@ -69,7 +69,7 @@ Debug = true
[your_program] 69f885b3988a52ffb03591985402b6d5285940ab
[your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c
[stage-6] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2493686961/codercat.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /tmp/torrents2177985479/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 @@ -89,8 +89,8 @@ Debug = true
[your_program] 3d8db9e34db63b4ba1be27930911aa37b3f997dd
[stage-6] Test passed.

[stage-5] Running tests for Stage #5: parse-torrent
[stage-5] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents1060379822/codercat.gif.torrent
[stage-5] Running tests for Stage #5: ow9
[stage-5] Running ./your_bittorrent.sh info /tmp/torrents3776668588/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 @@ -114,7 +114,7 @@ Debug = true
[stage-5] Length is correct
[stage-5] Test passed.

[stage-4] Running tests for Stage #4: bencode-dict
[stage-4] Running tests for Stage #4: mn6
[stage-4] Running ./your_bittorrent.sh decode de
[stage-4] Expected output: {}
[your_program] {}
Expand All @@ -126,7 +126,7 @@ Debug = true
[your_program] {"inner_dict":{"key1":"value1","key2":42,"list_key":["item1","item2",3]}}
[stage-4] Test passed.

[stage-3] Running tests for Stage #3: bencode-list
[stage-3] Running tests for Stage #3: ah1
[stage-3] Running ./your_bittorrent.sh decode le
[stage-3] Expected output: []
[your_program] []
Expand All @@ -141,7 +141,7 @@ Debug = true
[your_program] [[4],5]
[stage-3] Test passed.

[stage-2] Running tests for Stage #2: bencode-int
[stage-2] Running tests for Stage #2: eb4
[stage-2] Running ./your_bittorrent.sh decode i177586623e
[your_program] 177586623
[stage-2] Running ./your_bittorrent.sh decode i4294967300e
Expand All @@ -150,7 +150,7 @@ Debug = true
[your_program] -52
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: bencode-string
[stage-1] Running tests for Stage #1: ns2
[stage-1] Running ./your_bittorrent.sh decode 4:pear
[your_program] "pear"
[stage-1] Running ./your_bittorrent.sh decode 55:http://bittorrent-test-tracker.codecrafters.io/announce
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/init/failure
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[stage-1] Running tests for Stage #1: bencode-string
[stage-1] Running tests for Stage #1: ns2
[stage-1] Running ./your_bittorrent.sh decode 4:pear
[your_program] Logs from your program will appear here!
[stage-1] Expected "\"pear\"\n" as stdout, got: "Logs from your program will appear here!\n"
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/init/success
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[stage-1] Running tests for Stage #1: bencode-string
[stage-1] Running tests for Stage #1: ns2
[stage-1] Running ./your_bittorrent.sh decode 4:pear
[your_program] "pear"
[stage-1] Running ./your_bittorrent.sh decode 55:http://bittorrent-test-tracker.codecrafters.io/announce
Expand Down
42 changes: 21 additions & 21 deletions internal/test_helpers/fixtures/pass_all
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[stage-11] Running tests for Stage #11: dl-file
[stage-11] Running ./your_bittorrent.sh download -o /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2667986651/codercat.gif /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2667986651/codercat.gif.torrent
[stage-11] Running tests for Stage #11: jv8
[stage-11] Running ./your_bittorrent.sh download -o /tmp/torrents2541841433/codercat.gif /tmp/torrents2541841433/codercat.gif.torrent
[stage-11] Test passed.

[stage-10] Running tests for Stage #10: dl-piece
[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents3368166080/piece-2 /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents3368166080/congratulations.gif.torrent 2
[stage-10] Running ./your_bittorrent.sh download_piece -o /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents3368166080/piece-3 /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents3368166080/congratulations.gif.torrent 3
[stage-10] Running tests for Stage #10: nd2
[stage-10] Running ./your_bittorrent.sh download_piece -o /tmp/torrents1653419891/piece-2 /tmp/torrents1653419891/congratulations.gif.torrent 2
[stage-10] Running ./your_bittorrent.sh download_piece -o /tmp/torrents1653419891/piece-3 /tmp/torrents1653419891/congratulations.gif.torrent 3
[stage-10] Test passed.

[stage-9] Running tests for Stage #9: handshake
[stage-9] Running ./your_bittorrent.sh handshake /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2553910923/test.torrent 127.0.0.1:63378
[stage-9] Running tests for Stage #9: ca4
[stage-9] Running ./your_bittorrent.sh handshake /tmp/torrents210959508/test.torrent 127.0.0.1:36379
[your_program] Peer ID: ee8f5140bfc195c36b0567cd055ac9839e682ab0
[stage-9] Test passed.

[stage-8] Running tests for Stage #8: peers
[stage-8] Running ./your_bittorrent.sh peers /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents430650193/test.torrent
[stage-8] Running tests for Stage #8: fi9
[stage-8] Running ./your_bittorrent.sh peers /tmp/torrents1478803508/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 @@ -25,8 +25,8 @@
[your_program] 216.195.129.27:60000
[stage-8] Test passed.

[stage-7] Running tests for Stage #7: hashes
[stage-7] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents2741222045/test.torrent
[stage-7] Running tests for Stage #7: bf7
[stage-7] Running ./your_bittorrent.sh info /tmp/torrents3918854671/test.torrent
[your_program] Tracker URL: http://bttracker.debian.org:6969/announce
[your_program] Length: 1835008
[your_program] Info Hash: 1840a71323682db707d1e8c9761049e875c03656
Expand All @@ -41,8 +41,8 @@
[your_program] 70edcac2611a8829ebf467a6849f5d8408d9d8f4
[stage-7] Test passed.

[stage-6] Running tests for Stage #6: infohash
[stage-6] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents4217096716/itsworking.gif.torrent
[stage-6] Running tests for Stage #6: rb2
[stage-6] Running ./your_bittorrent.sh info /tmp/torrents3977432877/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 @@ -58,7 +58,7 @@
[your_program] 272a8ff8fc865b053d974a78681414b38077d7b1
[your_program] b07128d3a6018062bfe779db96d3a93c05fb81d4
[your_program] 7affc94f0985b985eb888a36ec92652821a21be4
[stage-6] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents4217096716/congratulations.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /tmp/torrents3977432877/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 @@ -68,7 +68,7 @@
[your_program] 69f885b3988a52ffb03591985402b6d5285940ab
[your_program] 76869e6c9c1f101f94f39de153e468be6a638f4f
[your_program] bded68d02de011a2b687f75b5833f46cce8e3e9c
[stage-6] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents4217096716/codercat.gif.torrent
[stage-6] Running ./your_bittorrent.sh info /tmp/torrents3977432877/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 @@ -88,8 +88,8 @@
[your_program] 3d8db9e34db63b4ba1be27930911aa37b3f997dd
[stage-6] Test passed.

[stage-5] Running tests for Stage #5: parse-torrent
[stage-5] Running ./your_bittorrent.sh info /var/folders/5l/z5y3dkwn68sgb6htzc5w7vnm0000gn/T/torrents645494093/codercat.gif.torrent
[stage-5] Running tests for Stage #5: ow9
[stage-5] Running ./your_bittorrent.sh info /tmp/torrents858807808/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 @@ -111,7 +111,7 @@
[stage-5] Length is correct
[stage-5] Test passed.

[stage-4] Running tests for Stage #4: bencode-dict
[stage-4] Running tests for Stage #4: mn6
[stage-4] Running ./your_bittorrent.sh decode de
[stage-4] Expected output: {}
[your_program] {}
Expand All @@ -123,7 +123,7 @@
[your_program] {"inner_dict":{"key1":"value1","key2":42,"list_key":["item1","item2",3]}}
[stage-4] Test passed.

[stage-3] Running tests for Stage #3: bencode-list
[stage-3] Running tests for Stage #3: ah1
[stage-3] Running ./your_bittorrent.sh decode le
[stage-3] Expected output: []
[your_program] []
Expand All @@ -138,7 +138,7 @@
[your_program] [[4],5]
[stage-3] Test passed.

[stage-2] Running tests for Stage #2: bencode-int
[stage-2] Running tests for Stage #2: eb4
[stage-2] Running ./your_bittorrent.sh decode i177586623e
[your_program] 177586623
[stage-2] Running ./your_bittorrent.sh decode i4294967300e
Expand All @@ -147,7 +147,7 @@
[your_program] -52
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: bencode-string
[stage-1] Running tests for Stage #1: ns2
[stage-1] Running ./your_bittorrent.sh decode 4:pear
[your_program] "pear"
[stage-1] Running ./your_bittorrent.sh decode 55:http://bittorrent-test-tracker.codecrafters.io/announce
Expand Down
22 changes: 11 additions & 11 deletions internal/tester_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@ var testerDefinition = tester_definition.TesterDefinition{
ExecutableFileName: "your_bittorrent.sh",
TestCases: []tester_definition.TestCase{
{
Slug: "bencode-string",
Slug: "ns2",
TestFunc: testBencodeString,
},
{
Slug: "bencode-int",
Slug: "eb4",
TestFunc: testBencodeInt,
},
{
Slug: "bencode-list",
Slug: "ah1",
TestFunc: testBencodeList,
},
{
Slug: "bencode-dict",
Slug: "mn6",
TestFunc: testBencodeDict,
},
{
Slug: "parse-torrent",
Slug: "ow9",
TestFunc: testParseTorrent,
},
{
Slug: "infohash",
Slug: "rb2",
TestFunc: testInfoHash,
},
{
Slug: "hashes",
Slug: "bf7",
TestFunc: testPieceHashes,
},
{
Slug: "peers",
Slug: "fi9",
TestFunc: testDiscoverPeers,
},
{
Slug: "handshake",
Slug: "ca4",
TestFunc: testHandshake,
},
{
Slug: "dl-piece",
Slug: "nd2",
TestFunc: testDownloadPiece,
},
{
Slug: "dl-file",
Slug: "jv8",
TestFunc: testDownloadFile,
Timeout: 90 * time.Second,
},
Expand Down

0 comments on commit 26db4ad

Please sign in to comment.