aboutsummaryrefslogtreecommitdiff
path: root/web/flux/flux_test.go
blob: 2be721244af8aa85468638acd877b19f3cc8bc4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package flux

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

// Mock server for testing
func mockServer() *httptest.Server {
	handler := http.NewServeMux()
	handler.HandleFunc("/health-check", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		w.Write([]byte(`{"status":"ok"}`))
	})
	return httptest.NewServer(handler)
}

func TestHealthCheck(t *testing.T) {
	server := mockServer()
	defer server.Close()

	client := NewClient(server.URL)
	healthResp, err := client.HealthCheck()
	if err != nil {
		t.Fatalf("expected no error, got %v", err)
	}

	if healthResp.Status != "ok" {
		t.Fatalf("expected status 'ok', got %v", healthResp.Status)
	}
}