system.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package system
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/docker/docker/api/types"
  7. "github.com/docker/docker/api/types/events"
  8. "github.com/docker/docker/client"
  9. "github.com/docker/docker/internal/test/environment"
  10. "github.com/stretchr/testify/require"
  11. )
  12. // Time provides the current time on the daemon host
  13. func Time(t *testing.T, client client.APIClient, testEnv *environment.Execution) time.Time {
  14. if testEnv.IsLocalDaemon() {
  15. return time.Now()
  16. }
  17. ctx := context.Background()
  18. info, err := client.Info(ctx)
  19. require.Nil(t, err)
  20. dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
  21. require.Nil(t, err, "invalid time format in GET /info response")
  22. return dt
  23. }
  24. // Version provides the version of the daemon
  25. func Version(client client.APIClient) (types.Version, error) {
  26. ctx := context.Background()
  27. return client.ServerVersion(ctx)
  28. }
  29. // EventsSince returns event and error streams since a provided time
  30. func EventsSince(client client.APIClient, since string) (<-chan events.Message, <-chan error, func()) {
  31. eventOptions := types.EventsOptions{
  32. Since: since,
  33. }
  34. ctx, cancel := context.WithCancel(context.Background())
  35. events, errs := client.Events(ctx, eventOptions)
  36. return events, errs, cancel
  37. }