Add FromClient to test env execution

While working on other tests I noticed that environment.Execution cannot
be used for anything but the pre-configured daemon, however this can
come in handy for being able share daemons across multiple tests that
currently spin up a new daemon.
The execution env also seems to be misused in some of these cases.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 1381956499)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Brian Goff 2019-07-24 11:32:05 -07:00 committed by Sebastiaan van Stijn
parent 6949793bb1
commit b813c398bb
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -34,13 +34,18 @@ type PlatformDefaults struct {
}
// New creates a new Execution struct
// This is configured useing the env client (see client.FromEnv)
func New() (*Execution, error) {
client, err := client.NewClientWithOpts(client.FromEnv)
c, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
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 {
return nil, errors.Wrapf(err, "failed to get info from daemon")
}
@ -48,7 +53,7 @@ func New() (*Execution, error) {
osType := getOSType(info)
return &Execution{
client: client,
client: c,
DaemonInfo: info,
OSType: osType,
PlatformDefaults: getPlatformDefaults(info, osType),