mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #39602 from cpuguy83/env_from_client
Add `FromClient` to test env execution
This commit is contained in:
commit
ecaf0b479f
1 changed files with 8 additions and 3 deletions
|
@ -34,13 +34,18 @@ type PlatformDefaults struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Execution struct
|
// New creates a new Execution struct
|
||||||
|
// This is configured useing the env client (see client.FromEnv)
|
||||||
func New() (*Execution, error) {
|
func New() (*Execution, error) {
|
||||||
client, err := client.NewClientWithOpts(client.FromEnv)
|
c, err := client.NewClientWithOpts(client.FromEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create client")
|
return nil, errors.Wrapf(err, "failed to create client")
|
||||||
}
|
}
|
||||||
|
return FromClient(c)
|
||||||
|
}
|
||||||
|
|
||||||
info, err := client.Info(context.Background())
|
// FromClient creates a new Execution environment from the passed in client
|
||||||
|
func FromClient(c *client.Client) (*Execution, error) {
|
||||||
|
info, err := c.Info(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to get info from daemon")
|
return nil, errors.Wrapf(err, "failed to get info from daemon")
|
||||||
}
|
}
|
||||||
|
@ -48,7 +53,7 @@ func New() (*Execution, error) {
|
||||||
osType := getOSType(info)
|
osType := getOSType(info)
|
||||||
|
|
||||||
return &Execution{
|
return &Execution{
|
||||||
client: client,
|
client: c,
|
||||||
DaemonInfo: info,
|
DaemonInfo: info,
|
||||||
OSType: osType,
|
OSType: osType,
|
||||||
PlatformDefaults: getPlatformDefaults(info, osType),
|
PlatformDefaults: getPlatformDefaults(info, osType),
|
||||||
|
|
Loading…
Add table
Reference in a new issue