-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain_suite_test.go
141 lines (125 loc) · 5.88 KB
/
main_suite_test.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main_test
import (
"fmt"
"strings"
"testing"
"time"
vsat "code.cloudfoundry.org/cf-volume-services-acceptance-tests"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
"github.com/cloudfoundry/cf-test-helpers/v2/config"
"github.com/cloudfoundry/cf-test-helpers/v2/workflowhelpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
var (
cfConfig *config.Config
pConfig vsat.Config
cfTestSuiteSetup *workflowhelpers.ReproducibleTestSuiteSetup
DEFAULT_TIMEOUT = 30 * time.Second
LONG_TIMEOUT = 600 * time.Second
POLL_INTERVAL = 3 * time.Second
appPath string
brokerName string
testValues persiTestValues
smbTestValues, nfsTestValues, nfsLDAPTestValues persiTestValues
)
type persiTestValues struct {
validCreateServiceConfig string
createServiceConfigWithInvalidShare string
validBindConfigs []string
bindConfigWithInvalidKeys string
bindConfigWithInvalidKeysFailure string
secondAppValidBindConfig string
invalidCreateConfig string
}
func TestPersiAcceptance(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cf Volume Services Acceptance Tests")
}
var _ = BeforeSuite(func() {
var err error
pConfig, err = vsat.LoadConfig()
Expect(err).NotTo(HaveOccurred())
cfConfig = config.LoadConfig()
cfTestSuiteSetup = workflowhelpers.NewTestSuiteSetup(cfConfig)
cfTestSuiteSetup.Setup()
brokerName = pConfig.ServiceName + "broker"
appPath = "assets/pora"
smbTestValues = persiTestValues{
invalidCreateConfig: `{"meow": "I don't have a share"}`,
validCreateServiceConfig: `{"share": "//smbtestserver.service.cf.internal/vol"}`,
secondAppValidBindConfig: `{}`,
bindConfigWithInvalidKeys: `{"uid": "1000", "gid": "1000"}`,
bindConfigWithInvalidKeysFailure: "Service broker error: - Not allowed options: gid, uid",
createServiceConfigWithInvalidShare: `{"share": "//meow.smbtestserver.this.does.not.exist.cf.internal/vol"}`,
validBindConfigs: []string{
fmt.Sprintf(`{"username": "%s", "password": "%s", "domain": "foo"}`, pConfig.Username, pConfig.Password),
fmt.Sprintf(`{"username": "%s", "password": "%s"}`, pConfig.Username, pConfig.Password),
fmt.Sprintf(`{"username": "%s", "password": "%s", "mount": "/var/vcap/data/foo", "domain": "foo"}`, pConfig.Username, pConfig.Password),
fmt.Sprintf(`{"username": "%s", "password": "%s", "domain": "foo", "version": "3"}`, pConfig.Username, pConfig.Password),
fmt.Sprintf(`{"username": "%s", "password": "%s", "domain": "foo", "version": "3.1.1"}`, pConfig.Username, pConfig.Password),
},
}
nfsTestValues = persiTestValues{
invalidCreateConfig: `{"meow": "I don't have a share"}`,
validCreateServiceConfig: `{"share": "nfstestserver.service.cf.internal/export/users"}`,
secondAppValidBindConfig: `{"uid":"5000","gid":"5000"}`,
bindConfigWithInvalidKeys: `{"domain":"foo"}`,
bindConfigWithInvalidKeysFailure: "Service broker error: - Not allowed options: domain",
createServiceConfigWithInvalidShare: `{"share": "nfstestserver.service.cf.internal/meow-meow-this-doesnt-exist"}`,
validBindConfigs: []string{
`{"uid": "1000", "gid": "1000"}`,
`{"uid": "1000", "gid": "1000", "mount": "/var/vcap/data/foo"}`,
`{"uid": "1000", "gid": "1000", "version": "3"}`,
`{"uid": "1000", "gid": "1000", "version": "4.0"}`,
`{"uid": "1000", "gid": "1000", "version": "4.1"}`,
`{"uid": "1000", "gid": "1000", "version": "4.2"}`,
},
}
ldapUser := "user1000"
ldapPassword := "secret" // these are hardcoded in nfstestldapserver
nfsLDAPTestValues = persiTestValues{
invalidCreateConfig: `{"meow": "I don't have a share"}`,
validCreateServiceConfig: `{"share": "nfstestserver.service.cf.internal/export/users"}`,
secondAppValidBindConfig: `{"username": "user2000", "password": "secret"}`, // these are hardcoded in nfstestldapserver
bindConfigWithInvalidKeys: `{"domain":"foo"}`,
bindConfigWithInvalidKeysFailure: "Service broker error: - Not allowed options: domain",
createServiceConfigWithInvalidShare: `{"share": "nfstestserver.service.cf.internal/meow-meow-this-doesnt-exist", "username": "1000", "password": "secret"}`,
validBindConfigs: []string{
fmt.Sprintf(`{"username": "%s", "password": "%s"}`, ldapUser, ldapPassword),
fmt.Sprintf(`{"username": "%s", "password": "%s", "mount": "/var/vcap/data/foo"}`, ldapUser, ldapPassword),
fmt.Sprintf(`{"username": "%s", "password": "%s", "version": "3"}`, ldapUser, ldapPassword),
fmt.Sprintf(`{"username": "%s", "password": "%s", "version": "4.0"}`, ldapUser, ldapPassword),
fmt.Sprintf(`{"username": "%s", "password": "%s", "version": "4.1"}`, ldapUser, ldapPassword),
fmt.Sprintf(`{"username": "%s", "password": "%s", "version": "4.2"}`, ldapUser, ldapPassword),
},
}
if pConfig.ServiceName == "nfs" {
if strings.Contains(pConfig.BrokerName, "ldap") {
testValues = nfsLDAPTestValues
} else {
testValues = nfsTestValues
}
} else if pConfig.ServiceName == "smb" {
testValues = smbTestValues
} else {
Expect(pConfig.ServiceName).To(BeElementOf([]string{"nfs", "smb"}))
}
})
var _ = AfterSuite(func() {
if cfTestSuiteSetup != nil {
cfTestSuiteSetup.Teardown()
}
})
var _ = BeforeEach(func() {
if pConfig.IncludeIsolationSegment {
org := cfTestSuiteSetup.RegularUserContext().Org
workflowhelpers.AsUser(cfTestSuiteSetup.AdminUserContext(), DEFAULT_TIMEOUT, func() {
enableIso := cf.Cf("enable-org-isolation", org, pConfig.IsolationSegmentName).Wait(DEFAULT_TIMEOUT)
Expect(enableIso).To(Exit(0))
defaultIso := cf.Cf("set-org-default-isolation-segment", org, pConfig.IsolationSegmentName).Wait(DEFAULT_TIMEOUT)
Expect(defaultIso).To(Exit(0))
})
}
})