mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
CI: move grabpl e2e tests from grabpl to grafana (#53075)
* move grabpl e2e tests
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package e2eutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const timeout = 60
|
||||
|
||||
type GrafanaServer struct {
|
||||
Port int
|
||||
Host string
|
||||
}
|
||||
|
||||
func Server(host string, port int) *GrafanaServer {
|
||||
return &GrafanaServer{
|
||||
Host: host,
|
||||
Port: port,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GrafanaServer) Wait() {
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
timeoutExceeded := time.After(timeout * time.Second)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-timeoutExceeded:
|
||||
log.Printf("grafana server failed to start after %d second(s) timeout", timeout)
|
||||
os.Exit(1)
|
||||
|
||||
case <-ticker.C:
|
||||
url := fmt.Sprintf("http://%s:%d", g.Host, g.Port)
|
||||
//nolint:gosec
|
||||
resp, err := http.Get(url)
|
||||
if err == nil {
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Printf("failed to read response body: %q", err)
|
||||
return
|
||||
}
|
||||
log.Println("connected to grafana-server!")
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
log.Printf("status code: %d, body: %s, exiting...", resp.StatusCode, string(body))
|
||||
os.Exit(1)
|
||||
}
|
||||
err = resp.Body.Close()
|
||||
if err != nil {
|
||||
log.Printf("error closing response body, body: %s", string(body))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Printf("failed attempt to connect to grafana-server on url %s, retrying...", url)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user