forked from vulncheck-oss/sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
indices_test.go
41 lines (30 loc) · 895 Bytes
/
indices_test.go
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
34
35
36
37
38
39
40
41
package sdk
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetIndices(t *testing.T) {
req := httptest.NewRequest("GET", "/index", nil)
w := httptest.NewRecorder()
mockJson := `{"_benchmark":0.02508,"data":[{"name":"a10","description":"A10 Networks Security Advisories","href":"https://api.vulncheck.com/v3/index/a10"}]}`
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, mockJson)
})
handler.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, 200, resp.StatusCode)
body, _ := io.ReadAll(resp.Body)
var indexResp IndicesResponse
err := json.Unmarshal(body, &indexResp)
if err != nil {
t.Error("error unmarshalling response")
}
t.Run("indexes response is parsed", func(t *testing.T) {
assert.Equal(t, "a10", indexResp.Data[0].Name)
})
}