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
|
package service_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -18,3 +21,22 @@ func shutdown() {
|
|||||||
panic(err)
|
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
|
package service_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/foomo/keel"
|
"github.com/foomo/keel"
|
||||||
"github.com/foomo/keel/service"
|
"github.com/foomo/keel/service"
|
||||||
@ -26,13 +23,8 @@ func ExampleNewHTTP() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if _, err := net.DialTimeout("tcp", "localhost:8080", 10*time.Second); err != nil {
|
waitFor("localhost:8080")
|
||||||
panic(err.Error())
|
l.Info(httpGet("http://localhost:8080"))
|
||||||
}
|
|
||||||
resp, _ := http.Get("http://localhost:8080") //nolint:noctx
|
|
||||||
defer resp.Body.Close() //nolint:govet
|
|
||||||
b, _ := io.ReadAll(resp.Body)
|
|
||||||
l.Info(string(b))
|
|
||||||
shutdown()
|
shutdown()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,6 @@ package service_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@ -68,10 +66,8 @@ func ExampleNewHTTPReadme() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
resp, _ := http.Get("http://localhost:9001/readme") //nolint:noctx
|
waitFor("localhost:9001")
|
||||||
defer resp.Body.Close() //nolint:govet
|
l.Info(httpGet("http://localhost:9001/readme"))
|
||||||
b, _ := io.ReadAll(resp.Body)
|
|
||||||
fmt.Print(string(b))
|
|
||||||
shutdown()
|
shutdown()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user