mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: refactor Events, Info, RegistryLogin
Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Austin Vazquez <austin.vazquez@docker.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
c438b3fbbf
commit
e46058cbae
@@ -740,10 +740,12 @@ func TestBuildEmitsImageCreateEvent(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
buildLogs := out.String()
|
||||
|
||||
eventsChan, errs := apiClient.Events(ctx, client.EventsListOptions{
|
||||
result := apiClient.Events(ctx, client.EventsListOptions{
|
||||
Since: since.Format(time.RFC3339Nano),
|
||||
Until: time.Now().Format(time.RFC3339Nano),
|
||||
})
|
||||
eventsChan := result.Messages
|
||||
errs := result.Err
|
||||
|
||||
var eventsReceived []string
|
||||
imageCreateEvts := 0
|
||||
|
||||
@@ -188,8 +188,9 @@ func TestCDIInfoDiscoveredDevices(t *testing.T) {
|
||||
defer d.Stop(t)
|
||||
|
||||
c := d.NewClientT(t)
|
||||
info, err := c.Info(ctx)
|
||||
result, err := c.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
info := result.Info
|
||||
|
||||
assert.Check(t, is.Len(info.CDISpecDirs, 1))
|
||||
assert.Check(t, is.Equal(info.CDISpecDirs[0], cdiDir))
|
||||
|
||||
@@ -807,9 +807,10 @@ func TestContainerdContainerImageInfo(t *testing.T) {
|
||||
apiClient := testEnv.APIClient()
|
||||
defer apiClient.Close()
|
||||
|
||||
info, err := apiClient.Info(ctx)
|
||||
result, err := apiClient.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
info := result.Info
|
||||
skip.If(t, info.Containerd == nil, "requires containerd")
|
||||
|
||||
// Currently a containerd container is only created when the container is started.
|
||||
|
||||
@@ -98,10 +98,11 @@ func TestMountDaemonRoot(t *testing.T) {
|
||||
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
info, err := apiClient.Info(ctx)
|
||||
result, err := apiClient.Info(ctx, client.InfoOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info := result.Info
|
||||
|
||||
for _, test := range []struct {
|
||||
desc string
|
||||
|
||||
@@ -39,11 +39,13 @@ func TestPause(t *testing.T) {
|
||||
|
||||
until := request.DaemonUnixTime(ctx, t, apiClient, testEnv)
|
||||
|
||||
messages, errs := apiClient.Events(ctx, client.EventsListOptions{
|
||||
result := apiClient.Events(ctx, client.EventsListOptions{
|
||||
Since: since,
|
||||
Until: until,
|
||||
Filters: make(client.Filters).Add(string(events.ContainerEventType), cID),
|
||||
})
|
||||
messages := result.Messages
|
||||
errs := result.Err
|
||||
assert.Check(t, is.DeepEqual([]events.Action{events.ActionPause, events.ActionUnPause}, getEventActions(t, messages, errs)))
|
||||
}
|
||||
|
||||
|
||||
@@ -247,9 +247,11 @@ func TestContainerRestartWithCancelledRequest(t *testing.T) {
|
||||
}()
|
||||
|
||||
// Start listening for events.
|
||||
messages, errs := apiClient.Events(ctx, client.EventsListOptions{
|
||||
result := apiClient.Events(ctx, client.EventsListOptions{
|
||||
Filters: make(client.Filters).Add("container", cID).Add("event", string(events.ActionRestart)),
|
||||
})
|
||||
messages := result.Messages
|
||||
errs := result.Err
|
||||
|
||||
// Make restart request, but cancel the request before the container
|
||||
// is (forcibly) killed.
|
||||
|
||||
@@ -21,9 +21,10 @@ func TestStats(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
info, err := apiClient.Info(ctx)
|
||||
result, err := apiClient.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
info := result.Info
|
||||
cID := container.Run(ctx, t, apiClient)
|
||||
t.Run("no-stream", func(t *testing.T) {
|
||||
resp, err := apiClient.ContainerStats(ctx, cID, client.ContainerStatsOptions{
|
||||
|
||||
@@ -70,9 +70,9 @@ func CheckGoroutineCount(ctx context.Context, apiClient client.SystemAPIClient,
|
||||
}
|
||||
|
||||
func getGoroutineNumber(ctx context.Context, apiClient client.SystemAPIClient) (int, error) {
|
||||
info, err := apiClient.Info(ctx)
|
||||
result, err := apiClient.Info(ctx, client.InfoOptions{})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return info.NGoroutines, nil
|
||||
return result.Info.NGoroutines, nil
|
||||
}
|
||||
|
||||
@@ -31,8 +31,9 @@ func TestInfoFirewallBackend(t *testing.T) {
|
||||
if !testEnv.IsRootless() && networking.FirewalldRunning() {
|
||||
expDriver += "+firewalld"
|
||||
}
|
||||
info, err := c.Info(ctx)
|
||||
result, err := c.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
info := result.Info
|
||||
assert.Assert(t, info.FirewallBackend != nil, "expected firewall backend in info response")
|
||||
t.Log("FirewallBackend: Driver:", info.FirewallBackend.Driver)
|
||||
for _, kv := range info.FirewallBackend.Info {
|
||||
@@ -43,8 +44,9 @@ func TestInfoFirewallBackend(t *testing.T) {
|
||||
// Check FirewallBackend is omitted for API <= 1.48.
|
||||
t.Run("api 1.48", func(t *testing.T) {
|
||||
c148 := request.NewAPIClient(t, client.WithVersion("1.48"))
|
||||
info148, err := c148.Info(ctx)
|
||||
result, err := c148.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
info148 := result.Info
|
||||
assert.Check(t, is.Nil(info148.FirewallBackend))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -276,9 +276,10 @@ func systemTime(ctx context.Context, t *testing.T, apiClient client.APIClient, t
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
info, err := apiClient.Info(ctx)
|
||||
result, err := apiClient.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
info := result.Info
|
||||
dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
|
||||
assert.NilError(t, err, "invalid time format in GET /info response")
|
||||
return dt
|
||||
@@ -289,9 +290,9 @@ func systemEventsSince(ctx context.Context, apiClient client.APIClient, since st
|
||||
Since: since,
|
||||
}
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
events, errs := apiClient.Events(ctx, eventOptions)
|
||||
result := apiClient.Events(ctx, eventOptions)
|
||||
|
||||
return events, errs, cancel
|
||||
return result.Messages, result.Err, cancel
|
||||
}
|
||||
|
||||
func TestAuthZPluginErrorResponse(t *testing.T) {
|
||||
|
||||
@@ -30,9 +30,11 @@ func TestEventsExecDie(t *testing.T) {
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
msg, errs := apiClient.Events(ctx, client.EventsListOptions{
|
||||
result := apiClient.Events(ctx, client.EventsListOptions{
|
||||
Filters: make(client.Filters).Add("container", cID).Add("event", string(events.ActionExecDie)),
|
||||
})
|
||||
msg := result.Messages
|
||||
errs := result.Err
|
||||
|
||||
_, err = apiClient.ExecStart(ctx, res.ID, client.ExecStartOptions{
|
||||
Detach: true,
|
||||
@@ -107,11 +109,13 @@ func TestEventsVolumeCreate(t *testing.T) {
|
||||
Add("type", "volume").
|
||||
Add("event", "create").
|
||||
Add("volume", volName)
|
||||
messages, errs := apiClient.Events(ctx, client.EventsListOptions{
|
||||
result := apiClient.Events(ctx, client.EventsListOptions{
|
||||
Since: since,
|
||||
Until: request.DaemonUnixTime(ctx, t, apiClient, testEnv),
|
||||
Filters: filter,
|
||||
})
|
||||
messages := result.Messages
|
||||
errs := result.Err
|
||||
|
||||
volEvents, err := getEvents(messages, errs)
|
||||
assert.NilError(t, err)
|
||||
@@ -123,11 +127,13 @@ func TestEventsVolumeCreate(t *testing.T) {
|
||||
Target: "/tmp/foo",
|
||||
}))
|
||||
|
||||
messages, errs = apiClient.Events(ctx, client.EventsListOptions{
|
||||
result = apiClient.Events(ctx, client.EventsListOptions{
|
||||
Since: since,
|
||||
Until: request.DaemonUnixTime(ctx, t, apiClient, testEnv),
|
||||
Filters: filter,
|
||||
})
|
||||
messages = result.Messages
|
||||
errs = result.Err
|
||||
|
||||
volEvents, err = getEvents(messages, errs)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types/registry"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/internal/testutil"
|
||||
"github.com/moby/moby/v2/internal/testutil/daemon"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -17,9 +18,10 @@ func TestInfoAPI(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
info, err := apiClient.Info(ctx)
|
||||
result, err := apiClient.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
info := result.Info
|
||||
// TODO(thaJeztah): make sure we have other tests that run a local daemon and check other fields based on known state.
|
||||
assert.Check(t, info.ID != "")
|
||||
assert.Check(t, is.Equal(info.Containers, info.ContainersRunning+info.ContainersPaused+info.ContainersStopped))
|
||||
@@ -51,9 +53,11 @@ func TestInfoAPIWarnings(t *testing.T) {
|
||||
d.Start(t, "-H=0.0.0.0:23756", "-H="+d.Sock())
|
||||
defer d.Stop(t)
|
||||
|
||||
info, err := c.Info(ctx)
|
||||
result, err := c.Info(ctx, client.InfoOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
info := result.Info
|
||||
|
||||
stringsToCheck := []string{
|
||||
"Access to the remote API is equivalent to root access",
|
||||
"http://0.0.0.0:23756",
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types/registry"
|
||||
"github.com/moby/moby/client"
|
||||
registrypkg "github.com/moby/moby/v2/daemon/pkg/registry"
|
||||
"github.com/moby/moby/v2/integration/internal/requirement"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -19,7 +19,7 @@ func TestLoginFailsWithBadCredentials(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
_, err := apiClient.RegistryLogin(ctx, registry.AuthConfig{
|
||||
_, err := apiClient.RegistryLogin(ctx, client.RegistryLoginOptions{
|
||||
Username: "no-user",
|
||||
Password: "no-password",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user