multinet/default_test.go
Dmitrii Stepanov ee601a7b5f [#3] dialer: Add default dialer.
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-11-02 13:25:54 +03:00

29 lines
607 B
Go

//go:build integration
package multinet
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestDefaultDialer(t *testing.T) {
srv := startHTTP(t)
defer require.NoError(t, srv.Close())
conn, err := Dial("tcp", "localhost:8080")
require.NoError(t, err)
require.NoError(t, conn.Close())
}
func startHTTP(t *testing.T) *http.Server {
srv := &http.Server{Addr: ":8080"}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Test stub") })
go func() {
require.ErrorIs(t, srv.ListenAndServe(), http.ErrServerClosed)
}()
return srv
}