forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
97 lines (80 loc) · 2.41 KB
/
utils.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"os"
"github.com/alibaba/pouch/test/environment"
"github.com/go-check/check"
)
// const defines common image name
var (
busyboxImage string
helloworldImage string
helloworldImageOnlyRepoName = "hello-world"
// GateWay test gateway
GateWay string
// Subnet test subnet
Subnet string
)
const (
busyboxImage125 = "registry.hub.docker.com/library/busybox:1.25"
busyboxImage125ID = "sha256:e02e811dd08fd49e7f6032625495118e63f597eb150403d02e3238af1df240ba"
testHubAddress = "registry.hub.docker.com"
testHubUser = "pouchcontainertest"
testHubPasswd = "pouchcontainertest"
testDaemonHTTPSAddr = "tcp://0.0.0.0:2000"
serverCa = "/tmp/tls/server/ca.pem"
serverCert = "/tmp/tls/server/cert.pem"
serverKey = "/tmp/tls/server/key.pem"
clientCa = "/tmp/tls/a_client/ca.pem"
clientCert = "/tmp/tls/a_client/cert.pem"
clientKey = "/tmp/tls/a_client/key.pem"
clientWrongCa = "/tmp/tls/a_client/ca_wrong.pem"
)
func init() {
// Get test images config from test environment.
environment.GetBusybox()
environment.GetHelloWorld()
busyboxImage = environment.BusyboxRepo + ":" + environment.BusyboxTag
helloworldImage = environment.HelloworldRepo + ":" + environment.HelloworldTag
GateWay = environment.GateWay
Subnet = environment.Subnet
}
type testingTB interface {
Fatalf(format string, args ...interface{})
Skip(string)
}
func helpwantedForMissingCase(t testingTB, name string) {
t.Skip(fmt.Sprintf("help wanted: %s", name))
}
// VerifyCondition is used to check the condition value.
type VerifyCondition func() bool
// SkipIfFalse skips the suite, if any of the conditions is not satisfied.
func SkipIfFalse(c *check.C, conditions ...VerifyCondition) {
for _, con := range conditions {
if con() == false {
c.Skip("Skip test as condition is not matched")
}
}
}
// IsTLSExist check if the TLS related file exists.
func IsTLSExist() bool {
if _, err := os.Stat(serverCa); os.IsNotExist(err) {
return false
}
if _, err := os.Stat(serverKey); os.IsNotExist(err) {
return false
}
if _, err := os.Stat(serverCert); os.IsNotExist(err) {
return false
}
if _, err := os.Stat(clientCa); os.IsNotExist(err) {
return false
}
if _, err := os.Stat(clientCert); os.IsNotExist(err) {
return false
}
if _, err := os.Stat(clientKey); os.IsNotExist(err) {
return false
}
return true
}