feat: improve python actions (#1083)

This commit is contained in:
Jonas Plum
2024-07-21 02:56:43 +02:00
committed by GitHub
parent 81bfbb2072
commit 91429effe2
55 changed files with 1143 additions and 585 deletions

37
testing/http.go Normal file
View File

@@ -0,0 +1,37 @@
package testing
import (
"context"
"errors"
"net/http"
"time"
)
func WaitForStatus(url string, status int, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
start := time.Now()
for {
if time.Since(start) > timeout {
return errors.New("timeout")
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return err
}
resp, err := http.DefaultClient.Do(req)
if err == nil && resp.StatusCode == status {
resp.Body.Close()
break
}
time.Sleep(100 * time.Millisecond)
}
return nil
}