Files
substrate/internal/e2e/router_client_test.go
T
Lior Lieberman 4e462b05e1 egress: make verify-egress-demo.sh robust and executable
The gateway access-log assertion read the log once, immediately after curl
returned, and failed if it saw nothing new. That is racy twice over:

  * Envoy emits the CONNECT access-log entry asynchronously, so for an
    external destination it can land seconds after the actor's response.
  * The Actor's HTTP client keeps the tunnel alive. A repeat fetch to a host
    it already reached rides the open tunnel and produces no new entry at
    all, so a run against a warm actor failed even though egress was working.

Poll for the new entry, and fall back to any tunnel already open for this
actor's SAN before declaring failure. Also read -c envoy explicitly (the pod
also runs the ext-proc sidecar) and mark the script executable, as every other
directly-invoked script in hack/ is.
2026-08-10 23:28:07 -07:00

71 lines
2.2 KiB
Go

// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package e2e
import (
"context"
"io"
"net/http"
"strings"
"testing"
"github.com/agent-substrate/substrate/internal/resources"
)
func TestRouterClientPostJSON(t *testing.T) {
client := &RouterClient{
baseURL: "http://router.test",
http: &http.Client{Transport: testRoundTripper(func(request *http.Request) (*http.Response, error) {
if request.Method != http.MethodPost {
t.Errorf("method = %q, want POST", request.Method)
}
if request.Host != "fetcher.demo.actors.resources.substrate.ate.dev" {
t.Errorf("host = %q", request.Host)
}
if request.URL.Path != "/fetch" {
t.Errorf("path = %q, want /fetch", request.URL.Path)
}
if request.Header.Get("Content-Type") != "application/json" {
t.Errorf("content type = %q, want application/json", request.Header.Get("Content-Type"))
}
body, err := io.ReadAll(request.Body)
if err != nil {
t.Fatalf("reading body: %v", err)
}
if string(body) != `{"url":"https://example.com/"}` {
t.Errorf("body = %q", body)
}
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader("ok")),
Header: make(http.Header),
}, nil
})},
}
actorRef := resources.ActorRef{Atespace: "demo", Name: "fetcher"}
response, err := client.PostJSON(context.Background(), actorRef, "/fetch", []byte(`{"url":"https://example.com/"}`))
if err != nil {
t.Fatalf("PostJSON: %v", err)
}
response.Body.Close()
}
type testRoundTripper func(*http.Request) (*http.Response, error)
func (f testRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
return f(request)
}