MCPcopy Create free account
hub / github.com/efficientgo/e2e / New

Function New

env_docker.go:88–161  ·  view source on GitHub ↗

New creates new, isolated docker environment.

(opts ...EnvironmentOption)

Source from the content-addressed store, hash-verified

86
87// New creates new, isolated docker environment.
88func New(opts ...EnvironmentOption) (_ *DockerEnvironment, err error) {
89 e := environmentOptions{}
90 for _, o := range opts {
91 o(&e)
92 }
93 if e.name == "" {
94 e.name, err = generateName()
95 if err != nil {
96 return nil, err
97 }
98 }
99 if err := validateName(e.name); err != nil {
100 return nil, err
101 }
102
103 if e.logger == nil {
104 e.logger = NewLogger(os.Stdout)
105 }
106
107 d := &DockerEnvironment{
108 logger: e.logger,
109 networkName: e.name,
110 verbose: e.verbose,
111 registered: map[string]struct{}{},
112 dockerVolumes: e.volumes,
113 }
114
115 // Force a shutdown in order to cleanup from a spurious situation in case
116 // the previous tests run didn't cleanup correctly.
117 d.close()
118
119 dir, err := getTmpDirectory()
120 if err != nil {
121 return nil, err
122 }
123 d.dir = dir
124
125 // Setup the docker network.
126 if out, err := d.exec("docker", "network", "create", "-d", "bridge", d.networkName).CombinedOutput(); err != nil {
127 e.logger.Log(string(out))
128 d.Close()
129 return nil, errors.Wrapf(err, "create docker network '%s'", d.networkName)
130 }
131
132 switch runtime.GOOS {
133 case "darwin":
134 d.hostAddr = dockerMacOSGatewayAddr
135 default:
136 out, err := d.exec("docker", "network", "inspect", d.networkName).CombinedOutput()
137 if err != nil {
138 e.logger.Log(string(out))
139 d.Close()
140 return nil, errors.Wrapf(err, "inspect docker network '%s'", d.networkName)
141 }
142
143 var inspectDetails []struct {
144 IPAM struct {
145 Config []struct {

Callers 5

TestDockerEnvironmentFunction · 0.92
TestExampleAppFunction · 0.92
deployWithMonitoringFunction · 0.92
TestExampleFunction · 0.92
NewDockerEnvironmentFunction · 0.85

Calls 8

closeMethod · 0.95
execMethod · 0.95
CloseMethod · 0.95
generateNameFunction · 0.85
validateNameFunction · 0.85
NewLoggerFunction · 0.85
getTmpDirectoryFunction · 0.85
LogMethod · 0.65

Tested by 3

TestDockerEnvironmentFunction · 0.74
TestExampleAppFunction · 0.74
TestExampleFunction · 0.74