chore: initialize containerized Go learning workbook (2026 DevOps/SRE)

This commit is contained in:
soda64 committed 2026-11-30 23:03:31 +01:00
commit 84be3e5d77
64 files changed
+1382

No files matched your search

@@ -0,0 +1,40 @@
package observability
import (
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
)
func TestFormatPrometheusCounter(t *testing.T) {
out := FormatPrometheusCounter("http_requests_total", "Total HTTP requests", 42)
for _, want := range []string{
"# HELP http_requests_total Total HTTP requests",
"# TYPE http_requests_total counter",
"http_requests_total 42",
} {
if !strings.Contains(out, want) {
t.Errorf("missing %q in:\n%s", want, out)
}
}
}
func TestReadinessHandler(t *testing.T) {
var ready atomic.Bool
h := ReadinessHandler(&ready)
rec1 := httptest.NewRecorder()
h(rec1, httptest.NewRequest(http.MethodGet, "/readyz", nil))
if rec1.Code != http.StatusServiceUnavailable {
t.Fatalf("got %d, want 503", rec1.Code)
}
ready.Store(true)
rec2 := httptest.NewRecorder()
h(rec2, httptest.NewRequest(http.MethodGet, "/readyz", nil))
if rec2.Code != http.StatusOK {
t.Fatalf("got %d, want 200", rec2.Code)
}
}