a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package contracts
|
|
|
|
import "testing"
|
|
|
|
// TestHTTPExtractor_Express_InlineArrowAnchor verifies that a route whose
|
|
// handler is an inline arrow anchors its Contract SymbolID to the synthetic
|
|
// express-handler node the JS extractor materialises (the through-handler
|
|
// call-attribution anchor), so a trace from the route reaches the services
|
|
// the anonymous handler calls.
|
|
func TestHTTPExtractor_Express_InlineArrowAnchor(t *testing.T) {
|
|
src := []byte("app.get('/u', (req, res) => { svc.list(); res.json({}); });\n")
|
|
ext := &HTTPExtractor{}
|
|
cs := ext.Extract("routes.js", src, nil, nil)
|
|
|
|
var get *Contract
|
|
for i := range cs {
|
|
if cs[i].ID == "http::GET::/u" {
|
|
get = &cs[i]
|
|
}
|
|
}
|
|
if get == nil {
|
|
t.Fatalf("no route contract for GET /u; got %+v", cs)
|
|
}
|
|
if get.SymbolID != "routes.js::express-handler@1" {
|
|
t.Errorf("inline-arrow route SymbolID = %q (want routes.js::express-handler@1)", get.SymbolID)
|
|
}
|
|
}
|
|
|
|
// TestHTTPExtractor_Express_NamedHandlerUnchanged confirms the inline anchor
|
|
// does not disturb named-handler binding.
|
|
func TestHTTPExtractor_Express_NamedHandlerUnchanged(t *testing.T) {
|
|
src := []byte("app.get('/named', listUsers);\n")
|
|
nodes := makeNodes("routes.js", []struct {
|
|
name string
|
|
start, end int
|
|
}{{"listUsers", 1, 1}})
|
|
ext := &HTTPExtractor{}
|
|
cs := ext.Extract("routes.js", src, nodes, nil)
|
|
|
|
for _, c := range cs {
|
|
if c.ID == "http::GET::/named" && c.SymbolID != "routes.js::listUsers" {
|
|
t.Errorf("named handler SymbolID = %q (want routes.js::listUsers)", c.SymbolID)
|
|
}
|
|
}
|
|
}
|