This repository has been archived by the owner on Feb 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tests to include the newline added to txt files by precommit
- Loading branch information
1 parent
ffc62f8
commit f0f27de
Showing
7 changed files
with
141 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 5 | ||
environments: | ||
default: | ||
channels: | ||
- url: https://conda.anaconda.org/conda-forge/ | ||
- url: https://conda.modular.com/max-nightly/ | ||
packages: {} | ||
packages: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[project] | ||
authors = ["Mikhail Tavarez <[email protected]>"] | ||
channels = ["conda-forge", "https://conda.modular.com/max-nightly"] | ||
description = "Add a short description here" | ||
name = "gojo" | ||
platforms = ["osx-arm64"] | ||
version = "0.1.0" | ||
|
||
[tasks] | ||
test = "bash scripts/run_tests.sh" | ||
prepare-tests = "bash scripts/build.sh tests" | ||
package = "bash scripts/build.sh package" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
from gojo.net import Socket, TCPAddr, get_ip_address, listen_tcp, dial_tcp | ||
from gojo.syscall import SocketOptions, ProtocolFamily | ||
# from gojo.net import Socket, TCPAddr, get_ip_address, listen_tcp, dial_tcp | ||
# from gojo.syscall import SocketOptions, ProtocolFamily | ||
|
||
|
||
def test_dial(): | ||
# Connect to example.com on port 80 and send a GET request | ||
var connection = dial_tcp("tcp", TCPAddr(get_ip_address("www.example.com"), 80)) | ||
var bytes_written: Int = 0 | ||
var err = Error() | ||
bytes_written, err = connection.write( | ||
String("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n").as_bytes_slice() | ||
) | ||
if err: | ||
raise err | ||
# def test_dial(): | ||
# # Connect to example.com on port 80 and send a GET request | ||
# var connection = dial_tcp("tcp", TCPAddr(get_ip_address("www.example.com"), 80)) | ||
# var bytes_written: Int = 0 | ||
# var err = Error() | ||
# bytes_written, err = connection.write( | ||
# String("GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n").as_bytes_slice() | ||
# ) | ||
# if err: | ||
# raise err | ||
|
||
if bytes_written == 0: | ||
print("No bytes sent to peer.") | ||
return | ||
# if bytes_written == 0: | ||
# print("No bytes sent to peer.") | ||
# return | ||
|
||
# Read the response from the connection | ||
var response = List[UInt8, True](capacity=4096) | ||
var bytes_read: Int = 0 | ||
bytes_read, err = connection.read(response) | ||
if err: | ||
raise err | ||
# # Read the response from the connection | ||
# var response = List[UInt8, True](capacity=4096) | ||
# var bytes_read: Int = 0 | ||
# bytes_read, err = connection.read(response) | ||
# if err: | ||
# raise err | ||
|
||
if bytes_read == 0: | ||
print("No bytes received from peer.") | ||
return | ||
# if bytes_read == 0: | ||
# print("No bytes received from peer.") | ||
# return | ||
|
||
print(String(response)) | ||
# print(String(response)) | ||
|
||
# Cleanup the connection | ||
err = connection.close() | ||
if err: | ||
raise err | ||
# # Cleanup the connection | ||
# err = connection.close() | ||
# if err: | ||
# raise err | ||
|
||
|
||
def test_listener(): | ||
var listener = listen_tcp("tcp", TCPAddr("0.0.0.0", 8081)) | ||
while True: | ||
var conn = listener.accept() | ||
print("Accepted connection from", str(conn.remote_address())) | ||
var err = conn.close() | ||
if err: | ||
raise err | ||
# def test_listener(): | ||
# var listener = listen_tcp("tcp", TCPAddr("0.0.0.0", 8081)) | ||
# while True: | ||
# var conn = listener.accept() | ||
# print("Accepted connection from", str(conn.remote_address())) | ||
# var err = conn.close() | ||
# if err: | ||
# raise err | ||
|
||
|
||
# def test_stuff(): | ||
# # TODO: context manager not working yet | ||
# # with Socket() as socket: | ||
# # socket.bind("0.0.0.0", 8080) | ||
# # def test_stuff(): | ||
# # # TODO: context manager not working yet | ||
# # # with Socket() as socket: | ||
# # # socket.bind("0.0.0.0", 8080) | ||
|
||
# var socket = Socket(protocol=ProtocolFamily.PF_UNIX) | ||
# socket.bind("0.0.0.0", 8080) | ||
# socket.connect(get_ip_address("www.example.com"), 80) | ||
# print("File number", socket.file_no()) | ||
# var local = socket.get_sock_name() | ||
# var remote = socket.get_peer_name() | ||
# print("Local address", str(local), socket.local_address) | ||
# print("Remote address", str(remote), socket.remote_address) | ||
# socket.set_socket_option(SocketOptions.SO_REUSEADDR, 1) | ||
# print("REUSE_ADDR value", socket.get_socket_option(SocketOptions.SO_REUSEADDR)) | ||
# var timeout = 30 | ||
# # socket.set_timeout(timeout) | ||
# # print(socket.get_timeout()) | ||
# socket.shutdown() | ||
# print("closing") | ||
# var err = socket.close() | ||
# print("closed") | ||
# if err: | ||
# print("err returned") | ||
# raise err | ||
# # var option_value = socket.get_sock_opt(SocketOptions.SO_REUSEADDR) | ||
# # print(option_value) | ||
# # socket.connect(self.ip, self.port) | ||
# # socket.send(message) | ||
# # var response = socket.receive() # TODO: call receive until all data is fetched, receive should also just return bytes | ||
# # socket.shutdown() | ||
# # socket.close() | ||
# # var socket = Socket(protocol=ProtocolFamily.PF_UNIX) | ||
# # socket.bind("0.0.0.0", 8080) | ||
# # socket.connect(get_ip_address("www.example.com"), 80) | ||
# # print("File number", socket.file_no()) | ||
# # var local = socket.get_sock_name() | ||
# # var remote = socket.get_peer_name() | ||
# # print("Local address", str(local), socket.local_address) | ||
# # print("Remote address", str(remote), socket.remote_address) | ||
# # socket.set_socket_option(SocketOptions.SO_REUSEADDR, 1) | ||
# # print("REUSE_ADDR value", socket.get_socket_option(SocketOptions.SO_REUSEADDR)) | ||
# # var timeout = 30 | ||
# # # socket.set_timeout(timeout) | ||
# # # print(socket.get_timeout()) | ||
# # socket.shutdown() | ||
# # print("closing") | ||
# # var err = socket.close() | ||
# # print("closed") | ||
# # if err: | ||
# # print("err returned") | ||
# # raise err | ||
# # # var option_value = socket.get_sock_opt(SocketOptions.SO_REUSEADDR) | ||
# # # print(option_value) | ||
# # # socket.connect(self.ip, self.port) | ||
# # # socket.send(message) | ||
# # # var response = socket.receive() # TODO: call receive until all data is fetched, receive should also just return bytes | ||
# # # socket.shutdown() | ||
# # # socket.close() |