MCPcopy Create free account
hub / github.com/andrey-vk/wdbgp / TestJavaScriptAdapterNormalizesResult

Function TestJavaScriptAdapterNormalizesResult

internal/feeds/feeds_test.go:80–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78 }
79}
80
81func TestJavaScriptAdapterNormalizesResult(t *testing.T) {
82 client := &http.Client{Transport: roundTripFunc(func(request *http.Request) (*http.Response, error) {
83 if request.URL.String() != "https://example.test/feed" {
84 t.Fatalf("request URL = %q", request.URL)
85 }
86 return &http.Response{
87 StatusCode: http.StatusOK,
88 Body: io.NopCloser(strings.NewReader(`["149.154.167.99/20"]`)),
89 Header: make(http.Header),
90 }, nil
91 })}
92 entries, err := (feedRunner{limits: testLimits(), client: client, timeout: time.Second}).run(
93 context.Background(),
94 store.Feed{ID: 1, Name: "test", URL: "https://example.test/feed"},
95 store.FeedAdapter{
96 APIVersion: 1, Source: `
97function sync(feed, api) {
98 return [{
99 category: "Messengers",
100 service: "Telegram",
101 cidrs: JSON.parse(api.httpGet(feed.url))
102 }];
103}`,
104 },
105 )
106 if err != nil {
107 t.Fatal(err)
108 }
109 if len(entries) != 1 || entries[0].CIDR != "149.154.160.0/20" {
110 t.Fatalf("entries = %#v", entries)
111 }
112}
113
114func TestJavaScriptAdapterSRSGet(t *testing.T) {

Callers

nothing calls this directly

Calls 4

roundTripFuncFuncType · 0.85
testLimitsFunction · 0.85
runMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected