Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions pkg/helm/actions/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions
import (
"fmt"
"io"
"net"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -129,7 +130,12 @@ func setupTestWithTls() error {
if err := ExecuteScript("./testdata/downloadHelm.sh", true); err != nil {
return err
}
time.Sleep(5 * time.Second)
if err := waitForTCP("localhost:9443", 30*time.Second); err != nil {
return fmt.Errorf("chartmuseum TLS not ready: %w", err)
}
if err := waitForTCP("localhost:5443", 30*time.Second); err != nil {
return fmt.Errorf("zot TLS not ready: %w", err)
}
if err := ExecuteScript("./testdata/cacertCreate.sh", true); err != nil {
return err
}
Expand All @@ -149,7 +155,12 @@ func setupTestWithoutTls() error {
if err := ExecuteScript("./testdata/zotWithoutTls.sh", false); err != nil {
return err
}
time.Sleep(5 * time.Second)
if err := waitForTCP("localhost:9181", 30*time.Second); err != nil {
return fmt.Errorf("chartmuseum no-TLS not ready: %w", err)
}
if err := waitForTCP("localhost:5000", 30*time.Second); err != nil {
return fmt.Errorf("zot no-TLS not ready: %w", err)
}
if err := ExecuteScript("./testdata/uploadChartsWithoutTls.sh", true); err != nil {
return err
}
Expand All @@ -164,7 +175,9 @@ func setupTestBasicAuth() error {
if err := ExecuteScript("./testdata/chartmuseumWithBasicAuth.sh", false); err != nil {
return err
}
time.Sleep(5 * time.Second)
if err := waitForTCP("localhost:8181", 30*time.Second); err != nil {
return fmt.Errorf("chartmuseum basic-auth not ready: %w", err)
}
if err := ExecuteScript("./testdata/uploadChartsWithBasicAuth.sh", true); err != nil {
return err
}
Expand All @@ -175,13 +188,28 @@ func setupTestOCIBasicAuth() error {
if err := ExecuteScript("./testdata/zotWithBasicAuth.sh", false); err != nil {
return err
}
time.Sleep(5 * time.Second)
if err := waitForTCP("localhost:5001", 30*time.Second); err != nil {
return fmt.Errorf("zot basic-auth not ready: %w", err)
}
if err := ExecuteScript("./testdata/uploadOciCharts.sh", true, "--basic-auth"); err != nil {
return err
}
return nil
}

func waitForTCP(addr string, timeout time.Duration) error {
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
conn, err := net.DialTimeout("tcp", addr, time.Second)
if err == nil {
conn.Close()
return nil
}
time.Sleep(time.Second)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker.
Do we try each second? Or maybe 2-5 seconds each time?

}
return fmt.Errorf("timed out waiting for %s after %s", addr, timeout)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

func ExecuteScript(filepath string, waitForCompletion bool, args ...string) error {
tlsCmd := exec.Command(filepath, args...)
tlsCmd.Stdout = os.Stdout
Expand Down