CI / changes (push) Successful in 5s
CI / openapi (push) Has been skipped
CI / go (push) Successful in 24s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, , evobgp-web) (push) Successful in 1m9s
CI / docker-web (deploy/docker/evobgp-web/Dockerfile, evobgp-all, evobgp-web-all) (push) Successful in 1m3s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 16s
CI / docker-go (deploy/docker/evobgp-agent/Dockerfile, , evobgp-agent) (push) Successful in 1m0s
CI / docker-go (evobgp-all, 1, deploy/docker/gobinary/Dockerfile, , evobgp-all) (push) Successful in 1m37s
CI / docker-go (evobgp-api, 1, deploy/docker/gobinary/Dockerfile, , evobgp-api) (push) Successful in 1m25s
CI / docker-go (evobgp-deploy, 0, deploy/docker/gobinary/Dockerfile, , evobgp-deploy) (push) Successful in 1m29s
CI / docker-go (evobgp-ingest, 0, deploy/docker/gobinary/Dockerfile, , evobgp-ingest) (push) Successful in 1m25s
CI / docker-go (evobgp-node, 0, deploy/docker/gobinary/Dockerfile, , evobgp-node) (push) Successful in 1m21s
CI / docker-go (evobgp-render, 0, deploy/docker/gobinary/Dockerfile, , evobgp-render) (push) Successful in 1m24s
CI / docker-go (evobgp-scheduler, 0, deploy/docker/gobinary/Dockerfile, , evobgp-scheduler) (push) Successful in 1m31s
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package asnresolve
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestAnnouncedPrefixes_Mock(t *testing.T) {
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Query().Get("resource") != "AS64496" {
|
|
t.Fatalf("resource: %q", r.URL.Query().Get("resource"))
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{"status":"ok","data":{"prefixes":[{"prefix":"203.0.113.0/24"},{"prefix":"2001:db8::/32"}]}}`))
|
|
}))
|
|
defer ts.Close()
|
|
|
|
t.Setenv("EVOBGP_RIPESTAT_ANNOUNCED_PREFIXES_URL", ts.URL)
|
|
t.Setenv("EVOBGP_ASN_RESOLVE_PAUSE_MS", "1")
|
|
|
|
pfx, err := AnnouncedPrefixes(context.Background(), ts.Client(), 64496)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(pfx) != 2 {
|
|
t.Fatalf("got %d prefixes", len(pfx))
|
|
}
|
|
if pfx[0].String() != "2001:db8::/32" || pfx[1].String() != "203.0.113.0/24" {
|
|
t.Fatalf("order or values: %#v", pfx)
|
|
}
|
|
}
|
|
|
|
func TestASHolderName_Mock(t *testing.T) {
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Query().Get("resource") != "AS64496" {
|
|
t.Fatalf("resource: %q", r.URL.Query().Get("resource"))
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{"status":"ok","data":{"holder":"Example Networks Ltd"}}`))
|
|
}))
|
|
defer ts.Close()
|
|
|
|
t.Setenv("EVOBGP_RIPESTAT_AS_OVERVIEW_URL", ts.URL)
|
|
|
|
name, err := ASHolderName(context.Background(), ts.Client(), 64496)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if name != "Example Networks Ltd" {
|
|
t.Fatalf("holder: %q", name)
|
|
}
|
|
}
|