Repository navigation
Expand file tree
/
Copy pathfuncFindCurrentIPV4Address_test.go
More file actions
79 lines (63 loc) · 1.96 KB
/
Copy pathfuncFindCurrentIPV4Address_test.go
File metadata and controls
79 lines (63 loc) · 1.96 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package iotmakerdockerbuilder
import (
"errors"
"github.com/helmutkemper/util"
"time"
)
func ExampleContainerBuilder_FindCurrentIPV4Address() {
var err error
SaGarbageCollector()
var container = ContainerBuilder{}
// set image name for docker pull
container.SetImageName("nats:latest")
// set a container name
container.SetContainerName("container_delete_nats_after_test")
// set a waits for the text to appear in the standard container output to proceed [optional]
container.SetWaitStringWithTimeout("Listening for route connections on 0.0.0.0:6222", 10*time.Second)
// inialize the container object
err = container.Init()
if err != nil {
util.TraceToLog()
panic(err)
}
// image nats:latest pull command [optional]
err = container.ImagePull()
if err != nil {
util.TraceToLog()
panic(err)
}
// container build and start from image nats:latest
// waits for the text "Listening for route connections on 0.0.0.0:6222" to appear in the standard container output
// to proceed
err = container.ContainerBuildAndStartFromImage()
if err != nil {
util.TraceToLog()
panic(err)
}
var IP string
IP, err = container.FindCurrentIPV4Address()
if err != nil {
util.TraceToLog()
panic(err)
}
if IP != container.GetIPV4Address() {
err = errors.New("all ip address must be a samer IP")
util.TraceToLog()
panic(err)
}
// container "container_delete_nats_after_test" running and ready for use on this code point on var IP
// all nats ports are open
// you can use AddPortToExpose("4222"), to open only ports defineds inside code;
// you can use AddPortToChange("4222", "1111") to open only ports defineds inside code and change port 4222 to port
// 1111;
// you can use SetDoNotOpenContainersPorts() to not open containers ports
SaGarbageCollector()
// use this function to remove image, ONLY before container stoped and deleted
err = container.ImageRemoveByName("nats:latest")
if err != nil {
util.TraceToLog()
panic(err)
}
// Output:
//
}