Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 72f7e5a

Browse files
cpuguy83thaJeztah
authored andcommitted
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 1381956499d357dcae47dd1239d4f35b176fea7d) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: b813c398bb38ff5f73099e9cde61eb217551e3bf Component: engine
1 parent 78567fe commit 72f7e5a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

components/engine/internal/test/environment/environment.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,26 @@ type PlatformDefaults struct {
3434
}
3535

3636
// New creates a new Execution struct
37+
// This is configured useing the env client (see client.FromEnv)
3738
func New() (*Execution, error) {
38-
client, err := client.NewClientWithOpts(client.FromEnv)
39+
c, err := client.NewClientWithOpts(client.FromEnv)
3940
if err != nil {
4041
return nil, errors.Wrapf(err, "failed to create client")
4142
}
43+
return FromClient(c)
44+
}
4245

43-
info, err := client.Info(context.Background())
46+
// FromClient creates a new Execution environment from the passed in client
47+
func FromClient(c *client.Client) (*Execution, error) {
48+
info, err := c.Info(context.Background())
4449
if err != nil {
4550
return nil, errors.Wrapf(err, "failed to get info from daemon")
4651
}
4752

4853
osType := getOSType(info)
4954

5055
return &Execution{
51-
client: client,
56+
client: c,
5257
DaemonInfo: info,
5358
OSType: osType,
5459
PlatformDefaults: getPlatformDefaults(info, osType),

0 commit comments

Comments
 (0)