Skip to content

monkrus/go-fibonacci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Create an endpoint (HandleFunc, "/fib", server by handleFib function )

  2. Start a server 8080 (ListenAndServe)

  3. Write a "Response-Request" function. We are getting a num parameter from request.(FormValue function)

  4. Need to convert into int since function takes int (FormValue)

  5. Atoi function returns int or error (StatusBadRequest)

  6. If convertion is good, returns a line

  7. Converting again: io.WriteString (int-->line)

  8. Define Fib function

  9. 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

Releases

No releases published

Packages

No packages published

Languages