github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/integration/internal/request/client.go (about)

     1  package request // import "github.com/docker/docker/integration/internal/request"
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"golang.org/x/net/context"
     9  
    10  	"github.com/docker/docker/client"
    11  	"github.com/docker/docker/internal/test/environment"
    12  	"github.com/gotestyourself/gotestyourself/assert"
    13  )
    14  
    15  // NewAPIClient returns a docker API client configured from environment variables
    16  func NewAPIClient(t *testing.T, ops ...func(*client.Client) error) client.APIClient {
    17  	ops = append([]func(*client.Client) error{client.FromEnv}, ops...)
    18  	clt, err := client.NewClientWithOpts(ops...)
    19  	assert.NilError(t, err)
    20  	return clt
    21  }
    22  
    23  // DaemonTime provides the current time on the daemon host
    24  func DaemonTime(ctx context.Context, t *testing.T, client client.APIClient, testEnv *environment.Execution) time.Time {
    25  	if testEnv.IsLocalDaemon() {
    26  		return time.Now()
    27  	}
    28  
    29  	info, err := client.Info(ctx)
    30  	assert.NilError(t, err)
    31  
    32  	dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
    33  	assert.NilError(t, err, "invalid time format in GET /info response")
    34  	return dt
    35  }
    36  
    37  // DaemonUnixTime returns the current time on the daemon host with nanoseconds precision.
    38  // It return the time formatted how the client sends timestamps to the server.
    39  func DaemonUnixTime(ctx context.Context, t *testing.T, client client.APIClient, testEnv *environment.Execution) string {
    40  	dt := DaemonTime(ctx, t, client, testEnv)
    41  	return fmt.Sprintf("%d.%09d", dt.Unix(), int64(dt.Nanosecond()))
    42  }