All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1021 B
Go
43 lines
1021 B
Go
package buildinfo
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandlerOK(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
|
rec := httptest.NewRecorder()
|
|
Handler().ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("code=%d", rec.Code)
|
|
}
|
|
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
|
|
t.Fatalf("content-type=%q", ct)
|
|
}
|
|
var body Response
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if body.Status != "ok" || body.Name != Name || body.Description == "" {
|
|
t.Fatalf("unexpected body: %+v", body)
|
|
}
|
|
if len(body.Tags) == 0 {
|
|
t.Fatal("expected tags")
|
|
}
|
|
if body.Build.Commit == "" {
|
|
t.Fatal("expected commit")
|
|
}
|
|
}
|
|
|
|
func TestHandlerMethodNotAllowed(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodPost, "/healthz", nil)
|
|
rec := httptest.NewRecorder()
|
|
Handler().ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusMethodNotAllowed {
|
|
t.Fatalf("code=%d", rec.Code)
|
|
}
|
|
}
|