build - prozess optimiert mit push nach zot

nginx-kill - > maint. site...
This commit is contained in:
br committed 2026-10-03 12:44:45 +02:00
1 parent 665135f87e
commit 64417d8353
19 files changed
+447 -61

No files matched your search

+48 -1
View File
@@ -33,7 +33,11 @@ func newFakeEngine(t *testing.T, handler func(w http.ResponseWriter, r *http.Req
t.Fatal(err)
}
mux := http.NewServeMux()
mux.HandleFunc("/containers/json", handler)
mux.HandleFunc("/containers/json", func(w http.ResponseWriter, r *http.Request) {
f.lastQ <- r.URL.RawQuery
handler(w, r)
})
mux.HandleFunc("/containers/{id}/json", handler)
mux.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
f.lastQ <- r.URL.RawQuery
w.Header().Set("Content-Type", "application/json")
@@ -75,6 +79,10 @@ func TestList(t *testing.T) {
if err != nil {
t.Fatalf("List: %v", err)
}
// Auch gestoppte Container: Sie werden zur Wartungsseite statt zu 404.
if q := <-f.lastQ; q != "all=1" {
t.Errorf("Query = %q, erwartet all=1", q)
}
want := []Container{
{
ID: "abc", Names: []string{"/wordpress"}, State: "running",
@@ -91,6 +99,45 @@ func TestList(t *testing.T) {
}
}
// Gestoppte Container haben in /containers/json keine Ports; die
// Zuordnung steht in HostConfig.PortBindings.
func TestPortBindings(t *testing.T) {
f := newFakeEngine(t, func(w http.ResponseWriter, r *http.Request) {
if r.PathValue("id") != "abc" {
http.Error(w, `{"message":"No such container"}`, http.StatusNotFound)
return
}
w.Write([]byte(`{"Id":"abc","State":{"Status":"exited"},"HostConfig":{"PortBindings":{
"80/tcp":[{"HostIp":"","HostPort":"9080"},{"HostIp":"::","HostPort":"9080"}],
"443/tcp":[{"HostIp":"127.0.0.1","HostPort":"9443"}],
"53/udp":[{"HostIp":"","HostPort":"5353"}],
"8080/tcp":[{"HostIp":"","HostPort":""}],
"9000/tcp":null}}}`))
})
c := &Client{Socket: f.path}
got, err := c.PortBindings(context.Background(), "abc")
if err != nil {
t.Fatalf("PortBindings: %v", err)
}
want := []Port{
{IP: "127.0.0.1", PrivatePort: 443, PublicPort: 9443, Type: "tcp"},
{IP: "", PrivatePort: 53, PublicPort: 5353, Type: "udp"},
{IP: "", PrivatePort: 80, PublicPort: 9080, Type: "tcp"},
{IP: "::", PrivatePort: 80, PublicPort: 9080, Type: "tcp"},
{IP: "", PrivatePort: 8080, Type: "tcp"}, // Host-Port erst beim Start vergeben
{IP: "", PrivatePort: 9000, Type: "tcp"},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("PortBindings =\n%+v\nerwartet\n%+v", got, want)
}
if _, err := c.PortBindings(context.Background(), "weg"); err == nil || !strings.Contains(err.Error(), "404") {
t.Errorf("unbekannter Container: %v", err)
}
if _, err := c.PortBindings(context.Background(), "../x"); err == nil {
t.Error("ungültige ID akzeptiert")
}
}
func TestList_Errors(t *testing.T) {
f := newFakeEngine(t, func(w http.ResponseWriter, r *http.Request) {
http.Error(w, `{"message":"kaputt"}`, http.StatusInternalServerError)