2018-02-09 13:13:26 -05:00
|
|
|
package request // import "github.com/docker/docker/integration/internal/request"
|
2017-07-12 18:26:09 -04:00
|
|
|
|
|
|
|
import (
|
2018-02-09 19:13:26 -05:00
|
|
|
"fmt"
|
2017-07-12 18:26:09 -04:00
|
|
|
"testing"
|
2017-09-22 09:05:56 -04:00
|
|
|
"time"
|
2017-07-12 18:26:09 -04:00
|
|
|
|
2018-02-09 19:13:26 -05:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-07-12 18:26:09 -04:00
|
|
|
"github.com/docker/docker/client"
|
2018-02-09 19:13:26 -05:00
|
|
|
"github.com/docker/docker/internal/test/environment"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
2017-07-12 18:26:09 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewAPIClient returns a docker API client configured from environment variables
|
2018-01-31 14:41:31 -05:00
|
|
|
func NewAPIClient(t *testing.T, ops ...func(*client.Client) error) client.APIClient {
|
|
|
|
ops = append([]func(*client.Client) error{client.FromEnv}, ops...)
|
|
|
|
clt, err := client.NewClientWithOpts(ops...)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-07-12 18:26:09 -04:00
|
|
|
return clt
|
|
|
|
}
|
2017-09-22 09:05:56 -04:00
|
|
|
|
2018-02-22 01:00:05 -05:00
|
|
|
// DaemonTime provides the current time on the daemon host
|
|
|
|
func DaemonTime(ctx context.Context, t *testing.T, client client.APIClient, testEnv *environment.Execution) time.Time {
|
2018-02-09 19:13:26 -05:00
|
|
|
if testEnv.IsLocalDaemon() {
|
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := client.Info(ctx)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err, "invalid time format in GET /info response")
|
2018-02-09 19:13:26 -05:00
|
|
|
return dt
|
|
|
|
}
|
|
|
|
|
|
|
|
// DaemonUnixTime returns the current time on the daemon host with nanoseconds precision.
|
|
|
|
// It return the time formatted how the client sends timestamps to the server.
|
|
|
|
func DaemonUnixTime(ctx context.Context, t *testing.T, client client.APIClient, testEnv *environment.Execution) string {
|
2018-02-22 01:00:05 -05:00
|
|
|
dt := DaemonTime(ctx, t, client, testEnv)
|
2018-02-09 19:13:26 -05:00
|
|
|
return fmt.Sprintf("%d.%09d", dt.Unix(), int64(dt.Nanosecond()))
|
|
|
|
}
|