Accountant: Inventar, where, Checkmk, Abrechnung
This commit is contained in:
1 parent
9f16148cde
commit
dd93277750
59 files changed
+7522
-113
No files matched your search
@@ -38,6 +38,7 @@ func newFakeEngine(t *testing.T, handler func(w http.ResponseWriter, r *http.Req
|
||||
handler(w, r)
|
||||
})
|
||||
mux.HandleFunc("/containers/{id}/json", handler)
|
||||
mux.HandleFunc("/info", handler)
|
||||
mux.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) {
|
||||
f.lastQ <- r.URL.RawQuery
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -199,3 +200,63 @@ func TestEvents_StreamEnds(t *testing.T) {
|
||||
t.Error("erwartet Fehler bei beendetem Stream")
|
||||
}
|
||||
}
|
||||
|
||||
// Inspect liefert Ports (auch gestoppter Container), Startzeit und
|
||||
// Health-Status in einem Aufruf.
|
||||
func TestInspect(t *testing.T) {
|
||||
f := newFakeEngine(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.PathValue("id") {
|
||||
case "abc":
|
||||
w.Write([]byte(`{"Id":"abc","State":{"Status":"running","StartedAt":"2026-10-16T08:15:30.123456789Z",
|
||||
"Health":{"Status":"healthy"}},
|
||||
"HostConfig":{"PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"9080"}]}}}`))
|
||||
case "nie":
|
||||
// Nie gestartet, kein Healthcheck: Docker liefert die Nullzeit.
|
||||
w.Write([]byte(`{"Id":"nie","State":{"Status":"created","StartedAt":"0001-01-01T00:00:00Z"},"HostConfig":{}}`))
|
||||
default:
|
||||
http.Error(w, `{"message":"No such container"}`, http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
c := &Client{Socket: f.path}
|
||||
got, err := c.Inspect(context.Background(), "abc")
|
||||
if err != nil {
|
||||
t.Fatalf("Inspect: %v", err)
|
||||
}
|
||||
want := Details{
|
||||
Ports: []Port{{PrivatePort: 80, PublicPort: 9080, Type: "tcp"}},
|
||||
StartedAt: time.Date(2026, 10, 16, 8, 15, 30, 123456789, time.UTC),
|
||||
Health: "healthy",
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("Inspect =\n%+v\nerwartet\n%+v", got, want)
|
||||
}
|
||||
got, err = c.Inspect(context.Background(), "nie")
|
||||
if err != nil {
|
||||
t.Fatalf("Inspect: %v", err)
|
||||
}
|
||||
if !got.StartedAt.IsZero() || got.Health != "" || len(got.Ports) != 0 {
|
||||
t.Errorf("nie gestartet: %+v", got)
|
||||
}
|
||||
if _, err := c.Inspect(context.Background(), "weg"); err == nil || !strings.Contains(err.Error(), "404") {
|
||||
t.Errorf("unbekannter Container: %v", err)
|
||||
}
|
||||
if _, err := c.Inspect(context.Background(), "../x"); err == nil {
|
||||
t.Error("ungültige ID akzeptiert")
|
||||
}
|
||||
}
|
||||
|
||||
// Info liefert das Betriebssystem des Hosts (nicht des Agent-Containers) und
|
||||
// die Docker-Version.
|
||||
func TestInfo(t *testing.T) {
|
||||
f := newFakeEngine(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(`{"Name":"webdocker11","OperatingSystem":"Debian GNU/Linux 13 (trixie)","ServerVersion":"29.8.2","NCPU":4}`))
|
||||
})
|
||||
got, err := (&Client{Socket: f.path}).Info(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("Info: %v", err)
|
||||
}
|
||||
want := Info{Name: "webdocker11", OperatingSystem: "Debian GNU/Linux 13 (trixie)", ServerVersion: "29.8.2"}
|
||||
if got != want {
|
||||
t.Errorf("Info = %+v, erwartet %+v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user