1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/internal/request/client.go
Daniel Nephin a68ae4a2d9 Improve docstrings and small cleanup in client
Use client instead of helpers for TLS in integration test

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-20 15:15:02 -05:00

42 lines
1.4 KiB
Go

package request // import "github.com/docker/docker/integration/internal/request"
import (
"fmt"
"testing"
"time"
"golang.org/x/net/context"
"github.com/docker/docker/client"
"github.com/docker/docker/internal/test/environment"
"github.com/stretchr/testify/require"
)
// NewAPIClient returns a docker API client configured from environment variables
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...)
require.NoError(t, err)
return clt
}
// 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 {
if testEnv.IsLocalDaemon() {
return time.Now()
}
info, err := client.Info(ctx)
require.NoError(t, err)
dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
require.NoError(t, err, "invalid time format in GET /info response")
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 {
dt := daemonTime(ctx, t, client, testEnv)
return fmt.Sprintf("%d.%09d", dt.Unix(), int64(dt.Nanosecond()))
}