https://github.com/monkrus/go-fibonacci
HTTP Server testing in Go
https://github.com/monkrus/go-fibonacci
go golang http http-server testify
Last synced: 6 months ago
JSON representation
HTTP Server testing in Go
- Host: GitHub
- URL: https://github.com/monkrus/go-fibonacci
- Owner: monkrus
- Created: 2020-03-30T14:49:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-31T05:19:27.000Z (about 6 years ago)
- Last Synced: 2024-05-01T14:38:58.842Z (about 2 years ago)
- Topics: go, golang, http, http-server, testify
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-fibonacci
HTTP Server testing in Go
1. Fibonacci function: In the sequence of x,y,z numbers number z returns the sum of x+y.
Our webserver returns the fibonacci sequence (or error) for any given number.
# SETUP
2. Create an endpoint (HandleFunc, "/fib", server by handleFib function )
3. Start a server 8080 (ListenAndServe)
4. Write a "Response-Request" function. We are getting a `num` parameter from request.(FormValue function)
5. Need to convert into `int` since function takes `int` (FormValue)
6. Atoi function returns `int` or error (StatusBadRequest)
7. If convertion is good, returns a line
8. Converting again: io.WriteString (int-->line)
10. Define Fib function
11. Create cache and initialize it with init function.
# TESTING
1. Testing function Handle Fib (using HTTPPIE, curl etc.)
2. Not testing a server, just a HandleFib function
3. Http test has recorder
4. Write test cases. We use `bytes` since response comes in bytes.
5. Handler returns --serve http-->fake request
6. Add cycle
7. http->recorder
8. Fake request (GET, sprintf)
9. Call ServeHTTP
-assert
-body ->returns bytes
-code status