mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
feat: extract helper
This commit is contained in:
parent
7fded0fa58
commit
8da81ee42e
@ -1,6 +1,9 @@
|
||||
package service_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
@ -18,3 +21,22 @@ func shutdown() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func waitFor(addr string) {
|
||||
if _, err := net.DialTimeout("tcp", addr, 10*time.Second); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func httpGet(url string) string {
|
||||
resp, err := http.Get(url) //nolint:all
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package service_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/foomo/keel"
|
||||
"github.com/foomo/keel/service"
|
||||
@ -26,13 +23,8 @@ func ExampleNewHTTP() {
|
||||
)
|
||||
|
||||
go func() {
|
||||
if _, err := net.DialTimeout("tcp", "localhost:8080", 10*time.Second); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
resp, _ := http.Get("http://localhost:8080") //nolint:noctx
|
||||
defer resp.Body.Close() //nolint:govet
|
||||
b, _ := io.ReadAll(resp.Body)
|
||||
l.Info(string(b))
|
||||
waitFor("localhost:8080")
|
||||
l.Info(httpGet("http://localhost:8080"))
|
||||
shutdown()
|
||||
}()
|
||||
|
||||
|
||||
@ -2,8 +2,6 @@ package service_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
@ -68,10 +66,8 @@ func ExampleNewHTTPReadme() {
|
||||
}))
|
||||
|
||||
go func() {
|
||||
resp, _ := http.Get("http://localhost:9001/readme") //nolint:noctx
|
||||
defer resp.Body.Close() //nolint:govet
|
||||
b, _ := io.ReadAll(resp.Body)
|
||||
fmt.Print(string(b))
|
||||
waitFor("localhost:9001")
|
||||
l.Info(httpGet("http://localhost:9001/readme"))
|
||||
shutdown()
|
||||
}()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user