Skip to content

Commit

Permalink
test: extend test for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sehat1137 committed Nov 24, 2024
1 parent 80e7412 commit 01960d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/docs/en/getting-started/asgi.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ It does nothing but launch the app itself as an **ASGI lifespan**.
faststream run main:app --workers 4
```
```shell
gunicorn -k uvicorn.workers.UvicornWorker main:app --workers=4
gunicorn -k uvicorn.workers.UvicornWorker main:app --workers=4
```
```shell
granian --interface asgi main:app --workers 4
Expand Down Expand Up @@ -186,8 +186,8 @@ app.mount("/asyncapi", make_asyncapi_asgi(FastStream(broker)))
```

!!! tip
You can also bind to unix domain or a file descriptor. FastStream will bind to “127.0.0.1:8000” by default
You can also bind to unix domain or a file descriptor. FastStream will bind to “127.0.0.1:8000” by default

```shell
faststream run main:app --bind unix:/tmp/socket.sock
```
Expand Down
6 changes: 4 additions & 2 deletions faststream/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ def load_config(_self: BaseApplication) -> None:
)

def init(
_self: ASGIRunner, asgi_app: "ASGIApp", options: Dict[str, Any]
) -> None: # type: ignore[valid-type]
_self: ASGIRunner, # type: ignore[valid-type]
asgi_app: "ASGIApp",
options: Dict[str, Any],
) -> None:
_self.options = options # type: ignore[attr-defined]
_self.asgi_app = asgi_app # type: ignore[attr-defined]
super(ASGIRunner, _self).__init__() # type: ignore[arg-type]
Expand Down
16 changes: 15 additions & 1 deletion tests/cli/utils/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from faststream.cli.utils.parser import parse_cli_args
from faststream.cli.utils.parser import is_bind_arg, parse_cli_args

APPLICATION = "module:app"

Expand Down Expand Up @@ -52,3 +52,17 @@ def test_custom_argument_parsing(args: Tuple[str]):
"k7": ["1", "2", "3"],
"bind": ["[::]:8000", "0.0.0.0:8000", "fd://2"],
}


@pytest.mark.parametrize(
"args", ["0.0.0.0:8000", "[::]:8000", "fd://2", "unix:/tmp/socket.sock"]
)
def test_bind_arg(args: str):
assert is_bind_arg(args) is True


@pytest.mark.parametrize(
"args", ["main:app", "src.main:app", "examples.nats.e01_basic:app2"]
)
def test_not_bind_arg(args: str):
assert is_bind_arg(args) is False

0 comments on commit 01960d8

Please sign in to comment.