Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andreburgaud/meetup-golang-httpexpect
Go code and examples used during the GoMN meetup on 6/19/2021
https://github.com/andreburgaud/meetup-golang-httpexpect
api go golang http meetup server talk testing web
Last synced: 30 days ago
JSON representation
Go code and examples used during the GoMN meetup on 6/19/2021
- Host: GitHub
- URL: https://github.com/andreburgaud/meetup-golang-httpexpect
- Owner: andreburgaud
- Created: 2021-06-14T22:06:54.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-26T01:38:48.000Z (about 2 years ago)
- Last Synced: 2024-08-03T23:19:07.237Z (4 months ago)
- Topics: api, go, golang, http, meetup, server, talk, testing, web
- Language: Go
- Homepage: https://www.meetup.com/golangmn/events/278773494/
- Size: 657 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-golang-repositories - meetup-golang-httpexpect
README
# GoMN Meetup - httpexpect
## Folders Description
* `1_gotesting`: Golang tests (no server involved) of an Add function using table driven data and subtests
* `2_go_web_servers`: Different approaches of serving HTTP requests using the Golang builtin `net/http` package
* server1: Define a HTTP Handler and use ServeHTTP
* server2: Convert a function to HTTP handler using `http.HandlerFunc`
* server3: Convert a function implicitly to `http.HandlerFunc`
* server4: Use `http.HandleFunc` to register functions as HTTP handlers* `3_httptest`: Examples using `net/http/httptest`
* `4_httpexpect`: Examples using `httpexpect`
* `add_server`: testing of the Add function served via HTTP
* `fastapi`: testing of a FastAPI server using Golang and `httpexpect`
* `self_contained`: server and test in the same file
* `separate_processes`: test a server started as a separate process* `slides`: Presentation slides in PDF format
## FastAPI Example
FastAPI is a Python high performance web framework compatible with Python 3.6+
To execute the FastAPI server in directory `4_httpexpect/fastapi/web` you first need to prepare a Python virtual environment. The instructions below assume that you have Python 3 installed:
```
$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install fastapi[all] # only once
$ uvicorn main:app
```The installation of fastapi is done only once. Subsequently, the folloing should be sufficient to activate the environment and start the web server:
```
$ . .venv/bin/activate
$ uvicorn main:app
```The `Makefile` included in the same folder shows other options to start the server.
After starting the server, you can point your browser to http://localhost:8000/docs to display the Swagger UI.
To test using `httpexpect`, in the directory `4_httpexpect/fastapi/test`, execute the following command:
```
$ go test -v
```The test folder is a Go mod project. If you experience any error related to the `httpexpect`, fetch the package manually with the followng command, and execute the test again:
```
$ go get github.com/gavv/httpexpect/v2
```## Resources
* https://github.com/gavv/httpexpect
* https://www.meetup.com/golangmn/events/278773494/
* https://tech.spscommerce.com/2021/06/11/andre-burgaud-presents.html