-
Notifications
You must be signed in to change notification settings - Fork 74
/
instance.go
60 lines (47 loc) 路 1.39 KB
/
instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package sidecar
import (
"context"
"io"
"github.com/testground/sdk-go/network"
"github.com/testground/sdk-go/runtime"
"github.com/testground/sdk-go/sync"
"github.com/testground/testground/pkg/logging"
"github.com/hashicorp/go-multierror"
)
type InstanceHandler func(context.Context, *Instance) error
type Reactor interface {
io.Closer
Handle(context.Context, InstanceHandler) error
}
// Instance is a test instance as seen by the sidecar.
type Instance struct {
logging.Logging
Hostname string
Client sync.Client
RunEnv *runtime.RunEnv
Network Network
}
// Network is a test instance's network, as seen by the sidecar.
//
// Sidecar runners must implement this interface.
type Network interface {
io.Closer
ConfigureNetwork(ctx context.Context, cfg *network.Config) error
ListActive() []string
}
// NewInstance constructs a new test instance handle.
func NewInstance(client sync.Client, runenv *runtime.RunEnv, hostname string, network Network) (*Instance, error) {
return &Instance{
Logging: logging.NewLogging(logging.S().With("sidecar", true, "run_id", runenv.TestRun).Desugar()),
Hostname: hostname,
RunEnv: runenv,
Network: network,
Client: client,
}, nil
}
// Close closes the instance. It should not be used after closing.
func (inst *Instance) Close() error {
var err *multierror.Error
err = multierror.Append(err, inst.Network.Close())
return err.ErrorOrNil()
}