summaryrefslogtreecommitdiff
path: root/registry-scanner
diff options
context:
space:
mode:
authorIshita Sequeira <46771830+ishitasequeira@users.noreply.github.com>2025-01-06 16:38:22 -0500
committerGitHub <noreply@github.com>2025-01-06 16:38:22 -0500
commit5ae9a451b57d74ae4d25127040f25d369df4a47e (patch)
tree8a057529c01f3140e0059ff86e8d5637599ef6ca /registry-scanner
parentd07cf716e6609b2fa466649af26b948736d1f3c9 (diff)
move pkg/health out of registry-scanner (#995)
Signed-off-by: Ishita Sequeira <ishiseq29@gmail.com>
Diffstat (limited to 'registry-scanner')
-rw-r--r--registry-scanner/pkg/health/health.go25
-rw-r--r--registry-scanner/pkg/health/health_test.go52
2 files changed, 0 insertions, 77 deletions
diff --git a/registry-scanner/pkg/health/health.go b/registry-scanner/pkg/health/health.go
deleted file mode 100644
index cbc4977..0000000
--- a/registry-scanner/pkg/health/health.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package health
-
-// Most simple health check probe to see whether our server is still alive
-
-import (
- "fmt"
- "net/http"
-
- "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
-)
-
-func StartHealthServer(port int) chan error {
- errCh := make(chan error)
- go func() {
- sm := http.NewServeMux()
- sm.HandleFunc("/healthz", HealthProbe)
- errCh <- http.ListenAndServe(fmt.Sprintf(":%d", port), sm)
- }()
- return errCh
-}
-
-func HealthProbe(w http.ResponseWriter, r *http.Request) {
- log.Tracef("/healthz ping request received, replying with pong")
- fmt.Fprintf(w, "OK\n")
-}
diff --git a/registry-scanner/pkg/health/health_test.go b/registry-scanner/pkg/health/health_test.go
deleted file mode 100644
index b5670f5..0000000
--- a/registry-scanner/pkg/health/health_test.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package health
-
-import (
- "fmt"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-)
-
-// Unit test function
-func TestStartHealthServer_InvalidPort(t *testing.T) {
- // Use an invalid port number
- port := -1
- errCh := StartHealthServer(port)
- defer close(errCh) // Close the error channel after the test completes
- select {
- case err := <-errCh:
- if err == nil {
- t.Error("Expected error, got nil")
- } else if err.Error() != fmt.Sprintf("listen tcp: address %d: invalid port", port) {
- t.Errorf("Expected error message about invalid port, got %v", err)
- }
- case <-time.After(2 * time.Second):
- t.Error("Timed out waiting for error")
- }
-}
-
-func TestHealthProbe(t *testing.T) {
- // Create a mock HTTP request
- req, err := http.NewRequest("GET", "/healthz", nil)
- if err != nil {
- t.Fatalf("Failed to create request: %v", err)
- }
-
- // Create a mock HTTP response recorder
- w := httptest.NewRecorder()
-
- // Call the HealthProbe function directly
- HealthProbe(w, req)
-
- // Check the response status code
- if w.Code != http.StatusOK {
- t.Errorf("Expected status OK; got %d", w.Code)
- }
-
- // Check the response body
- expectedBody := "OK\n"
- if body := w.Body.String(); body != expectedBody {
- t.Errorf("Expected body %q; got %q", expectedBody, body)
- }
-}