Add the shared packages for the sharks stack
model, tunnel, wg, authtoken, netguard, docker and dotenv, split out of the original single repository so Hammerhead, Blacktip and Bamboo can live in their own repos and import them. README extended; LICENSE unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c7c2ae8f8d
commit
2259580adf
16 files changed
+1359
-1
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListParsesContainers(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/containers/json" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Write([]byte(`[
|
||||
{"Id":"abcdef1234567890","Names":["/minecraft"],"Image":"itzg/minecraft-server","State":"running",
|
||||
"Ports":[{"PrivatePort":25565,"PublicPort":25565,"Type":"tcp"},{"PrivatePort":25565,"PublicPort":25565,"Type":"tcp"},{"PrivatePort":8123,"Type":"tcp"}],
|
||||
"NetworkSettings":{"Networks":{"bridge":{"IPAddress":"172.17.0.2"},"none":{"IPAddress":""}}}},
|
||||
{"Id":"1111","Names":["/db"],"Image":"postgres","State":"running","Ports":[],"NetworkSettings":{"Networks":{}}}
|
||||
]`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
t.Setenv("DOCKER_HOST", "tcp://"+strings.TrimPrefix(srv.URL, "http://"))
|
||||
|
||||
got, err := List(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 2 || got[0].Name != "db" || got[1].Name != "minecraft" {
|
||||
t.Fatalf("unexpected list: %+v", got)
|
||||
}
|
||||
mc := got[1]
|
||||
if mc.ID != "abcdef123456" || len(mc.Ports) != 2 || mc.Ports[0].Public != 25565 || mc.Ports[1].Public != 0 {
|
||||
t.Errorf("ports/id wrong: %+v", mc)
|
||||
}
|
||||
if mc.Networks["bridge"] != "172.17.0.2" || len(mc.Networks) != 1 {
|
||||
t.Errorf("networks wrong: %+v", mc.Networks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListUnreachable(t *testing.T) {
|
||||
t.Setenv("DOCKER_HOST", "tcp://127.0.0.1:1")
|
||||
if _, err := List(context.Background()); err == nil {
|
||||
t.Fatal("expected an error when docker is not running")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user