samedi 27 décembre 2014

kill running process in test golang

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


Aucun commentaire:

Enregistrer un commentaire