Deploy managed portal with Docker

This commit is contained in:
Yoilun
2026-05-07 17:58:26 +08:00
parent 74d1e72591
commit be5014c582
15 changed files with 350 additions and 39 deletions

View File

@@ -4,10 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"strings"
"testing"
"time"
)
type roundTripFunc func(req *http.Request) (*http.Response, error)
@@ -139,3 +141,37 @@ func TestRemoteClientRoundTrip(t *testing.T) {
t.Fatalf("Content-Disposition = %q", resp.Header.Get("Content-Disposition"))
}
}
func TestRemoteClientRetriesTransientRequestErrors(t *testing.T) {
t.Parallel()
attempts := 0
client := NewRemoteClient(&http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
attempts++
if attempts < 3 {
return nil, errors.New("connect: connection refused")
}
return &http.Response{
StatusCode: http.StatusOK,
Header: make(http.Header),
Body: io.NopCloser(strings.NewReader(`{"config_path":"/srv/store/config/local.yaml"}`)),
}, nil
})})
client.retryDelay = time.Millisecond
service := Service{
ID: "store_dwell_alert",
APIBaseURL: "http://managed.invalid/store",
}
configPayload, err := client.GetConfig(context.Background(), service)
if err != nil {
t.Fatalf("GetConfig() error = %v", err)
}
if attempts != 3 {
t.Fatalf("attempts = %d", attempts)
}
if got := configPayload["config_path"]; got != "/srv/store/config/local.yaml" {
t.Fatalf("config_path = %#v", got)
}
}