31 lines
658 B
Go
31 lines
658 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestVulnCatalogEndpoint(t *testing.T) {
|
|
h := NewVulnHandler()
|
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/vuln/catalog", nil)
|
|
w := httptest.NewRecorder()
|
|
h.Catalog(w, req)
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("status %d", w.Code)
|
|
}
|
|
var body struct {
|
|
Catalog []struct {
|
|
ID string `json:"id"`
|
|
} `json:"catalog"`
|
|
Source string `json:"source"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if body.Source != "embedded" || len(body.Catalog) < 10 {
|
|
t.Fatalf("unexpected catalog response: %+v", body)
|
|
}
|
|
}
|