Writing a program based on http.ListenAndServe
and writing the tests i've hit a stump. my test looks like this
package main
import (
"testing"
"../"
)
func TestServer(t *testing.T) {
Server.Server()
}
and the tested function
package Server
import (
"net/http"
)
var (
DefaultPort = "8080"
DefaultDir = "."
)
func Server() {
port := DefaultPort
directory := DefaultPort
http.ListenAndServe(":"+port, http.FileServer(http.Dir(directory)))
}
my goal is to be able to run test and after the server listener is launched kill it and return a success message
You can't. To be able to stop, you need to create Listener by hand
listener, err := net.Listen("http", ":"+port)
err=http.Serve(listener, http.FileServer(http.Dir(directory)))
then you can
err=listener.Close()